(Timer) For timer 1 or timer 2, the prescaler and timer register are initialized each time an interrupt is generated. What are the precautions concerning usage of interrupts in this way? [2005/03/01]
In this case, the period of the timer interrupt becomes "the value of the initialized timer + the processing time from after the interrupt request is generated until the prescaler and timer register are initialized".
- <Note regarding initialization procedures>
- We recommend setting the prescaler first, then the timer.
The timer and prescaler continue counting even while being set. Therefore, they may down-count from the transient value during initialization. When the timer is set before the prescaler is set, if the prescaler underflows within the period after the timer is set but before the prescaler is set, the timer will down-count from the latest value. Accordingly, the period until the next interrupt will be shortened.
- <Note regarding interrupts generating time lags>
- After an interrupt request is generated due to a timer underflow, the time until the interrupt routine is actually started varies according to the number of cycles of the instruction being executed at the time the request was generated.