Perhaps you haven't noticed, but every time you hit a key on the keyboard or click the mouse, the CPU on the computer motherboard triggers an interrupt to process your request. Interrupts are the foundation of microcomputers' ability to handle complex signals and execute tasks in an "event-driven" manner. PLCs in industrial settings, essentially microcontrollers (MCUs), also possess the capability of interrupt handling. In today's article, we will take Siemens' S7 series PLC as an example to discuss the interrupt management mechanism of PLCs.
After all that talk, what exactly is an "interrupt"? Interrupt, also known by its English name "interrupt," refers to the process where the CPU (PLC) stops the current task it's executing and switches to execute another task. The CPU was originally busy with a task, but due to a request (interrupt request), it sets aside the current task to handle this request (interrupt handling). This process is called an "interrupt." Let me give you an example: Imagine I'm boasting to my colleague about how much I can drink, and suddenly my wife calls. Should I answer or not? (You understand the consequences of not answering.) Of course, I obediently pick up the phone and say, "Hello, my dear..."
No laughing allowed, this is a typical interrupt process: When an interrupt request (my wife's phone call) occurs, the CPU first saves the data of the currently running task's registers to the interrupt stack (saving the scene, I pause the conversation with my colleague and remember where we left off); then it jumps to the entry point of the interrupt handling function to begin executing the interrupt handling function (answering the phone); after handling is complete, it returns to the original function, retrieves the saved data from the stack, and continues executing the original program (restoring the scene from the interrupt, continuing the original conversation topic).
In simple terms, the interrupt process includes: interrupt request - save scene - handle interrupt - restore scene. The tasks of "saving the scene" and "restoring the scene" are completed by the operating system, and we only need to focus on completing the task of "interrupt handling."
In the Siemens S7 series PLC, depending on the type of interrupt, it can be divided into: time-of-date interrupt, time-delay interrupt, cyclic interrupt, hardware interrupt, asynchronous error interrupt, synchronous error interrupt. The figure below shows the configurable interrupt types displayed in the CPU317 hardware configuration: