2.2.9 Delayed or Missing Interrupts

Symptoms:

  • An interrupt that was triggered was missed
  • An interrupt was slow to trigger

Troubleshooting:

  • Interrupt was not enabled
  • Toggle I/O to record time in other interrupts
  • Increase oscillator frequency
  • Check interrupt priorities

Missing an interrupt is one of the more difficult problems to troubleshoot in the microcontroller since the issue can be intermittent and difficult to detect in the first place.

The simplest cause of this issue is a disabled interrupt at the peripheral level or by not enabling the interrupts globally. In some cases (such as high/low interrupt priority), there are separate global enables for each interrupt level.

One way to verify triggered interrupts and visualize the interrupt activity is to use an I/O line. The I/O line can be set HIGH during the interrupt and dropped LOW when the interrupt completes. Use an oscilloscope to measure the active time of the I/O line to determine how long the microcontroller spends in the interrupt routine.

Note: It is good programming practice to keep interrupts non-blocking and as short as possible.

One issue which can occur in complex or longer interrupt routines is that the microcontroller spends too much time in the interrupt handler. If this happens, another instance of the same interrupt could set the same interrupt flag. The interrupt flag clear, which can be placed at the end of the interrupt, may prevent the interrupt from being run a second time. If the interrupt must(1) remain long or complicated, then increasing the oscillator frequency (and thus the instruction clock) may help the microcontroller finish executing the instructions before the next interrupt occurs.

Another possibility is a higher-priority interrupt executing over a lower priority interrupt. On microcontrollers with interrupt priority, interrupt priority is assigned manually. If another interrupt (at the same or lower priority) is executing at the same time as another interrupt is pending, then the other interrupt will remain pending until the active interrupt finishes. This behavior is described in more detail in the device data sheet.

Note:
  1. As noted earlier, interrupts are intended to be relatively short segments of code. There are use cases for more complex interrupt handlers. However, those are relatively rare. An alternative to using an interrupt to execute the complex operation might be to set a software flag to execute the operation in the main loop.