In this lesson, you will learn how to quantify the delay and variability in your system’s response to hardware interrupts to ensure your real-time deadlines are consistently met.
The Anatomy of Response Time
When a hardware event occurs, your system cannot react instantaneously. Interrupt Latency is the total time elapsed from the hardware signal being asserted to the first instruction of your Interrupt Service Routine (ISR) executing. This delay is composed of several factors: the CPU pipeline flush, the execution of any currently running ISRs with higher or equal priority, and the time the kernel spends disabling interrupts for critical sections.
Jitter is the variability of this latency. If your latency is consistently 5µs, your jitter is zero. However, if your latency fluctuates between 2µs and 10µs, you have 8µs of jitter, which makes the system non-deterministic.
Measuring Latency and Jitter
To measure these, we use an "Input-to-Toggle" approach. You trigger a hardware interrupt via an external signal (like a function generator) and toggle a GPIO pin immediately at the start of your ISR. By observing both the trigger signal and the GPIO toggle on an oscilloscope or logic analyzer, you can measure the delta.
// Inside your ISR
void GPIO_ISR_Handler(void) {
// Toggle pin immediately to mark start of ISR
GPIO_Write(DEBUG_PIN, HIGH);
// Perform essential work...
GPIO_Write(DEBUG_PIN, LOW);
}
To evaluate jitter, you must capture multiple samples. Use the "Persistence" or "Infinite Accumulate" mode on your logic analyzer. The width of the "edge" in your captured waveform represents the jitter; a thick, blurry edge indicates that the interrupt entry time is inconsistent due to conflicting tasks, higher-priority interrupts, or kernel-level masking.
If you find that your jitter exceeds your system's timing budget, you must investigate the longest periods where interrupts are disabled (e.g., inside critical sections or during OS scheduler locks). Reducing these windows is the primary method for tightening your real-time response.
Key Takeaway: Interrupt latency is the fixed delay of the response, while jitter is the variance; minimizing both requires reducing the time the CPU spends with interrupts disabled or executing higher-priority tasks.