Timer Stop/Start question

Timer 1 is being used to generate timed interrupts to read a sample count from an encoder-disk tied to INT0. When I enter the ISR for Timer 1, I disable interrupts, then gather data, then re-enable interrupts.

Is the timer still running while the interrupts are off? (I'm thinking it is...)

For consistency should I also STOP the timer, then enable interrupts and START the timer? My thinking is this stop/start would then provide uniform n-second interrupts...

The devil is in the details! :slight_smile:

Harrzack:
When I enter the ISR for Timer 1, I disable interrupts, then gather data, then re-enable interrupts.

No need to do that. It's automatic for every interrupt.

Harrzack:
Is the timer still running while the interrupts are off? (I'm thinking it is...)

Yes. When the timer hits the point where it generates an interrupt, it sets a flag. If interrupts are enabled: the interrupts are disabled, the flag is cleared, and control is passed to the ISR. If interrupts are disabled when the flag is set the interrupt will be serviced almost immediately after the interrupts are re-enabled. As long as the interrupts aren't disabled for TWO time intervals (timer tries to interrupt when the flag is already set) you won't lose any interrupts.

Harrzack:
For consistency should I also STOP the timer, then enable interrupts and START the timer? My thinking is this stop/start would then provide uniform n-second interrupts...

NO! If you turn off the timer (stop the ticking) your next interval will be longer by the amount of time the timer is stopped.