Ladder Logic 207: Interrupts and Periodic Tasks

Interrupt Service Routine (ISR)
Interrupt Service Routine (ISR)

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!

Share
About

Electrical Engineer and business owner from the Nashville, Tennessee area. I also play music, Chess and Go.

4 Comments on “Ladder Logic 207: Interrupts and Periodic Tasks

  1. Can you also use an AOI (AB) in place of an interrupt? If so are there situations where this could cause problems?
    I’m pretty new to PLC programming and have only worked with Logix5000, and have seen a lot of AOI’s and that is the first thing that I thought of when reading this post.

    • Hi Mike, thanks for the comment! AOI’s can really just be thought of like any other instruction, usually they are used for complex stuff. Think of it like a PID or Sequencer instruction where you have to pass in and out several parameters.

      So AOIs really don’t have anything to do with executing an instruction immediately. In ControlLogix the way you would do that is with an EVENT task. The SLC used an Immediate Output (IOM) instruction for that sort of thing.

  2. Hey Frank, I will guess that on Control Logic PLC, the Input and Output RPI needs to be faster than the cyclic task time. Otherwise, Cyclic Program would run with the same inputs and outputs multiple times. Which will defeat the purpose of Interrupts

    • Not necessarily Raj. The purpose is to make the I/O updates more consistent, but the 20ms default is usually fine. It serves to reduce the overhead of updating the I/O so often unnecessarily, so for instance if your scan time is only 5ms, you would only update the I/O once every 3-4 times rather than every time. since I/O updating takes 1ms or more, this effectively reduces processing time.

      Interrupts are a different thing, you jump out of scan and do something immediately based on I/O. The Event driven task or produced-consumed change of state covers that for ControlLogix. Programs run with the same input and output states multiple times anyway, most I/O signals stay in the same state for many many scans.