# timer input capture for really low frequencies

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;
}
}

• 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. – Spehro Pefhany Sep 20 '19 at 5:21
• I'm using an STM32. Would this change your approach? – scottc11 Sep 20 '19 at 13:17

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.

• 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? – scottc11 Sep 20 '19 at 13:20
• One tick (the resolution) is 65536 APB clock ticks, overflows after 51 seconds. – berendi - protesting Sep 20 '19 at 16:39