0
\$\begingroup\$

How low of a frequency can a timer be used to measure an external signal in "input capture" mode?

If I need to measure something that has a frequency of say 1hz - 2hz... or even slower for that matter, at which point do I just use a standard interrupt and use the system clock to get my period measurements? Is there even a difference in the two approaches?

void myInterupt() {
  newCapture = systemClockCount;

  if (newCapture != previousCapture && captureChanged == false) {
    if (newCapture >= previousCapture) {
      period = newCapture - previousCapture;
    } else {
      period = previousCapture - newCapture;
    }
    captureChanged = true;
    previousCapture = newCapture;
  }
}
\$\endgroup\$
  • \$\begingroup\$ The usual method with primitive 8-bit micro timers is to use the hardware timer for the fine measurement and count overflows of the timer with interrupts. Then there is no limit to the minimum frequency for all practical purposes, and only very loose constraints on servicing the interrupts. \$\endgroup\$ – Spehro Pefhany Sep 20 '19 at 5:21
  • \$\begingroup\$ I'm using an STM32. Would this change your approach? \$\endgroup\$ – scottc11 Sep 20 '19 at 13:17
0
\$\begingroup\$

It depends on the MCU and the timer clock frequency (APB in most cases).

Standard timers have 16 bit counters and 16 bit prescalers. They can measure up to 232 cycles, but the resolution would be 16 bits only. About 51 seconds at 84 MHz APB clock.

Some timers have 32 bit counters and 16 bit prescalers. They can measure up to 232 cycles without using the prescaler, in full 32 bit resolution, and up to 248 cycles with prescaling. About 38 days at 84 MHz.

Timers can be connected in a master-slave configuration, the overflow of one timer advancing the other. Combining two 32-bit timers would yield 264 cycles without prescalers, 296 cycles with prescalers. About 3*1013 years, more than 2000 times the age of the universe. And more than 2 timers can be connected that way if that wouldn't be enough.

I just use a standard interrupt and use the system clock to get my period measurements? Is there even a difference in the two approaches?

Interrupts can be blocked by other interrupts or code disabling the interrupts. The counter is read by interrupt code that needs some time to execute, causing imprecise measurements. A timer stores the capture value at the exact cycle when the trigger occurs.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Standard timers have 16 bit counters and 16 bit prescalers. They can measure up to 232 cycles, but the resolution would be 16 bits only. About 51 seconds at 84 MHz APB clock. - When you say 51 seconds, is that 51 seconds for each tick? Or51 seconds before the timer overflows? \$\endgroup\$ – scottc11 Sep 20 '19 at 13:20
  • \$\begingroup\$ One tick (the resolution) is 65536 APB clock ticks, overflows after 51 seconds. \$\endgroup\$ – berendi - protesting Sep 20 '19 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.