Ladder logic 105: PLC scanning
Understanding how scanning works in a programmable logic controller (PLC) is something that needs to be addressed for a user regardless of the program being used.
Almost all programmable logic controllers (PLCs) worldwide handle scanning in the same way. First, the CPU reads the physical inputs into a memory table, usually called the "input table." This table is then used as the program is evaluated. There are different types of registers that are used in different platforms; these registers are updated as the logic is processed left to right on each rung and top to bottom within each routine. This includes updating an output table, which will later be used to drive the physical devices connected to the PLC.
The program might call different subroutines for different purposes, and it can be important in what order routines are called. Depending on where memory registers and output tables are updated, the physical outputs could be delayed by up to two scans.
In either case, the program meanders through the different routines as they are called before returning to wherever they were called from and eventually ends up at the end of the original cyclic routine. Most programs use an initial cyclic routine that is used to call all of the other routines. It should be noted that some programs, however, run on a periodic basis instead of a continuous program. This is uncommon, though. Most programs use a continuous program configuration that runs as fast as it can. After executing all of the code, evaluating the logic, and updating all of the tables (except for the input tables, which were written at the beginning of the scan), the resulting output table or register contents are written to the physical outputs. This is illustrated by Figure 1, which shows the results.
How long does this take? That depends on the platform (speed of the processor), how much code there is in the program, and the types of instructions used. Sometimes programmers will use loops in the program or make repetitive calls to the same routines. All of this has an effect on the total scan time. There is usually documentation available indicating the execution time for different instructions, but there’s no point in trying to add up all of the code to make an estimate on length. It is simply available for reference.
The scan time can take as long as 80 ms. If the scan time is longer than about 50 ms (for a machine control project) then the user should be looking for a more powerful processor or ways to make the code more efficient. Beyond 50 ms the effect on output reaction for a machine control project starts to be noticeable; for a process control project this may not matter.
In Figure 1, the scan time is shown as 56 ms, but this is a pretty big program. And while scanning works the way described for every platform, this is an exception, as shown by A, B, and C. This platform works on a producer-consumer model where input cards produce information for CPUs, and the CPU produces information for the output cards. The CPU can then be said to "consume" information, and the output cards consume information from the CPU. The production and consumption of information is scheduled within each input/output (I/O) card by setting what is known as a requested packet interval (RPI).
In Figure 1, the RPI is set at 20 ms (A). This means that the program will get a couple of updates from the physical inputs each scan and will update the physical outputs twice per scan also. This is typical for digital I/O; analog inputs are usually set at 100 ms or more and are also usually updated more slowly than digital. The updates happen at different points within the scan cycle, which varies in duration quite a bit.
Figure 2 is from a training manual that asks: "Will Output 2 Ever Turn On?" There are three common answers: It will never turn on, it will always be on, or it will briefly flicker every scan. See below to find out the answer.
Frank Lamb is the founder of Automation Consulting Services Inc. This article originally appeared on the Automation Primer blog. Automation Primer is a CFE Media content partner. Edited by Chris Vavra, production editor, Control Engineering, CFE Media, cvavra@cfemedia.com.
Key Concepts
- Almost all programmable logic controllers (PLCs) handle scanning the same way.
- The length of a PLC scan depends on the platform and whether it is for a machine control project or a process control project.
Consider this
What programs do you use for a PLC scan and what challenges have you encountered that aren’t mentioned in this article?
ONLINE extra
The answer to the question shown in Figure 2 is: Output 2 is always on at the end of the scan.
– See additional stories about ladder logic linked below.
Do you have experience and expertise with the topics mentioned in this content? You should consider contributing to our WTWH Media editorial team and getting the recognition you and your company deserve. Click here to start this process.