Interrupt Latency Calculator Formula

Understand the math behind the interrupt latency calculator. Each variable explained with a worked example.

Formulas Used

Interrupt Latency

latency_ns = total_cycles / (clock_mhz * 1e6) * 1e9

Interrupt Latency

latency_us = total_cycles / (clock_mhz * 1e6) * 1e6

Total Latency Cycles

total_cycles_out = total_cycles

Max Interrupt Rate (100% CPU)

max_interrupt_rate = clock_mhz * 1e6 / total_cycles

Variables

VariableDescriptionDefault
clock_mhzCPU Clock(MHz)72
sync_cyclesSynchronization Cycles2
pipeline_flushPipeline Flush Cycles3
context_save_cyclesContext Save Cycles12
vector_fetch_cyclesVector Fetch Cycles3
total_cyclesDerived value= sync_cycles + pipeline_flush + context_save_cycles + vector_fetch_cyclescalculated

How It Works

Understanding Interrupt Latency

Interrupt latency is the delay from when an interrupt occurs to when the ISR begins executing.

Components

Total Cycles = Sync + Pipeline Flush + Context Save + Vector Fetch

Latency (ns) = Total Cycles / Clock Frequency x 10^9

Breakdown

  • Synchronization: Aligning the async interrupt to the clock
  • Pipeline flush: Discarding partially executed instructions
  • Context save: Pushing registers onto the stack
  • Vector fetch: Reading the ISR address from the vector table
  • ARM Cortex-M3/M4 processors achieve 12 cycles total. Simpler 8-bit MCUs may take 4-6 cycles.

    Worked Example

    72 MHz ARM Cortex-M: 2 sync, 3 pipeline, 12 context save, 3 vector fetch.

    clock_mhz = 72sync_cycles = 2pipeline_flush = 3context_save_cycles = 12vector_fetch_cycles = 3
    1. 01Total cycles: 2 + 3 + 12 + 3 = 20
    2. 02Latency: 20 / 72e6 x 1e9 = 277.8 ns
    3. 03Max interrupt rate: 72e6 / 20 = 3,600,000 Hz

    Ready to run the numbers?

    Open Interrupt Latency Calculator