Hi! I'm currently playing with timer interrupts and I want to start a timer when an event happens. After the timer-interrupt has happened, I want disable it until the event happens again. The timer period should be the same, so I need to reset the counter at some point:
TCNT = 0;
Now as far as I can see - there's two ways of disabling the timer-interrupt. But I wonder what's best to do.
-
Timer-interrupt occurs → disable interrupt via TIMSK → event occurs → Reset counter (TCNT) → enable interrupt via TIMSK.
-
Timer-interrupt occurs → disable counter via TCCR → Reset counter (TCNT) → event occurs → enable counter via TIFR.
(Disabling the counter via TCCR by setting CS10, 11 & 12 to 0)
Also, should I clear the TIFR after disabling** counter in 2nd method?**