Electronic – On an AVR (ATtiny2313), which is serviced first when TIMER0_OVF and TIMER0_COMPA are due at the same time

avrtimer

If an AVR's 8-bit timer compare register is 255 and the timer overflows (according to the datasheet, the compare interrupt happens on the next timer clock cycle) then both the overflow interrupt and the compare interrupt should be due at the same time. Which will be serviced first?

Best Answer

See the datasheet for the ATtiny2313: http://www.atmel.com/dyn/resources/prod_documents/doc2543.PDF

The priority of interrupts is determined by the order of the interrupt vectors. See page 46 for the list. The lower the number, the higher the priority. Since Timer/Counter0 Overflow has a lower number (7) than Timer/Counter0 Compare Match A (14), the overflow ISR will run first.