Home > electrical-training-simulator > PLC programming lessons > lesson 3
PLC Programming Lesson 3: Understanding The PLC Scan Cycle
Follow the PLC scan from input image to ladder execution to physical output update
Lesson objective: Examine the PLC scan cycle, consider how scan order affects program execution, work through a two-scan example, and use PLCLogix Single Scan / Step Mode to advance the simulation one scan at a time.
Lesson 3: In this lesson we will examine the PLC “Scan Cycle”. The PLC program is executed as part of a repetitive process referred to as a “Scan”. A PLC scan begins with the CPU reading the status of its inputs. The application program is executed based on this information. Once the program is completed, the PLC performs internal diagnostics and communications tasks. The scan cycle is completed by updating the output image table. At that time, the cycle starts over.
Processor Scan Sequence
Processor Scan Sequence: The easiest way to conceptualize this cycle is to mentally divide the processor SCAN into three steps. Let's examine each of these steps in a bit more detail.
Step 1: Update the image table – in this step, the processor checks each input address in the following manner: If there IS a signal present at the input terminal screw, put a “1” in the bit associated (by address) with the screw. If there is NOT a signal present at the input screw, put a “0” in the bit associated (by address) with that screw. These bits are “input bits” and their addresses will begin with the capital letter “I”.
Step 2: Execute the ladder logic – in this step the processor executes the rungs one at a time in order from top to bottom. If the instructions from a rung command tell the processor to turn on a particular bit, the processor places a “1” in that bit. A “0” bit is used if the instruction tells the processor to turn OFF a particular bit. It does NOT matter if the bit being controlled is a real-world (output) bit or an internal bit being used by an instruction, or even in some cases an input bit. The processor writes the bit commanded “1” or “0” instantly before moving on. The processor scans ALL rungs before moving on to the next step.
Step 3: Send the output image table to the output modules – In this step the processor posts all the “1” and “0” states to the physical output modules by address. At this point, any physical output locations with corresponding “1” bits are turned ON. Any output locations with corresponding “0” bits are turned OFF. This step completes a single scan cycle.
At this point in time the processor starts at Step 1 again and the whole scan cycle repeats itself.
Scan Cycle Implications
Some Scan Cycle Implications/Considerations: Let's say that during Step 2, a ladder program on rung 5 tells the processor to turn ON a particular output bit. Then, on rung 10 of the same program, an instruction tells the processor to turn OFF that same particular bit. (Normally this would be an error in programming.) In this situation, would a real-world output be ON or OFF? Would it just flicker? No, it would be OFF. This is because the “1” sent to the bit from rung 5 does not immediately get posted to the physical output. The bit is overwritten by rung 10, which turns the same bit OFF. Once all rungs are executed in this part of the cycle, the resulting output table is posted to the physical output module addresses in Step 3.
A common misconception people have pertains to the nature of BITS versus INSTRUCTIONS. They confuse instructions (XIC, XIO, TON, MOV, etc…) in the ladder program with bits in the processor’s internal memory. Bits and Instructions are not the same thing. Instructions in a ladder program have that name for a reason. They literally instruct the processor to deal with input conditions in a manner specified by the programmer (usually task oriented).
Always remember that the processor ONLY communicates with any of the input modules BEFORE the program is executed. Equally important to remember, the processor only communicates with the output modules AFTER all the ladder rungs in the program have been executed.
Scan Cycle Example
An Example Illustrating Scan Cycle:
Here we have a very simple example program that uses a toggle switch to turn on and off a green bulb. We will use this simple example to consider how the scan cycle works and how it impacts on program execution.
Questions:
- Given what we learned about the scan cycle, determine how many complete scan cycles it will take for the “Green_Bulb” to turn on from the instant the “Toggle_ON_OFF” switch associated with address I:1/0 is closed.
- 1 scan cycle
- 2 scan cycles
- 3 scan cycles
- Describe the state of the two NO contacts and the two OTE output instructions on this two-rung program during each of the scan(s) you believe are required for the “Green_Bulb” to turn on.
Answers:
- b, it will take 2 scan cycles.
- Once the Toggle_ON_OFF switch is closed…
Scan 1: the “update input image table” step will detect a “1” at the I:1/0 address. The value will be added to the image table along with the “0” present at B3:0/0 bit file address. Next, when the image table is updated, the NO contact on rung “0” closes. (At this instant the NO contact on rung 1 will still be open.) By the end of the first scan cycle, the “Bit_Flag” OTE instruction would be energized on rung “0”.
Scan 2: On the second scan, the I:1/0 input would remain in its current state, a “1”, and the OTE instruction on rung “0” remains energized. The NO contact sharing the B3 bit file address will be closed, and this state will now be propagated to the O:2/0 green bulb output at the end of the second scan. The bulb would not actually turn on until the end of the second scan.
Single Scan / Step Mode
Single Scan Using STEP Mode: In this mode, the processor can perform a single scan cycle and stop. This allows the user to go through the operation of a program or advance the program one “single scan” at a time. There are some considerations regarding recognizing state changes and timed events when using this mode, but it can be extremely useful in identifying logical errors in the program.
Clicking on the ”Step Mode” menu item brings up the dialog box below. This dialog box has two sections, the “Test Single Step” section that works with breakpoints and is used mainly for debugging program issues, and the “Test Single Scan” section (1) normally used to walk through your program one scan at a time to ensure correct operation. Clicking on the “Go Single Scan” (2) button advances the simulation a single scan each time you click on it.
Need access to the required simulator? PLCLogix 500 Simulator | PLCLogix 5000 Simulator
PLC Scan Cycle Frequently Asked Questions
What is a PLC scan cycle?
A PLC scan cycle is the repetitive process in which the processor reads the input states, executes the ladder program, performs internal diagnostics and communications, and updates the outputs before repeating the cycle.
What is the first step in a PLC scan cycle?
The first step is updating the input image table. The processor checks each physical input and stores a 1 or 0 in the corresponding input bit according to the state at the input terminal.
What is the second step in a PLC scan cycle?
The second step is executing the ladder logic. The processor evaluates the program rung by rung from top to bottom and updates the corresponding processor bits as each instruction is executed.
What is the third step in a PLC scan cycle?
The third step is updating the physical outputs. The processor sends the final output image-table states to the output modules, turning physical outputs on or off according to the resulting bit values.
What is the difference between PLC bits and instructions?
PLC bits are memory locations that hold states such as 1 or 0. PLC instructions such as XIC, XIO, TON, and MOV are program commands that tell the processor how to evaluate conditions or manipulate data. Bits and instructions are not the same thing.
How do I use PLCLogix Single Scan / Step Mode?
Open Step Mode and use the Test Single Scan section. Clicking Go Single Scan advances the simulation one complete processor scan at a time so you can observe how the program changes from scan to scan.