Basics
We have covered the basics of AVR timer Programming, during the Timer 1 example we saw that we had to monitor the Flags to check if the Timer has overflown which made the main program dependent on the status of the flags. Timers are independent unit's inside a micro-controller and to make full use of them we will configure and use them with Interrupts. This makes the CPU free from polling the flags and timers can operate on their own. When the timing task is finished, it will interrupt and inform the CPU.
Let us repeat the same example of generating a 100ms delay with Timer 1 but this time using Interrupts. We have covered the Basics of AVR Interrupts, you may wish to go through it first.
TIMSK | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
- | - | TICIE1 | OCIE1A | OCIE1B | TOIE1 | - | - |
Code