How to Measure Interrupt Latency

Interrupt latency is the time from the pin change to the first action in the handler. The core’s catalogue figure is not the whole of that time.

How to Measure Interrupt Latency

Interrupt latency is the time from a pin changing to the first response of the software. The cycle count in the core manual is the time for the processor to accept the interrupt and reach the first instruction. The measured time also carries the peripheral, the priority, and any stretch where interrupts are masked. The catalogue number is not a substitute for the time on the board.

The ARM Cortex-M4 Devices Generic User Guide (DUI 0553) describes how the core enters an interrupt and how tail-chaining works. A higher-priority interrupt does not wait for a lower-priority one to finish. The lower-priority one waits for the higher one. If interrupts are off inside a critical section, the time stretches until that section ends. If the length of the critical section is not written down, the measurement is read as "the core is slow".

Measurement is done two ways. The first toggles a pin on the first line of the handler and views that pin on a scope next to the pin that triggered the interrupt. The time between the two edges is the latency at that moment. The second reads the DWT cycle counter on the Cortex-M at the trigger and at the start of the handler. If the two methods do not measure the same thing, one of them is reading the wrong place. The counter keeps running while interrupts are masked; the scope edge shows that separately.

Yiu's Cortex-M book treats how latency changes with tail-chaining and late arrival. A single "typical microsecond" cannot be written for every board. Clock frequency, memory wait states and the interrupt already running change the number. The number is reported together with the conditions of the measurement.

When a FenergyTech job needs a latency, the time is measured with its conditions. The cycle count in the core manual does not stand in for that measurement.

The measurement starts with an edge. The trigger pin changes, and the first line of the handler changes a second pin. The scope gives the time between the two edges. That time is the latency at that moment. The cycle count in the catalogue is the time for the core to accept the interrupt and reach the first instruction. The measured time adds the masked stretch and the interrupt that was already running. They are not the same number.

The DWT counter reads the same interval in cycles. The counter keeps running while interrupts are masked. The scope edge shows that. The counter alone does not say "the core took this long". If the two methods disagree, one of them is reading the wrong line. The read is done before the handler's first piece of work. Done after, the measurement includes the work itself.

The conditions are written: clock, memory waits, which interrupts were enabled, the longest critical section. Without them, 12 microseconds means another job on another board. Yiu treats how tail-chaining and late arrival change this time. A single "typical" is not written for every board.

Sources: ARM, Cortex-M4 Devices Generic User Guide, DUI 0553. J. Yiu, The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors, 3rd ed., Newnes, 2014.

Share:

Planning a similar project?

We can talk through how the topic in this article applies to your product.

More articles

Browse our other technical articles