Interrupt in
Embeded System
Prepared BY :
Mohammed Abd-Elrazik
Abd-Alrhman Miloud
Supervised By :
Abdelfattah Bushnaf
Table of contents
Principle of
01 Introduction 05 operation
02 Types of Interrupt 06 Interrupt Priority
STACK & PROGRAM Benefits of
03 COUNTER 07 Interrupt
Interrupt Service
04 Routine 08 Conclusion
INTRODUCTION
In many microcontrollers, we find some functions
that require an ultra-fast response to a specific
event. This must be taken into account in most
microcontrollers (even old ones) where interrupt
function has been added. Interrupts play a crucial
role in computer devices by allowing the
processor to react quickly to events or requests
from external devices or software.
The interrupt is a signal emitted by hardware or
software when a process or an event needs
immediate attention. It alerts the processor to a
high-priority process requiring interruption of the
current working process.
Types of Interrupts
Hardware Interrupts:
If the signal for the processor is from devices or hardware is called hardware interrupts.
• External Interrupts: Triggered by external events, such as a button press or signal from a sensor.
• Internal Interrupts: Triggered by internal events, such as a timer overflow.
software interrupt
A software interrupt is generated by a program or the operating system, rather than by hardware components.
It occurs either due to an exceptional condition or via a specific instruction designed to trigger an interrupt
when executed by the processor.
For example, if the processor's arithmetic logic unit runs a command to divide a number by zero, to cause a
divide-by-zero exception, thus causing the computer to abandon the calculation or display an error message.
STACK & PROGRAM COUNTER
Stack Program Counter
The Stack memory is a special and temporary The program counter is a register in a computer
area in the Random Access Memory (RAM) used processor that stores the memory address of
to store data that the processor needs quickly the next instruction to be executed. It keeps
and temporarily while executing the program. track of the current position in the program's
sequence of instructions, allowing the processor
This memory is based on a simple engineering to fetch the next instruction from memory and
principle called LIFO (which stands for Last-In, execute it. The program counter is a crucial
First-Out). component in the control flow of a computer
program
When an interrupt occurs, the processor
immediately pushes the current state of the
registers and the address of the next instruction
onto the stack, then executes the interrupt, and
when it finishes, it pops them to restore its
previous state as if nothing had happened.
Interrupt Service Routine
Interrupt Service Routine (ISR) is a specialized function or routine that is called when an
interrupt is triggered by a hardware device.
During an interrupt, the processor automatically switches to the ISR, which handles the
specific task associated with the interrupt (such as reading data from a device or
acknowledging the interrupt). ISRs are critical for real-time systems and embedded
applications, ensuring that the CPU responds swiftly to hardware events without disrupting
normal program flow.
In all microcontrollers the code responsible for handling interrupts is designed completely
independently of the main program, so we always find that the interrupt service, called
Interrupt service routine (ISR), is written in a remote part of the main function.
Principle of operation
1 2 3
The system's interrupt controller The processor temporarily Control transfers to the ISR
detects and prioritizes the suspends the current program, associated with the triggered
interrupt based on its type and saving its state (e.g., program interrupt. The ISR performs
configuration. counter, registers) to the stack. necessary tasks, such as reading
device data, and initiating further
actions.
Principle of operation
4 5 6
Once the ISR completes its tasks, it The processor restores the saved The processor resumes executing
signals the interrupt controller state (The last instruction where the interrupted program from
that the interrupt has been the program stopped) of the where it left off.
serviced. interrupted program from the
stack.
Interrupt Priority
RESET
External
Interrupt
Internal
Interrupt
Benefits of Interrupt
Real-time Asynchronous Efficient CPU Increased
Responsiveness Event Handling Utilization protection and
security
01
Business
plan
Thanks!
Do you have any questions?
Slidesgo
CREDITS: This presentation template was created by Slidesgo, and includes icons by
Flaticon Freepik
Flaticon, and infographics & images by Freepik