An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service.
A single microcontroller can serve several devices by two ways a) interrupt and b) polling
· Interrupts
o Whenever any device needs its service, the device notifies the microcontroller by sending it an interrupt signal
o Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and serves the device
o The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler
o For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler
· Polling
o The polling method is not efficient, since it wastes much of the microcontroller’s time by polling devices that do not need service
ISR or Interrupt Service Routine or Interrupt Handler defines the task that is needed to be performed when the interrupt occurs. It is the set of codes for the controller to execute on the occurrence of the interrupt. The following table gives the interrupt sources in AVR Atmega 8 microcontroller, but most of this is common for the Atmega series controllers such as Atmega 16, Atmega 168, Atmega 32, etc
AVR microcontroller has many interrupt sources but each has a different vector name which is used by the AVR studio compiler. But the vector name is specific to a interrupt source, which has a different name from the interrupt source name. The following table shows the vector name used by the compiler. The ISR is function whose input is the "INTERRUPT VECTOR NAME". These Vector Name is mapped into vector addresses.
AVR microcontroller has many interrupt sources but each has a different vector name which is used by the AVR studio compiler. But the vector name is specific to a interrupt source, which has a different name from the interrupt source name. The following table shows the vector name used by the compiler. The ISR is function whose input is the "INTERRUPT VECTOR NAME". These Vector Name is mapped into vector addresses.
VECTOR NAME
|
INTERRUPT SOURCE
|
INT0_vect
|
External INT0
|
INT1_vect
|
External INT1
|
TIMER2_COMP_vect
|
Timer 2 Compare match
|
TIMER2_OVF_vect
|
Timer 2 overflow
|
TIMER1_CAPT_vect
|
Timer1 Input Capture
|
TIMER1_COMPA_vect
|
Timer1 Compare A match
|
TIMER1_COMPB_vect
|
Timer1 Compare B match
|
TIMER1_OVF_vect
|
Timer1 Overflow
|
TIMER0_OVF_vect
|
Timer0 Overflow
|
SPI_STC_vect
|
SPI complete
|
USART_RXC_vect
|
USART RX Complete
|
USART_UDRE_vect
|
USART UDR EMPTY
|
USART_TXC_vect
|
USART TX Complete
|
ADC_vect
|
ADC Conv Complete
|
EE_RDY_vect
|
EEPROM Ready/Complete
|
ANA_COMP_vect
|
Analog Comparator i/p change
|
TWI_vect
|
TWI or I2C done/complete/receive
|
To add the ISR for an interrupt source, just type the vector name in the function ISR(<vect_name>). All other interrupts are disabled when controller is servicing (executing) an ISR and automatically enabled when the execution is completed. The AVR accomplishes this by disabling the global interrupt enable {sei();} and disable {cli();} function. Don’t forget to enable global interrupt enable flag before going into the infinite program loop, else the interrupt will not be served.
Syntax:
ISR(<vector_name>)
{
//code for the ISR
}
Syntax:
ISR(<vector_name>)
{
//code for the ISR
}
Example:
ISR(INT0_vect)
{//1 int0
}
ISR(TIMER1_COMPA_vect)
{//1 int0
}
In order to have smooth interrupt functions follow the procedure,
1. Choose the required interrupt source and its int type & trigger, read its registers description.
2. Set the interrupt type & trigger method of the corresponding interrupt in its control registers and status register.
3. Set the interrupt enable bit in control register.
4. Set the global interrupt enable bit using “ sei(); ” command.
NOTE: If two or more interrupt sources are used in the program, then the global interrupt enable bit must be set after initializing all the interrupt sources.
0 comments:
Post a Comment