SlideShare a Scribd company logo
1 of 26
Download to read offline
Interrupts
Eman Aboelatta

Copyright © 2012 Embedded Systems
Committee
Agenda:
•
•
•
•
•
•
•
•
•
•

Introduction
Interrupts
Interrupt sequence
So how to we define an ISR?
Interrupt Vector Table
Modifying Interrupt Vector Table of ATmega16
Registers Used
Interrupt priorities
Interrupt nesting
Nested Interrupt Priorities

Copyright © 2012 Embedded Systems
Committee
Introduction:
At first we have two methods for receiving data or get status

Polling

Interrupt

Copyright © 2012 Embedded Systems
Committee
Introduction:con’t
Polling :
which involves reading the status of the port at fixed intervals to
determine whether any data has been received or a change of status
has occurred. If so, then we can branch to a routine to service the
ports requests.
oTakes CPU time even when no requests pending.

oOverhead.
“Polling is like picking up your phone every few seconds to see if
you have a call. …”

Other alternative would be to use Interrupts.
Copyright © 2012 Embedded Systems
Committee
Interrupts (IR):
 Interrupts can be used to interrupt the sequential execution of
the program flow(called asynchronous processing - that is, we are
processing the interrupt events outside the regular execution of the
main program.)

 Interrupt sources can be
- external events (e.g. change of signal at PORTB2).
- internal events.

Hardware interrupt
(e.g. timer
overflow).

Software interrupt

(which occur in response
to a command issued in
software-Exception
Handling )
Copyright © 2012 Embedded Systems
Committee
Interrupts (IR):con’t
Non Maskable Interrupts :

doesn’t depend on global interrupt enable in processor status word
Usually it’s external interrupt(Ex : Reset).
Maskable Interrupts:
Depends on global interrupt enable in processor status word
May be :
External interrupt from external pin
Internal interrupt from peripheral

Copyright © 2012 Embedded Systems
Committee
Interrupts (IR):Con’t




In the case of an interrupt event
the execution of the main
routine is interrupted and the
interrupt service routine (ISR)
of the according event is
executed.

After executing the ISR the
execution proceeds where it has
been interrupted.

Copyright © 2012 Embedded Systems
Committee
Interrupt sequence:
When the CPU detects

The CPU finishes its current instruction.
The contents of the program counter and the condition code
register(status register or Processor status word) are pushed
onto the stack(because the interrupt routine will almost
certainly modify the condition code bits).
Further interrupts are disabled to avoid an interrupt being
interrupted.
The CPU deals with the cause of the interrupt by executing
a program called an interrupt handler(ISR)(Interrupt service
routine).
The CPU executes a return from interrupt instruction at the
end of the interrupt handler. Executing this instruction pulls
the PC and PSW off the stack and execution then continues
normally—as if the interrupt had never happened.
Copyright © 2012 Embedded Systems
Committee
Interrupt sequence: con’t

o PSR : Processor Status
Register ==status
register==Condition Code
register

o PC : Program Counter

(contains Address of next
instruction to be executed)

Copyright © 2012 Embedded Systems
Committee
So how to we define an ISR?
For an ISR to be called, we need three conditions to be
true:
Firstly, the AVR's global Interrupts Enable bit (I) must be set in
the MCU control register SREG.

Secondly, the individual interrupt source's enable bit must be

set. Each interrupt source has a separate interrupt enable bit in
the related peripheral's control registers, which turns on the
ISR for that interrupt.

Thirdly, The condition for the interrupt must be met - for

example, for the USART Receive Complete (USART RX)
interrupt, a character must have been received(i.e flag that
indicate interrupt raised)
Copyright © 2012 Embedded Systems
Committee
So how to we define an ISR?con’t
Enable Global interrupt (I)

Execute ISR

Enable peripheral interrupt
Interrupt occurred (flag
raised)

Copyright © 2012 Embedded Systems
Committee
• Constant table in ROM.
• Special addresses with respect to CPU.
• Each interrupt has specific address in interrupt vector
table .
• This specific address should be programmed to have the
address of ISR of this interrupt.
• At interrupt processing PC will contain this address or it
will be an instruction to jump to this address
Copyright © 2012 Embedded Systems
Committee
Interrupt Vector Table:cont
• From Datasheet ATmega32/16.

Copyright © 2012 Embedded Systems
Committee
Modifying Interrupt Vector Table of
ATmega16:
 Assembly 
.org $000
rjmp Reset
.
.
.
.
.
Reset:
//instructions

C

ISR ({Vector Source}_vect)
{
// ISR code to execute here
}
Copyright © 2012 Embedded Systems
Committee
Registers Used
Status Register (SREG):To Enable Global Interrupt

• The status register contains:
– Six bits status indicators ( Z,C,H,V,N,S )
– One bit for global interrupt enable ( I )
• The status bits reflect the results of CPU operation as it executes
instructions
Copyright © 2012 Embedded Systems
Committee
Registers Used with Atmega32/16:
To Set/Clear global interrupt enable:

• Set global interrupt enable: (Allow)

• Clear global interrupt enable: (prevent)

The I-bit is cleared by hardware after an interrupt has
occurred, and is set by the RETI instruction to enable
subsequent interrupts.
Copyright © 2012 Embedded Systems
Committee
Registers Used with Atmega32/16:
GICR (General Interrupt Control Register):P.no 47

Copyright © 2012 Embedded Systems
Committee
Registers Used with Atmega32/16:
MCUCR (MCU Control Register) P.66

Copyright © 2012 Embedded Systems
Committee
Registers Used with Atmega32/16:
MCUCSR (MCU Control and Status Register) P67

Copyright © 2012 Embedded Systems
Committee
Registers Used with Atmega32/16:
GIFR (General Interrupt Flag Register)

Copyright © 2012 Embedded Systems
Committee
Defining ISR :
• ISR(Interrupt Service Routine)
#include <avr/interrupt.h>

ISR({Vector Source}_vect)
{
// ISR code to execute here
}

Copyright © 2012 Embedded Systems
Committee
Interrupt priorities:
• Each interrupt has default priority by its location in
interrupt vector table
• Some controllers provide more intelligent interrupt
controller which give interrupt priority level for each
interrupt
• If two interrupts have a same priority level then the rule
to return to the default priority

Copyright © 2012 Embedded Systems
Committee
Interrupt nesting:
• Interrupt Nesting: ability to leave the current interrupt
and serve another interrupt

• Usually done if global interrupt is enabled and this
interrupt has more priority
• Some controllers support the nesting of context switching
in hardware and others leave it to be done in software

Copyright © 2012 Embedded Systems
Committee
Nested Interrupt Priorities:

Copyright © 2012 Embedded Systems
Committee
References
• ATmega16 Datasheet.
• http://www.avrfreaks.net/

Copyright © 2012 Embedded Systems
Committee
info@escommittee.net

Copyright © 2012 Embedded Systems
Committee

More Related Content

What's hot (20)

Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
 
Embedded System Basics
Embedded System BasicsEmbedded System Basics
Embedded System Basics
 
Embedded Software Development
Embedded Software DevelopmentEmbedded Software Development
Embedded Software Development
 
Interrupts
InterruptsInterrupts
Interrupts
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Real Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systemsReal Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systems
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085
 
Rtos Concepts
Rtos ConceptsRtos Concepts
Rtos Concepts
 
Embedded system introduction
Embedded system introductionEmbedded system introduction
Embedded system introduction
 
Advanced pipelining
Advanced pipeliningAdvanced pipelining
Advanced pipelining
 
Controller Area Network(CAN)
Controller Area Network(CAN)Controller Area Network(CAN)
Controller Area Network(CAN)
 
Interrupts
InterruptsInterrupts
Interrupts
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
Embedded system
Embedded systemEmbedded system
Embedded system
 

Similar to Interrupts

Device drivers and interrupt service mechanism
Device drivers and interrupt service mechanismDevice drivers and interrupt service mechanism
Device drivers and interrupt service mechanismVijay Kumar
 
ESD III UNIT.pptx
ESD III UNIT.pptxESD III UNIT.pptx
ESD III UNIT.pptxECEHOD19
 
AAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced FeaturesAAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced FeaturesAnh Dung NGUYEN
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
 
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptxUNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptxLeahRachael
 
Assembly programming
Assembly programmingAssembly programming
Assembly programmingOmar Sanchez
 
Advanced Embedded System Subject seminar on SCB,DEBUG,RESET
Advanced Embedded System Subject seminar on SCB,DEBUG,RESETAdvanced Embedded System Subject seminar on SCB,DEBUG,RESET
Advanced Embedded System Subject seminar on SCB,DEBUG,RESETರೇಣುಕ ಭುವನ್
 
Unit 1 intro-embedded
Unit 1 intro-embeddedUnit 1 intro-embedded
Unit 1 intro-embeddedPavithra S
 
Run time, frequently, non-frequently reconfigurable system &
Run time, frequently, non-frequently reconfigurable system &Run time, frequently, non-frequently reconfigurable system &
Run time, frequently, non-frequently reconfigurable system &Sudhanshu Janwadkar
 
Embedded system - Introduction to interfacing with peripherals
Embedded system - Introduction to interfacing with peripheralsEmbedded system - Introduction to interfacing with peripherals
Embedded system - Introduction to interfacing with peripheralsVibrant Technologies & Computers
 
Top schools in delhi ncr
Top schools in delhi ncrTop schools in delhi ncr
Top schools in delhi ncrEdhole.com
 

Similar to Interrupts (20)

Device drivers and interrupt service mechanism
Device drivers and interrupt service mechanismDevice drivers and interrupt service mechanism
Device drivers and interrupt service mechanism
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
presentation on SCB,DEBUG,RESET of Arm Cortex processor
presentation on SCB,DEBUG,RESET of Arm Cortex processorpresentation on SCB,DEBUG,RESET of Arm Cortex processor
presentation on SCB,DEBUG,RESET of Arm Cortex processor
 
Interrupts.ppt
Interrupts.pptInterrupts.ppt
Interrupts.ppt
 
ESD III UNIT.pptx
ESD III UNIT.pptxESD III UNIT.pptx
ESD III UNIT.pptx
 
AAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced FeaturesAAME ARM Techcon2013 002v02 Advanced Features
AAME ARM Techcon2013 002v02 Advanced Features
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptxUNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
UNIT 5- UNDERSTANDING THE SYSTEM DESIGN PROCESS.pptx
 
Io pro
Io proIo pro
Io pro
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
IO hardware
IO hardwareIO hardware
IO hardware
 
Advanced Embedded System Subject seminar on SCB,DEBUG,RESET
Advanced Embedded System Subject seminar on SCB,DEBUG,RESETAdvanced Embedded System Subject seminar on SCB,DEBUG,RESET
Advanced Embedded System Subject seminar on SCB,DEBUG,RESET
 
Unit 1 intro-embedded
Unit 1 intro-embeddedUnit 1 intro-embedded
Unit 1 intro-embedded
 
Run time, frequently, non-frequently reconfigurable system &
Run time, frequently, non-frequently reconfigurable system &Run time, frequently, non-frequently reconfigurable system &
Run time, frequently, non-frequently reconfigurable system &
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Embedded system - Introduction to interfacing with peripherals
Embedded system - Introduction to interfacing with peripheralsEmbedded system - Introduction to interfacing with peripherals
Embedded system - Introduction to interfacing with peripherals
 
unit 5.pptx
unit 5.pptxunit 5.pptx
unit 5.pptx
 
Interrupts
InterruptsInterrupts
Interrupts
 
Interrupts
InterruptsInterrupts
Interrupts
 
Top schools in delhi ncr
Top schools in delhi ncrTop schools in delhi ncr
Top schools in delhi ncr
 

More from محمدعبد الحى (16)

Iso26262 component reuse_webinar
Iso26262 component reuse_webinarIso26262 component reuse_webinar
Iso26262 component reuse_webinar
 
Interfacing using ِAtmega16/32
Interfacing using ِAtmega16/32 Interfacing using ِAtmega16/32
Interfacing using ِAtmega16/32
 
Can bus
Can busCan bus
Can bus
 
Lin bus
Lin busLin bus
Lin bus
 
Embedded Systems in Automotive
Embedded Systems in Automotive Embedded Systems in Automotive
Embedded Systems in Automotive
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
CPU Architecture
CPU ArchitectureCPU Architecture
CPU Architecture
 
8 bit microcontroller
8 bit microcontroller8 bit microcontroller
8 bit microcontroller
 
Matlab workshop
Matlab workshopMatlab workshop
Matlab workshop
 
Timers
TimersTimers
Timers
 
Uart
UartUart
Uart
 
Sw testing
Sw testingSw testing
Sw testing
 
Rtos
RtosRtos
Rtos
 
Dio
DioDio
Dio
 
Micro controller
Micro controllerMicro controller
Micro controller
 
Day1
Day1Day1
Day1
 

Recently uploaded

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 

Recently uploaded (20)

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 

Interrupts

  • 1. Interrupts Eman Aboelatta Copyright © 2012 Embedded Systems Committee
  • 2. Agenda: • • • • • • • • • • Introduction Interrupts Interrupt sequence So how to we define an ISR? Interrupt Vector Table Modifying Interrupt Vector Table of ATmega16 Registers Used Interrupt priorities Interrupt nesting Nested Interrupt Priorities Copyright © 2012 Embedded Systems Committee
  • 3. Introduction: At first we have two methods for receiving data or get status Polling Interrupt Copyright © 2012 Embedded Systems Committee
  • 4. Introduction:con’t Polling : which involves reading the status of the port at fixed intervals to determine whether any data has been received or a change of status has occurred. If so, then we can branch to a routine to service the ports requests. oTakes CPU time even when no requests pending. oOverhead. “Polling is like picking up your phone every few seconds to see if you have a call. …” Other alternative would be to use Interrupts. Copyright © 2012 Embedded Systems Committee
  • 5. Interrupts (IR):  Interrupts can be used to interrupt the sequential execution of the program flow(called asynchronous processing - that is, we are processing the interrupt events outside the regular execution of the main program.)  Interrupt sources can be - external events (e.g. change of signal at PORTB2). - internal events. Hardware interrupt (e.g. timer overflow). Software interrupt (which occur in response to a command issued in software-Exception Handling ) Copyright © 2012 Embedded Systems Committee
  • 6. Interrupts (IR):con’t Non Maskable Interrupts : doesn’t depend on global interrupt enable in processor status word Usually it’s external interrupt(Ex : Reset). Maskable Interrupts: Depends on global interrupt enable in processor status word May be : External interrupt from external pin Internal interrupt from peripheral Copyright © 2012 Embedded Systems Committee
  • 7. Interrupts (IR):Con’t   In the case of an interrupt event the execution of the main routine is interrupted and the interrupt service routine (ISR) of the according event is executed. After executing the ISR the execution proceeds where it has been interrupted. Copyright © 2012 Embedded Systems Committee
  • 8. Interrupt sequence: When the CPU detects The CPU finishes its current instruction. The contents of the program counter and the condition code register(status register or Processor status word) are pushed onto the stack(because the interrupt routine will almost certainly modify the condition code bits). Further interrupts are disabled to avoid an interrupt being interrupted. The CPU deals with the cause of the interrupt by executing a program called an interrupt handler(ISR)(Interrupt service routine). The CPU executes a return from interrupt instruction at the end of the interrupt handler. Executing this instruction pulls the PC and PSW off the stack and execution then continues normally—as if the interrupt had never happened. Copyright © 2012 Embedded Systems Committee
  • 9. Interrupt sequence: con’t o PSR : Processor Status Register ==status register==Condition Code register o PC : Program Counter (contains Address of next instruction to be executed) Copyright © 2012 Embedded Systems Committee
  • 10. So how to we define an ISR? For an ISR to be called, we need three conditions to be true: Firstly, the AVR's global Interrupts Enable bit (I) must be set in the MCU control register SREG. Secondly, the individual interrupt source's enable bit must be set. Each interrupt source has a separate interrupt enable bit in the related peripheral's control registers, which turns on the ISR for that interrupt. Thirdly, The condition for the interrupt must be met - for example, for the USART Receive Complete (USART RX) interrupt, a character must have been received(i.e flag that indicate interrupt raised) Copyright © 2012 Embedded Systems Committee
  • 11. So how to we define an ISR?con’t Enable Global interrupt (I) Execute ISR Enable peripheral interrupt Interrupt occurred (flag raised) Copyright © 2012 Embedded Systems Committee
  • 12. • Constant table in ROM. • Special addresses with respect to CPU. • Each interrupt has specific address in interrupt vector table . • This specific address should be programmed to have the address of ISR of this interrupt. • At interrupt processing PC will contain this address or it will be an instruction to jump to this address Copyright © 2012 Embedded Systems Committee
  • 13. Interrupt Vector Table:cont • From Datasheet ATmega32/16. Copyright © 2012 Embedded Systems Committee
  • 14. Modifying Interrupt Vector Table of ATmega16:  Assembly  .org $000 rjmp Reset . . . . . Reset: //instructions C ISR ({Vector Source}_vect) { // ISR code to execute here } Copyright © 2012 Embedded Systems Committee
  • 15. Registers Used Status Register (SREG):To Enable Global Interrupt • The status register contains: – Six bits status indicators ( Z,C,H,V,N,S ) – One bit for global interrupt enable ( I ) • The status bits reflect the results of CPU operation as it executes instructions Copyright © 2012 Embedded Systems Committee
  • 16. Registers Used with Atmega32/16: To Set/Clear global interrupt enable: • Set global interrupt enable: (Allow) • Clear global interrupt enable: (prevent) The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. Copyright © 2012 Embedded Systems Committee
  • 17. Registers Used with Atmega32/16: GICR (General Interrupt Control Register):P.no 47 Copyright © 2012 Embedded Systems Committee
  • 18. Registers Used with Atmega32/16: MCUCR (MCU Control Register) P.66 Copyright © 2012 Embedded Systems Committee
  • 19. Registers Used with Atmega32/16: MCUCSR (MCU Control and Status Register) P67 Copyright © 2012 Embedded Systems Committee
  • 20. Registers Used with Atmega32/16: GIFR (General Interrupt Flag Register) Copyright © 2012 Embedded Systems Committee
  • 21. Defining ISR : • ISR(Interrupt Service Routine) #include <avr/interrupt.h> ISR({Vector Source}_vect) { // ISR code to execute here } Copyright © 2012 Embedded Systems Committee
  • 22. Interrupt priorities: • Each interrupt has default priority by its location in interrupt vector table • Some controllers provide more intelligent interrupt controller which give interrupt priority level for each interrupt • If two interrupts have a same priority level then the rule to return to the default priority Copyright © 2012 Embedded Systems Committee
  • 23. Interrupt nesting: • Interrupt Nesting: ability to leave the current interrupt and serve another interrupt • Usually done if global interrupt is enabled and this interrupt has more priority • Some controllers support the nesting of context switching in hardware and others leave it to be done in software Copyright © 2012 Embedded Systems Committee
  • 24. Nested Interrupt Priorities: Copyright © 2012 Embedded Systems Committee
  • 25. References • ATmega16 Datasheet. • http://www.avrfreaks.net/ Copyright © 2012 Embedded Systems Committee
  • 26. info@escommittee.net Copyright © 2012 Embedded Systems Committee