Ground Embedded KO Subscribe

3D Labs

Interrupts and Priority Simulation

Watch where the CPU jumps when an interrupt arrives in the middle of the main loop, and when it comes back. Try priority and preemption, long handlers, critical sections, and the endless re-entry you get when a flag is never cleared.

Controls

Execution trace last 40 ms

Filled spans are when the CPU ran that code. Red vertical lines mark when a request arrived.

Measurements

Button latency
-
UART latency
-
Main loop lap
-
Stack use
0 bytes

Try this

  1. The yellow marble is the CPU. Normally it circles the lower ring, the main loop. Press UART interrupt and it jumps to the middle level, runs the handler to the end, and returns to exactly where it left.
  2. While the UART handler is running, press Button interrupt. Its priority is higher, so it cuts into the UART handler and climbs to the top level. One more box lands on the stack tower. That is preemption.
  3. Set priority to Equal and repeat. Now it cannot cut in and waits for the UART handler to finish. "Button latency" below grows by that wait.
  4. Stretch UART ISR length and set UART reception to every 1.5 ms. The main loop barely runs, and the LED in the ring blinks more slowly. This is why handlers should be short.
  5. Set Critical section to 5 ms. While main keeps interrupts off, requests only wait (red dot) and are served the moment the section ends.
  6. Switch Clear flag to "Forgotten" and the UART handler is called again the instant it ends. The main loop stops for good.

How to read it

When an interrupt arrives, the CPU finishes the current instruction, saves eight registers on the stack, and jumps to the handler. When the handler ends, it restores them and goes back. Each box on the stack tower is one such save, 32 bytes.

Only a higher-priority interrupt can cut into a running handler. Equal or lower ones wait. On Cortex-M a smaller number means a higher priority.

This lab leaves out details such as the 12-cycle entry and focuses on ordering and where delay comes from. The times shown are example values.

FREE PDFGet the 3 free ebooksIf you want what you just ran written down: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →

This lab is also available in Korean. More labs: all 3D labs.