Interrupts are the best ever. If we didn't have interrupts we would have to just poll constantly and waste a lot of CPU time and that would be bad. Now instead of that we can infinite loop on nothing until we hit an interrupt, then process it.

So, no different in our case really :P But better in a lot of cases!
Interrupts need hardware though and are hard to do cause timers are jerks.

Interrupt Handling

  • Recognise
    • Could come from any of multiple interrupts so it has to specify what it is and why it is interrupting
    • Have to handle which one to do first if multiple come at once
  • Respond
    • Wait until we finish the current thing we're doing right now
    • Branch over to the correct handler
  • Resume
    • Jump back to what we were doing when we were so rudely interrupted

AVR has to do at least 4 clock things: save PC and jump to interrupt handler

Lowest program memory spaces specify the interrupt vectors. They have to be right at start of .cseg or shit goes cray.


Software; we can do it so we let programmers enable/disable other interrupts when we handling one.

OR hardware force disables them when we handle one. (Using an Interrupt enable flip flop).

Each IRQ (interrupt input pin thing) has a vector in memory and can be separately enabled/disabled. We use the maskings to do it.

If we have multiple interrupts and we need to know which one generated an IRQ we can either poll them all from most to least important, or we can daisy chain in hardware (query all, in a line. If one generated an interrupt, give back your vector, don’t pass along. Similar to polling).

Software interrupts typically implement syscalls, whereas hardware does things like power failure or timers.

TO enable an interrupt, two control bits must be set - Global Interrupt Enable Bit (Bit I of SREG) using SEI and we have to enable the bit for that particular interrupt in the interrupt mask thing.

To enable interrupts. Either 1, 0, 10 or 11 « ISC01 (or whatever the interrupt that we want to enable is).


We use a watchdog timer. We can change the period to control the interval; 8 different periods determined by WDP2, WDP1 and WDP0 bits in WDTCR.

Watchdogs are used to reset the system if it hangs. E.g. if we set a bit to show that something was used.

We have 8 and 16 bit timers.
Basically we get a timer alert every time period and we use the time period to figure out how many of them we need to count and when we've counted enough we do something and reset the counting. Yay!

We set TOIEx bit to enable the timer and OCIEx to enable compare interrupt timer