Ladder Logic 207: Interrupts and Periodic Tasks
Today’s post is in response to Darko’s comment on my Ladder Logic 206: Scanning post. He mentioned that readers might want to learn a little bit about interrupts.
It can be difficult to discuss this subject generically since different manufacturers handle tasks and functions differently. For instance, not all PLCs scan the same way. Some PLC tasks can be assigned a maximum period of time that each task must be completed within. As long as the total scan time for all tasks doesn’t become to long, some tasks may be assigned a period that allows it to run several times for every one scan of another task. For example, the overall scan time of a processor may be 50ms, but a specific task within the processor might be assigned to run every 10ms. This type of task is known as a periodic task.
This can be further complicated by the fact that some IO systems are assigned a Requested Packet Interval (RPI) that will update the inputs and outputs of a PLC on a time schedule also. I mentioned in the post on scanning that typically the input table is updated at the beginning of a scan, the logic is solved, and then the output table is written to the physical outputs. In some newer PLCs, input and output tables can be assigned to physically update on a time basis just like a periodic task. This means that outputs can be guaranteed a maximum update time in a PLC program regardless of the scan time of a typical “continuous” task, which is at the mercy of the length of the program. Having this type of control over program execution can be important when dealing with techniques such as PID loops or safety.
But what if you need a task or instruction to run immediately, without waiting for the scan to complete? This is where interrupts are used. In interrupt may be assigned as a task or program that will run if a certain bit or input is turned on, or it may be a special instruction that executes under the same circumstances. In a routine setup in a software package, typically there will be a selection for the type of routine it will be. One selection might be the language of the routine (ladder, structured text, SFC etc.) while another might be whether it is a continuous, periodic or interrupt routine or task. Interrupt routines are often written for safety or event-based reasons. They update affected outputs immediately regardless of a program’s position in the scan cycle.
Some program instructions are also designed to jump out of scan and perform a function immediately. An example of this may be a registration input used to detect a mark on a web or object as it moves in front of a sensor. This is a case where it is important to move some actuator or trigger a device very quickly and precisely based on the physical location of a mark. In this case it may not require an entire routine to run based on the interrupt.
All of the major PLC manufacturers have the ability to run a task or routine immediately based on a hardware or software-based command. Many hardware devices such as servo or high-speed counter cards also have inputs assigned specifically for interrupt devices. There are even input cards available where all of the points can be assigned as high speed interrupt triggers. Since lately I have been teaching Allen-Bradley and Siemens programming classes, these are the hardware and software platforms I am most familiar with, but I can speak first hand of Mitsubishi, Koyo and Omron also having this capability.
Tell me about some of your experiences with the use of interrupts in PLC programming!