(MCU) Lecture 3 - Interrupts
(MCU) Lecture 3 - Interrupts
Timer Interrupt
Interrupt in Microcontroller
2
Interrupt in Microcontroller
▪ MCU/MPU gets the program counter (PC) address from the stack pointer by popping the top
two bytes of the stack into the PC
▪ Then it starts to execute from that address and continue executing main program.
3
Interrupt in Microcontroller
4
Interrupt in Microcontroller
Advantages - Disadvantages
▪ It increases the efficiency of ▪ CPU has to handle
CPU. interrupts, resume its
▪ It decreases the waiting time of previous execution of
CPU. programs
▪ Stops the wastage of instruction ▪ Overhead required to handle
cycle. the interrupt request can
▪ Enables multitasking by reduce the efficiency of the
allowing the CPU to quickly system
switch between different ▪ Nested interrupts can
processes. occur when there is high
▪ Simplifies input/output (I/O)
levels of interrupt activity
operations by allowing devices to ▪ Priority inversion can occur
communicate directly with the when a low-priority task
CPU. holds a resource needed by
a higher-priority task
▪ The keyword to build RTOS
5
Interrupt in Microcontroller
Types of Interrupts
▪ Hardware interrupts:
▫ Maskable: Can be masked or disabled
▫ Non-maskable: Cannot be disabled
▫ External and Internal interrupts
6
Interrupt in Microcontroller
main main
main main
Components of NVIC
▪ Clock Security System
(CSS) interrupt is connected
to Non-Maskable Interrupt
(NMI) lines
▪ Peripheral interrupts are
connected to Interrupt
Requests (IRQ) lines
▪ GPIO interrupts are connected
to an External
Interrupt/Event Controller
(EXTI) before connecting to
the IRQ lines
10
Interrupt in Microcontroller
11
Timer Interrupt
Interrupt in Microcontroller
Timer Interrupt
Clock Configuration
14
Interrupt in Microcontroller
Parameter Settings
The clock source is 8MHz,
by setting the prescaller to
7999, the input clock
source to the timer is
8MHz/(7999+1) =
1000Hz
15
Interrupt in Microcontroller
NVIC Settings
16
Interrupt in Microcontroller
ISR Implementation
17