SlideShare une entreprise Scribd logo
1  sur  22
INTERRUPTS
Prepared by:

Islam Samir
INTERRUPT

-

Definition:
An interrupt is an asynchronous signal indicate for an
event which needs processor’s attention immediately
regardless to the instruction it executes at this moment.

It’s like a
Doorbell.
WHY DO WE USE INTERRUPTS?
Example. (Software Polling)
Assume that the MCU is supposed to do two tasks.
-

In one of them, it needs to know if a certain I/O pin is „1‟ or not yet.

-

We can do so by checking if this pin is „1‟ or „0‟, which called
“Polling”.

-

By this method, the MCU is doing nothing but waiting for the pin to
be high, the 2nd task can‟t be done in this time.

 Wasting MCU’s time.
-

If the MCU left this task to do the 2nd task. While executing it, the pin
became high. It won‟t know (the check won‟t be done) until it leaves
the 2nd task.

 Slow response to important events.
INTERRUPT


Instead of checking each pin constantly (polling) and wasting the
processor’s time, the MCU waits for the interrupt signal that
indicates for the waited event.



When this interrupt signal equals ‘1’ :
The MCU leaves the current program.
Executes the predefined code for this event and returns back to
the original program.

I.

II.
COMPARISON
Interrupts

Software Polling

Save processor‟s time.

Waste processor‟s time.

Fast response from the CPU to the
event that has happened

The processor‟s response depends
on where it‟s in the program.

Can‟t be used with switches or
sensors. (because of Bouncing)

Used with switches or sensors

Ex. Timers.

Ex. Switches.
INTERRUPT DEFINITIONS

-


-


-

Interrupt Flag (IF):
A bit that is automatically set if the interrupt source (event) happens.
Global Interrupt Enable (GIE):
Enables (if set) all un-masked interrupts (interrupts with IE=1) or disables
(if cleared) all interrupts.
Interrupt Enable (IE):
If the GIE was ‘1’, this bit forces the CPU to respond to the interrupt signal
when IF=1  when the waited event happens.
INTERRUPT DEFINITIONS

-

-

-

Interrupt service routine (ISR):
The code which the CPU jumps to when an interrupt happens.
Actually, the CPU will automatically jumps to the (interrupt vector)
0004h.
From there the code should be written to force the MCU to jump to
the ISR address.
INTERRUPTS


1)

2)

3)

When the event (interrupt source) happens, the following steps happen:

The corresponding interrupt flag (IF) will equal ‘1’.
If the interrupt enable (IE) was ‘1’, and the global interrupt enable
(GIE) was ‘1’ also, the GIE is cleared by hardware to avoid
responding any further interrupt
The return address is pushed into the stack and the PC is loaded with
0004h (the interrupt vector).
INTERRUPTS
4)

In the ISR, you can determine the source of interrupt by polling the
interrupt flag bits and do the required action for it.

5)

(Context Switching) You have to save key registers values before
interrupt has happened e.g. W register and STATUS register. This has
to be implemented in software
If you use high level language the compiler will do it for you.

-

4)

At the end of the ISR, you’ve to clear the IF in software then set the
GIE bit in the end of the ISR code.
HOW ARE INTERRUPTS IMPLEMENTED IN
MICROPROCESSORS?
If interrupts are not used, the control unit goes through the
ordinary instruction cycle:
I.
Fetch instruction. ( Ins. register<--M[PC] ).
II.
Decode the instruction.
III. Execute it.

HOW ARE INTERRUPTS IMPLEMENTED IN
MICROPROCESSORS?


When interrupts are used in the microprocessor, the control
unit checks first if there is an interrupt signal or not.

If the interrupt signal was „1‟, it goes through interrupt cycle:
I.
Store the current address into the stack.

(the address of the next instruction which should have been
loaded if there is no interrupt).
II.
Load the PC with the interrupt vector address.
III. Make the GIE=„0‟.

Interrupt
signal?
T

F

Interrupt cycle

Instruction cycle

Stack <-- return address

PC <-- Interrupt vector

In
S.W., m
ake
IF=0

GIE=0

Fetch

Decode

Execute
HOW ARE INTERRUPTS IMPLEMENTED IN
MICROPROCESSORS?


The last instruction in the ISR should be:
RETFIE (return from interrupt).



This instruction makes the control unit loads the PC with the address
stored in the stack so that the original program can continue.
INTERRUPT SOURCES IN THE PIC 16 MCU


INT Pin Interrupt (external interrupt)



TMR0 Overflow Interrupt



PORTB Change Interrupt (pins RB7:RB4)



Comparator Change Interrupt



Parallel Slave Port Interrupt



USART Interrupts



Receive Interrupt



Transmit Interrupt



A/D Conversion Complete Interrupt



Data EEPROM Write Complete Interrupt



Timer1 Overflow Interrupt



Timer2 Overflow Interrupt



CCP Interrupt



SSP Interrupt
INTERRUPT SOURCES
-

-

Many peripherals use interrupts when finishing its job (ex.
USART, ADC, Timers …), or when there is a problem needs to
be configured (ex. EEPROM Write Complete ).
Here, we’ll talk about the simplest type of interrupt, and the
rest of interrupt sources should be handled in the same way.

Very important:
 If you configure the MCU to respond to more than one
interrupt source at the same time, to determine which one has
happened, pull their flags in the ISR (check which one equals
1).
RB0/INT


The RB0/INT pin is a single external interrupt source.



When the waited edge rising or falling edge as selected)
happens on RB0 pin, the interrupt signal is generated.



It can be configured to react to signal raising edge or signal
falling edge.
RB0/INT
Steps:
1.
Configure the interrupt source to work as you want, here :
falling or rising edge.



2.

Set the IE bit of this interrupt source.

3.

Write the Interrupt Service Routine (ISR).

4.

Set the GIE bit.
EXAMPLE



Make the led illuminates when the button is pressed, using
RB0 interrupt.
ASSIGNMENT

-

Make an application using interrupts,
detects raising edge signals on RB0,
and detect any change happens is PORTB <7:4> and
respond to it as specified in the next table:
PORTB<7:4>

PORTC<7:4>

xxx1

xxx1

xx1x

xx1x

x1xx

x1xx

1xxx

1xxx

Contenu connexe

Tendances

INTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORINTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORGurudev joshi
 
Instruction cycle presentation
Instruction   cycle presentationInstruction   cycle presentation
Instruction cycle presentationMoniba Irfan
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle pptsheetal singh
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output OrganizationKamal Acharya
 
Basic ops concept of comp
Basic ops  concept of compBasic ops  concept of comp
Basic ops concept of compgaurav jain
 
Instruction Cycle in Computer Organization.pptx
Instruction Cycle in Computer Organization.pptxInstruction Cycle in Computer Organization.pptx
Instruction Cycle in Computer Organization.pptxYash346903
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingTushar Swami
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference InstructionsRabin BK
 
Micro Programmed Control Unit
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control UnitKamal Acharya
 
RISC and CISC Processors
RISC and CISC ProcessorsRISC and CISC Processors
RISC and CISC ProcessorsAdeel Rasheed
 
Introduction to Bus | Address, Data, Control Bus
Introduction to Bus | Address, Data, Control BusIntroduction to Bus | Address, Data, Control Bus
Introduction to Bus | Address, Data, Control BusHem Pokhrel
 
Central processing Unit.pptx
Central processing Unit.pptxCentral processing Unit.pptx
Central processing Unit.pptxabdullahi26027
 
Registers and-common-bus
Registers and-common-busRegisters and-common-bus
Registers and-common-busAnuj Modi
 

Tendances (20)

INTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORINTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSOR
 
Instruction cycle presentation
Instruction   cycle presentationInstruction   cycle presentation
Instruction cycle presentation
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Interrupts
InterruptsInterrupts
Interrupts
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
 
Basic ops concept of comp
Basic ops  concept of compBasic ops  concept of comp
Basic ops concept of comp
 
Instruction Cycle in Computer Organization.pptx
Instruction Cycle in Computer Organization.pptxInstruction Cycle in Computer Organization.pptx
Instruction Cycle in Computer Organization.pptx
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set Computing
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
Micro Programmed Control Unit
Micro Programmed Control UnitMicro Programmed Control Unit
Micro Programmed Control Unit
 
Registers
RegistersRegisters
Registers
 
RISC and CISC Processors
RISC and CISC ProcessorsRISC and CISC Processors
RISC and CISC Processors
 
control unit
control unitcontrol unit
control unit
 
Introduction to Bus | Address, Data, Control Bus
Introduction to Bus | Address, Data, Control BusIntroduction to Bus | Address, Data, Control Bus
Introduction to Bus | Address, Data, Control Bus
 
Instruction cycle
Instruction cycleInstruction cycle
Instruction cycle
 
Central processing Unit.pptx
Central processing Unit.pptxCentral processing Unit.pptx
Central processing Unit.pptx
 
Registers and-common-bus
Registers and-common-busRegisters and-common-bus
Registers and-common-bus
 
Interrupt
InterruptInterrupt
Interrupt
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
 

Similaire à Interrupts

Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kVijay Kumar
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxSujalKumar73
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Vikas Dongre
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interruptsdharmesh nakum
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxnaveen088888
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVRHamdy Fouad
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085ShivamSood22
 
8086 Interrupts & With DOS and BIOS by vijay
8086 Interrupts &  With DOS and BIOS  by vijay8086 Interrupts &  With DOS and BIOS  by vijay
8086 Interrupts & With DOS and BIOS by vijayVijay Kumar
 
unit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxpppppppppppppppppppppppppppunit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxpppppppppppppppppppppppppppsachin397946
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18raosandy11
 

Similaire à Interrupts (20)

Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptx
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
 
Interrupt 8085
Interrupt 8085Interrupt 8085
Interrupt 8085
 
DPA
DPADPA
DPA
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
 
Interrupts
InterruptsInterrupts
Interrupts
 
Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interrupts
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVR
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Interrupts of 8085
Interrupts of 8085Interrupts of 8085
Interrupts of 8085
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Embedded systems, lesson 16
Embedded systems, lesson 16Embedded systems, lesson 16
Embedded systems, lesson 16
 
8086 Interrupts & With DOS and BIOS by vijay
8086 Interrupts &  With DOS and BIOS  by vijay8086 Interrupts &  With DOS and BIOS  by vijay
8086 Interrupts & With DOS and BIOS by vijay
 
ES-CH6.ppt
ES-CH6.pptES-CH6.ppt
ES-CH6.ppt
 
unit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxpppppppppppppppppppppppppppunit 3 a.pptxppppppppppppppppppppppppppp
unit 3 a.pptxppppppppppppppppppppppppppp
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18
 
Interrupts
InterruptsInterrupts
Interrupts
 

Plus de Islam Samir

Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog worldIslam Samir
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIslam Samir
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architecturesIslam Samir
 

Plus de Islam Samir (6)

USART
USARTUSART
USART
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
 
Timers
TimersTimers
Timers
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and Microcontrollers
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures
 

Dernier

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Interrupts

  • 2.
  • 3. INTERRUPT  - Definition: An interrupt is an asynchronous signal indicate for an event which needs processor’s attention immediately regardless to the instruction it executes at this moment. It’s like a Doorbell.
  • 4. WHY DO WE USE INTERRUPTS? Example. (Software Polling) Assume that the MCU is supposed to do two tasks. - In one of them, it needs to know if a certain I/O pin is „1‟ or not yet. - We can do so by checking if this pin is „1‟ or „0‟, which called “Polling”. - By this method, the MCU is doing nothing but waiting for the pin to be high, the 2nd task can‟t be done in this time.  Wasting MCU’s time. - If the MCU left this task to do the 2nd task. While executing it, the pin became high. It won‟t know (the check won‟t be done) until it leaves the 2nd task.  Slow response to important events.
  • 5. INTERRUPT  Instead of checking each pin constantly (polling) and wasting the processor’s time, the MCU waits for the interrupt signal that indicates for the waited event.  When this interrupt signal equals ‘1’ : The MCU leaves the current program. Executes the predefined code for this event and returns back to the original program. I. II.
  • 6. COMPARISON Interrupts Software Polling Save processor‟s time. Waste processor‟s time. Fast response from the CPU to the event that has happened The processor‟s response depends on where it‟s in the program. Can‟t be used with switches or sensors. (because of Bouncing) Used with switches or sensors Ex. Timers. Ex. Switches.
  • 7. INTERRUPT DEFINITIONS  -  -  - Interrupt Flag (IF): A bit that is automatically set if the interrupt source (event) happens. Global Interrupt Enable (GIE): Enables (if set) all un-masked interrupts (interrupts with IE=1) or disables (if cleared) all interrupts. Interrupt Enable (IE): If the GIE was ‘1’, this bit forces the CPU to respond to the interrupt signal when IF=1  when the waited event happens.
  • 8.
  • 9. INTERRUPT DEFINITIONS  - - - Interrupt service routine (ISR): The code which the CPU jumps to when an interrupt happens. Actually, the CPU will automatically jumps to the (interrupt vector) 0004h. From there the code should be written to force the MCU to jump to the ISR address.
  • 10. INTERRUPTS  1) 2) 3) When the event (interrupt source) happens, the following steps happen: The corresponding interrupt flag (IF) will equal ‘1’. If the interrupt enable (IE) was ‘1’, and the global interrupt enable (GIE) was ‘1’ also, the GIE is cleared by hardware to avoid responding any further interrupt The return address is pushed into the stack and the PC is loaded with 0004h (the interrupt vector).
  • 11. INTERRUPTS 4) In the ISR, you can determine the source of interrupt by polling the interrupt flag bits and do the required action for it. 5) (Context Switching) You have to save key registers values before interrupt has happened e.g. W register and STATUS register. This has to be implemented in software If you use high level language the compiler will do it for you. - 4) At the end of the ISR, you’ve to clear the IF in software then set the GIE bit in the end of the ISR code.
  • 12.
  • 13. HOW ARE INTERRUPTS IMPLEMENTED IN MICROPROCESSORS? If interrupts are not used, the control unit goes through the ordinary instruction cycle: I. Fetch instruction. ( Ins. register<--M[PC] ). II. Decode the instruction. III. Execute it. 
  • 14. HOW ARE INTERRUPTS IMPLEMENTED IN MICROPROCESSORS?  When interrupts are used in the microprocessor, the control unit checks first if there is an interrupt signal or not. If the interrupt signal was „1‟, it goes through interrupt cycle: I. Store the current address into the stack.  (the address of the next instruction which should have been loaded if there is no interrupt). II. Load the PC with the interrupt vector address. III. Make the GIE=„0‟. 
  • 15. Interrupt signal? T F Interrupt cycle Instruction cycle Stack <-- return address PC <-- Interrupt vector In S.W., m ake IF=0 GIE=0 Fetch Decode Execute
  • 16. HOW ARE INTERRUPTS IMPLEMENTED IN MICROPROCESSORS?  The last instruction in the ISR should be: RETFIE (return from interrupt).  This instruction makes the control unit loads the PC with the address stored in the stack so that the original program can continue.
  • 17. INTERRUPT SOURCES IN THE PIC 16 MCU  INT Pin Interrupt (external interrupt)  TMR0 Overflow Interrupt  PORTB Change Interrupt (pins RB7:RB4)  Comparator Change Interrupt  Parallel Slave Port Interrupt  USART Interrupts  Receive Interrupt  Transmit Interrupt  A/D Conversion Complete Interrupt  Data EEPROM Write Complete Interrupt  Timer1 Overflow Interrupt  Timer2 Overflow Interrupt  CCP Interrupt  SSP Interrupt
  • 18. INTERRUPT SOURCES - - Many peripherals use interrupts when finishing its job (ex. USART, ADC, Timers …), or when there is a problem needs to be configured (ex. EEPROM Write Complete ). Here, we’ll talk about the simplest type of interrupt, and the rest of interrupt sources should be handled in the same way. Very important:  If you configure the MCU to respond to more than one interrupt source at the same time, to determine which one has happened, pull their flags in the ISR (check which one equals 1).
  • 19. RB0/INT  The RB0/INT pin is a single external interrupt source.  When the waited edge rising or falling edge as selected) happens on RB0 pin, the interrupt signal is generated.  It can be configured to react to signal raising edge or signal falling edge.
  • 20. RB0/INT Steps: 1. Configure the interrupt source to work as you want, here : falling or rising edge.  2. Set the IE bit of this interrupt source. 3. Write the Interrupt Service Routine (ISR). 4. Set the GIE bit.
  • 21. EXAMPLE  Make the led illuminates when the button is pressed, using RB0 interrupt.
  • 22. ASSIGNMENT  - Make an application using interrupts, detects raising edge signals on RB0, and detect any change happens is PORTB <7:4> and respond to it as specified in the next table: PORTB<7:4> PORTC<7:4> xxx1 xxx1 xx1x xx1x x1xx x1xx 1xxx 1xxx