This article introduces the concept of interrupts and the different types of interrupts in AVR Microcontroller (ATmega16). Interrupt as the name suggests, interrupts the current routine of the microcontroller. Microcontroller executes instructions in a sequence as per the programs. Sometimes there may be a need of handling planned and higher priority events instantaneously that might occur during the normal operations. To handle such kind of events AVR microcontrollers are equipped with Interrupt Systems.
When an interrupt occurs, the normal flow of instructions is suspended by the microcontroller
and the code corresponding to the interrupt, which has occurred, is executed. Once the code corresponding to the interrupt is executed completely the execution again begins from the same instruction where it was stopped.
Following is what happens when an interrupt occurs:
1. Microcontroller normally completes the instruction which is being executed.
2. The program control transfers to Interrupt Service Routine (ISR). Each interrupt have an associated ISR which is a piece of code which tells the microcontroller what to do when an interrupt has occurred.
3. Execution of ISR is performed by loading the beginning address of the corresponding ISR into program counter.
4. Execution of ISR continues until the return from the interrupt instruction (RETI) is encountered.
5. When ISR is complete, the microcontroller resumes processing where it left off before the interrupt occurred, i.e., program control is reverted back to the main program.
The whole process can be visualized by the following flow diagram:
Number of available interrupts varies with different microcontrollers of AVR family. Atmega16
in total has twenty one (21) interrupts available. The available interrupts are categorized in two classes:
1. External Interrupts- Out of the twenty one interrupts available, four interrupts are directly present on controller pins to handle the interrupts generated by external sources, so they are called as external interrupts. The four available interrupts and their respective pins are shown in the figure below in their order of priority: