0% found this document useful (0 votes)
7 views24 pages

Lec-18 EE-222

The document discusses the differences between polling and interrupt methods for managing I/O services in microcontrollers, highlighting that interrupts are more efficient as they allow the CPU to handle multiple devices based on priority. It outlines the steps involved in executing an interrupt in AVR microcontrollers, including saving the program counter and executing the corresponding Interrupt Service Routine (ISR). Additionally, it covers how to enable and disable interrupts and the structure of the interrupt vector table.

Uploaded by

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

Lec-18 EE-222

The document discusses the differences between polling and interrupt methods for managing I/O services in microcontrollers, highlighting that interrupts are more efficient as they allow the CPU to handle multiple devices based on priority. It outlines the steps involved in executing an interrupt in AVR microcontrollers, including saving the program counter and executing the corresponding Interrupt Service Routine (ISR). Additionally, it covers how to enable and disable interrupts and the structure of the interrupt vector table.

Uploaded by

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

MICROPROCESSOR

SYSTEMS

EE-222

AVR Interrupts
Interrupt vs Polling
I/O SERVICES

• A single microcontroller can serve several devices.


• Two ways:
• Polling method
• Interrupt method
POLLING VS. INTERRUPT

• Polling • Interrupt

• Ties down the CPU • Efficient CPU use


• Has priority
• Can be masked

while (true) main( )

{ {

if(PIND.2 == 0) Do your common task

//do something; }

}
whenever PIND.2 is 0 then
do something
POLLING METHOD

• What if you had to use all three timers


CPU
simultaneously?
NO
• The microcontroller continuously monitors the If TOV0
TOVx status of a given timer.
YES
• When the condition is met, it performs the
service. Handle TOV0
• After that, it moves on to monitor the next
device until everyone is serviced. NO
If TOV1
• The microcontroller check all devices in a round-
robin fashion. YES
••••

NO
If TOV2

YES
Handle TOV2
INTERRUPT METHOD

• An interrupt is an external or internal event that interrupts the


microcontroller to inform it that a device needs its service.
• Whenever any device needs its service, the device notifies the
microcontroller by sending it an interrupt signal.
• Upon receiving an interrupt signal, the microcontroller interrupts
whatever it is doing and serves the device by executing the Interrupt
Service Routine.

Peripherals
Timers
IRQ0
CPU IRQ1 I/Os
Interrupt IRQ2
Controller IRQ3 USART
….

IRQn
SPI
THE ADVANTAGE OF
INTERRUPTS

• The use of microcontroller is more efficient.


• In polling system, SBRS R20,TOV0 wastes much of the microcontroller’s time.

• The microcontroller can monitor many devices simultaneously.

• Each device can get service based on the priority assigned to it.

• The microcontroller can ignore (mask) a device request.


INTERRUPT CONTROL UNIT IN AVR

SREG I T HRAM S V EEPROM


N Z C Timers

PROGRAM
ROM

Program
Bus Bus
CPU

SREG

EIMSK
PCICR
PCMSK0
PCMSK1 Other
OSC PCMSK2 Ports
Peripherals
Interrupt Unit
TIMSK0
TIMSK1
TIMSK2
I/O
PINS
Steps in Executing an Interrupt
REVIEW OF C ALL A SUBROUTINE

ROM addr.

0000
ROM addr. DELAY
0300 OUT DDRB,0FFH;

0004 CALL DELAY;


0006 IN PORTA,20;
0008
return address 0304 RET;
STEPS IN EXECUTING AN AVR
INTERRUPT (1/2)

• Upon activation of an interrupt, the microcontroller goes through the


following steps:
1. It finishes the instruction it is executing and saves the address of the next
instruction (PC) on the stack.

2. It jumps to a fixed location in memory based on the interrupt vector table. [see
couple of slides down]

3. The microcontroller gets the address of the ISR from the interrupt vector table
and jumps to it.

4. The microcontroller starts to execute the interrupt service routine until it


reaches the last instruction of the subroutine which is RETI (return from
interrupt).
STEPS IN EXECUTING AN AVR
INTERRUPT (2/2)

• Executing steps (continuous):


5. 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 two bytes of the stack into the PC.
• Then it starts to execute from that address.
Interrupt Service Routine (ISR)
INTERRUPT SERVICE ROUTINE
(ISR)

• ISRs are like normal subroutines.


• ISRs are generated by programs to handle interrupt events.
• For every interrupt, there must be an ISR.
• For every interrupt event, its corresponding ISR is held at a fixed
location in memory.

TOV0 0000
.... Reserved
1 0012 ISR of timer0 for
jumps to .... Interrupt
....
0028
main program
....
THE ADDRESSES OF ISRS

• The group of memory locations set aside to hold the addresses of ISRs is called
the interrupt vector table.

• See AVR Interrupt Vector Table in next slide.


16
INTERRUPT VECTOR TABLE

• Normally, the ISR for an interrupt is too long to fit into the memory space
allocated inside the interrupt vector table.

• For that reason, a JMP instruction is placed in the vector table to point to
the address of the ISR.
How to Enable and Disable an Interrupt?
ENABLE/DISABLE INTERRUPTS

IE register
External
Interrupt 0

Timer/
Counter 0

External
Interrupt 1

Timer/ I–
CPU
Counter 1 [Gloable
Inettrupt
Serial Enable]
Port

Timer/
Counter 2
GLOBAL INTERRUPT ENABLE

SEI ; set I (enable interrupts globally)


TIMER INTERRUPT MASK REGISTER
(TIMSK)

LDI R16, 1<<TOV0


OUT TIMSK, R16;
enable Timer0 overflow interrupts
NOTICES

• Interrupt is disable upon RESET.

• You can open the functionality of interrupt or not.

• You can choose to disable some interrupt events,


• You do not need to write ISRs for them.

• Programmers must enable these interrupts before using them.


RECOMMENDED READING

• The AVR Microcontroller and Embedded Systems: Using


Assembly and C by Mazidi et al., Prentice Hall
• Chapter 10
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy