Counter input capture
I'm trying to set up a counter to capture the period of an input signal. I'm getting lost in the different CCMR bits. If it possible to do the following:
- wait for a raising edge on an input.
- on the raising edge, start counter
- on the next raising edge
- record CNT (I can do that, in CCR)
- reset CNT to 0
- fire an interrupt
- for bonus points, if the leading edge fails to arrive by a certain count, reset CNT to that overshoot and fire an interrupt
(e.g., I'm expecting a raising edge every 10,000 ticks of the timer. If the timer goes to 12,000, I'm going to decide that the signal failed to arrive. I want to reset the counter to 2,000 and keep counting from there, as if input capture did happen. I can use a counter compare interrupt and set CNT manually, but I don't know how to account for the ticks that happen while I'm in the ISR)