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.


Figure 1: Example of a programmable logic controller (PLC) scan with a requested packet interval (RPI). Courtesy: Automation PrimerAlmost 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).

Figure 2: Example from a training manual that asks whether Output 2 will ever turn on. Courtesy: Automation PrimerIn 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,

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.

WILLIAM , CA, United States, 03/16/16 02:54 PM:

Typical PLC's tend to update I/O no faster than 20 msec. We need much faster in propulsion testing, as do engineers designing motion control (hydraulics, CNC machines, ...). We use Beckhoff's EtherCAT (up to 0.05 msec updates) but also found B&R Automation to be fairly fast. National Instruments has some fast products, but isn't standard PLC programming. Ditto for most motion controllers.
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by...
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
The Engineering Leaders Under 40 program identifies and gives recognition to young engineers who...
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Motor specification guidelines; Understanding multivariable control; Improving a safety instrumented system; 2017 Engineers' Choice Award Winners
Selecting the best controller from several viewpoints; System integrator advice for the IIoT; TSN and real-time Ethernet; Questions to ask when selecting a VFD; Action items for an aging PLC/DCS
Robot advances in connectivity, collaboration, and programming; Advanced process control; Industrial wireless developments; Multiplatform system integration
Motion control advances and solutions can help with machine control, automated control on assembly lines, integration of robotics and automation, and machine safety.
This article collection contains several articles on the Industrial Internet of Things (IIoT) and how it is transforming manufacturing.

Find and connect with the most suitable service provider for your unique application. Start searching the Global System Integrator Database Now!

Future of oil and gas projects; Reservoir models; The importance of SCADA to oil and gas
Big Data and bigger solutions; Tablet technologies; SCADA developments
SCADA at the junction, Managing risk through maintenance, Moving at the speed of data
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
click me