10.4.2 External Interrupts

The ATMega128 has many external interrupt lines. An external interrupt pin is a general purpose I/O pin as far as configuration is concerned. However, an external interrupt pin also has the ability to cause an interrupt when it senses a transition. This is great for encoding purposes, because we only need to pay attention when there is a transition.

Different members of the AVR have different external interrupt designs. On an ATMega128, an external interrupt can be set up to sense either a rising edge or a falling edge. Although this appears to be a problem, it is not.

Except for the first transition, all other transitions (rising or falling) can be captured correctly. This is because the ISR can flip the edge sensing polarity! In other words, after sensing a falling edge, the ISR can flip the polarity to sense a rising edge. This makes sense because a falling edge must be followed by a rising edge before another falling edge occurs.

Although external interrupts only occur when there is a transition, there is still a maximum number of transitions that the processor can handle. For very high speed or high resolution encoding, ISRs should be written in assembly language to minimize the overhead (mostly for saving and restoring registers).

Copyright © 2006-02-15 by Tak Auyeung