Glossary · Automation software engineering and architecture
Interrupt service routine (ISR)
Also known as: ISR, Interrupt handler
German: Interrupt-Service-Routine (ISR)
In embedded and real-time systems, an interrupt service routine (ISR) is a function that the processor executes in response to a hardware or software interrupt, temporarily suspending the running code to handle an urgent event, such as a timer tick, a received message or an input signal change.
- Software engineering
In one sentence
An interrupt service routine is code the processor runs in response to an interrupt, suspending normal code to handle an urgent event.
Example
When the encoder index pulse arrives, an ISR latches the current position counter within microseconds and signals the motion task to process it.
How it applies
- Engineering: Keep ISRs short: capture the data, acknowledge the interrupt and hand further processing to a task, for example through a Circular buffer or flag. Long ISRs delay other interrupts and tasks and increase jitter.
- Concurrency: Data shared between an ISR and normal code needs protection, such as atomic access or briefly disabling interrupts. Many functions, like memory allocation or blocking calls, must not be used in ISRs.
- Documentation: Document which interrupts are used, their priorities, what each ISR does and its maximum execution time. In PLC environments, hardware interrupt tasks play a similar role and should be documented in the task configuration.
ISR vs. event task
An ISR runs at interrupt level, directly triggered by hardware, with strict restrictions. An event task in a PLC runtime or real-time operating system is scheduled as a normal task after the event and can use more functions, with a slightly longer reaction time. See Event-triggered execution.