Skip to content
Tactiverge

Computer architecture

Interrupts

Also called: ISR · interrupt service routine · IRQ · interrupt latency

Definition

An interrupt is a hardware signal that makes the processor pause the main program, run a short interrupt service routine (ISR), and then resume where it left off.

Picture it

Instead of checking a button a thousand times a second, let the button tap the processor on the shoulder. ISRs must be short: set a flag or count an encoder tick, then return, and let the main loop do the heavy work. Variables shared with an ISR must be marked volatile.

The maths

CPU load from interrupts = rate × (ISR cycles) / f_clock
SI units used in this entry
QuantityUnitSymbol
frequencyhertzHz
timeseconds
percentageper cent%

Worked example

An encoder generates 20000 interrupts per second. Each ISR takes 90 cycles on a 48 MHz processor. What fraction of CPU time do the interrupts use?

  1. Cycles per second = 20000 × 90 = 1800000
  2. Fraction = 1800000 / 48000000 = 0.0375 = 3.75 %

Answer3.75 % of the CPU.

✓ The number in this answer is recomputed from scratch by an automated test.

Common misconceptions

  • Misconception: Printing or delaying inside an ISR blocks everything else.
  • Misconception: Interrupts are not threads; they cannot be paused and resumed arbitrarily.