I'm trying to figure out all of the nitty gritty details surrounding implementing an input capture timer that has > 16 bit resolution. I want to use the timer 1 input capture unit, but I also want to accurately account for timer overflows.
I've read this forum post:
but it's not clear if the last proposed solution is correct. I've also read app note AVR135:
but that seems to assume that the next event will happen within 64K clocks of the last event, so there's no need to keep track of timer1 overflows.
For concreteness let's make the following assumptions:
- CPU is a atmega328 running at 8 MHz
- the TIMER1 prescaler is 1
- the event being timed is greater than a couple of microseconds but could be up to a few seconds in length so a 24 or 32-bit counter would be needed to hold the timer value.
- only one event duration needs to be measured - although it would be nice if the timer could be kept running so that you could record the times of subsequent events; again, you can assume that the time between events will be at least a few microseconds