0% found this document useful (0 votes)
22 views28 pages

Interrupts in AVR

Uploaded by

neha bhangare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views28 pages

Interrupts in AVR

Uploaded by

neha bhangare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Interrupts in AVR

AVR Interrupt
• Interrupt service routine (ISR)
• Upon activation of an interrupt, the microcontroller goes through the following steps:
1. It finishes the instruction it is currently executing and saves the address of the next
instruction (program counter) on the stack.
2. It jumps to a fixed location in memory called the interrupt vector table. The interrupt
vector table directs the microcontroller to the address of the interrupt service routine
(ISR).
3. The microcontroller starts to execute the interrupt service subroutine until it reaches
the last instruction of the subroutine, which is RETI (return from inter- rupt).
4. Upon executing the RETI instruction, the microcontroller returns to the place where it
was interrupted. First, it gets the program counter (PC) address from the stack by
popping the top bytes of the stack into the PC. Then it starts to execute from that
address.
Vector Table
General program setup for the Interrupt Vector Addresses in ATmega32
Sources of interrupts in the AVR
• There are many sources of interrupts in the AVR, depending on which peripheral is
incorporated into the chip
• The following are some of the most widely used sources of interrupts in the AVR:
1. There are at least two interrupts set aside for each of the timers, one for over- flow
and another for compare match
2. Three interrupts are set aside for external hardware interrupts. Pins PD2 (PORTD.2),
PD3 (PORTD.3), and PB2 (PORTB.2) are for the external hard- ware interrupts INTO,
INT1, and INT2, respectively
3. Serial communication's USART has three interrupts, one for receive and two
interrupts for transmit
4. The SPI interrupts
5. The ADC (analog-to-digital converter)
• Enabling and Disabling an Interrupt
Programming Timer Interrupts
• RET Vs RETI
• Compare match timer flag and interrupt
Programming External Hardware Interrupts
• . The ATmega32 has three external hardware interrupts: pins PD2 (PORTD.2), PD3
(PORTD.3), and PB2 (PORTB.2), designated as INTO, INTI, and INT2, respectively
• Upon activation of these pins, the AVR is interrupted in whatever it is doing and jumps to
the vector table to perform the interrupt service routine
External interrupts INT0, INT1, and INT2
• They are located on pins PD2, PD3, and PB2, respectively
• The interrupt vector table locations $2, $4, and $6 are set aside for INTO, INT1, and INT2,
respectively
• The hardware interrupts must be enabled before they can take effect. This is done using
the INTx bit located in the GICR register
• For example, the following instructions enable INTO:
LDI 20,0x40
OUT GICR, R20
• The INT0 is a low-level-triggered interrupt by default, which means, when a low signal is
applied to pin PD2 (PORTD.2), the controller will be interrupted and jump to location $0002
in the vector table to service the ISR
Edge-triggered vs. level-triggered interrupts
• There are two types of activation for the external hardware interrupts:
• Level triggered
• Edge triggered
• INT2 is only edge triggered, while INTO and INTI can be level or edge triggered
• Upon reset INTO and INTI are low-level-triggered interrupts
• The bits of the MCUCR register indicate the trigger options of INTO and INT1
• The ISC2 bit of the MCUCSR register defines whether INT2 activates in the falling edge or the rising edge
• Upon reset ISC2 is 0, meaning that the external hardware interrupt of INT2 is falling edge triggered.
Serial Communication
Parallel Communication (Printer)
• Fast, but distance cannot be great
• Expensive

Serial Communication (Telephone line)


• Slower but long distance
• Cheaper
Synchronuous Vs. Asynchronuous
Two methods of Serial Communication –
• Synchronous : Transfer block of data(characters)at a time
• Asynchronous: Transfer a single byte at a time
• UART: Universal Asynchronous Receiver-Transmitter
• USART: Universal Synchronous Asynchronous Receiver-Transmitter
• The AVR chip has a build in USART

• In simplex transmission such as with printers, computer only sends data.


• If the data can be transmitted and received, it is a duplex transmission.
• Duplex can be half or full duplex, depending on whether or not the data transfer
can be simultaneous.
Asynchronuous Serial Communication
• . Widely used to send 1 byte at a time
• Start bit and stop bit
USART Serial Communication

You might also like