Select Page

I have seen, that over the years, this is part of PLC’s that gets left out of a lot of courses.  Too bad.  Because over those same years I have seen Scan Cycle problems cause hair loss, throwing of tools, swearing, and even the replacement of perfectly good CPUs only to find the same problem with the new CPU.  It causes programming frustration as well.

It is always a major part of my courses.  So, what is it.  A PLC, just like any computer, operates one instruction at a time.  They just do the instructions really fast so it looks like it is doing multiple things at the same time.

But it is not.  I am sure that all of you are familiar with the Blue Circle of Delay displayed by computers while they are “Thinking,” or waiting for a response from another computer on the internet.

When all your doing is waiting for a picture to download, that is no biggie.  But on a machine, if someone gets a hand caught in the machine, they expect the machine to respond to the Estop button NOW!!  No little circle of delay. This is what delayed PLC’s from using the ethernet for real time control for a while.  It is also part of the reason for the Scan Cycle.

A circle has no beginning but you need to start somewhere.  I start with Reading the Inputs.  It is pretty tough to know what to do if you don’t know what is going on.  So, the PLC will read the state (ON /OFF) of the digital Inputs and the values for Analog signals, and store this information in the Input memory section of the PLC.  It takes a bit of time to do this depending on the number of Inputs.

 

Once the PLC knows the status of it’s real world inputs it can execute or do the program.  The time this takes is dependent on the number of rungs/networks and the complexity of the instructions used in the program.  Move instructions take much longer than an Output instruction.  As the program is being done, the ON/OFF status of the Outputs (based on the program logic) is stored in the Output memory section of the PLC.  The REAL WORLD State of the outputs is not changed while the Scan is doing the program.  That does not happen until the Write the Output part of the scan.

During the Write the Outputs section of the scan, the ON/OFF state of the Output memory addresses are sent to the actual Output modules and the Real World Outputs get turned ON or OFF.  Analog outputs get set to their programmed dependent values as well.  The amount of time this takes is dependent on the number of Outputs.

The main work is done.  During Housekeeping the timers are updated, the bit buckets get emptied, and the CPU looks after its self.

Next comes Communications.  It is time to talk to the HMI, or another PLC or computer, or maybe the drives, and the laptop of the technician that is monitoring the program.  Now just a note here.  You will notice a definite lag between what the laptop screen is showing you (Green Paths) and what is happening.  This can be explained that non-essential communications, like updating the laptop, may not all be completed in one scan.

All of these tasks MUST be completed in a specific amount of time.  This can often be user set, but factory default is normally sufficient.

This time is controlled by a device known as the watchdog timer.  The watch dog timer will monitor the actual time to do a scan.  If the scan were to exceed the limit of the watch dog timer, then the CPU goes into fault mode, and the outputs will shut off.  In this way the PLC guards against the blue circle of delay ever not allowing the PLC to do it’s primary function of control.

The Watchdog guards against hardware faults, and programming faults.  Today most software does a compile of the program each time before it downloads, and check for programming errors that might cause a scan fault.  This was not always the case.   Any old guys/gals out there that remember a Jump to Label with no Label programmed in a PLC 2 family??

The Scan cycle will cause some programming issues as well.  Programming the same Output address on different rungs/networks with different logic is the most common.  I have seen a lot of new CPUs bought over this one.  Let’s look at an example.

The operator comes and tells you that when they are in Auto mode Pump 1 will not start.  It works fine in Manual mode but will not work in Auto.  You get out your laptop and bring up the pump 1 output on Rung 1.  You see that the Auto mode is true, and the cycle start bit is true.  Under these conditions the Pump 1 Output has to be true as well, but it is not.  You have the operator turn the mode switch to manual and still the output is off.  The CPU must be faulty.  But wait a minute. Based on the way that a PLC executes a program, from top to bottom, every rung, every scan, could there be another answer??

In this situation do a “Search” of Output Pump 1.  You find the output on rung 1, but you also find it on rung 14!

Now you look at rung 14.  With the mode switch in Auto, the Auto/Man instruction is False.  As it should be.  Which will not allow the Output Pump 1 to turn ON.  But in Rung 1 the logic should turn ON the Pump 1.  What is going on??

You have just been bitten by the Scan Cycle.  In rung 1 with both the Auto/Man and Cycle Start bits on, the PLC sets the Pump1 Output memory bit ON.  Just like it should.  But when it gets to rung 14 it again solves the logic.  With the mode switch in Auto Rung 14 is False, and so the PLC turns the Output memory bit for pump 1 OFF again as it should.  (It doesn’t understand why the human would turn it on in one rung and then a few rungs later turn it off.

This proves that the scan cycle works as described.  During the Do the Program section, the logic causes the outputs to turn ON and OFF according to the programmed logic.  Regardless of how illogical the instructions.  But it is the last scanned state that actually goes out to the Real world in the Write the Output part of the scan.  We will talk about the affect of the scan in other posts.