What Is a PLC? Parts and the Scan Cycle Explained
What is a PLC? A PLC (programmable logic controller) is an industrial computer that reads signals from field devices, runs a stored program, and switches outputs to control a machine or process. It repeats this as a loop called the scan cycle, many times a second.
This is lesson 1 of the PLC Programming Tutorial. It covers what a PLC does, what is inside one and how the scan cycle works, and then uses the scan cycle to work out scan time and response time for a small conveyor.
Step 1: Know what a PLC is and why it exists
IEC 61131-1 describes a PLC as a digital electronic system built for industrial environments. It stores user instructions in programmable memory and uses them for logic, sequencing, timing, counting and arithmetic, controlling machines and processes through digital and analog inputs and outputs.
PLCs appeared in the late 1960s. The automotive industry, General Motors in particular, wanted to replace hard-wired relay panels. Changing a relay panel meant rewiring it; changing a PLC means editing the program.
Compared with a relay panel, a PLC gives you:
- logic changes in software, without rewiring;
- timers, counters and arithmetic built in;
- diagnostics and status lights for every input and output;
- communication with HMIs, SCADA and other controllers.
The PLC sits between the field and the operator. Sensors and switches feed it, and it drives contactors, valves and lamps.
Step 2: Identify the main parts of a PLC
Every PLC, compact or modular, has the same functional blocks.
- The CPU (processor) runs the user program and the operating system. Inside it is a dedicated microcontroller or microprocessor.
- Memory holds the operating system, the user program and the data tables, including the input and output image tables.
- Input modules convert field signals, such as 24 V DC from a push button or a 4 to 20 mA signal from a transmitter, into values the CPU can read.
- Output modules convert CPU results into field signals. They use relay, transistor or triac switching for discrete loads, or analog signals for drives and valves.
- The power supply turns the incoming supply into the low DC voltages the CPU and modules need.
- The programming device, usually a laptop running the vendor software, is used to write, download and monitor the program.
How you size these parts for a real project is covered in PLC hardware selection. For this lesson, all you need is the data path: field, input module, CPU, output module, field.
Step 3: Follow one scan cycle stage by stage
In RUN mode the CPU repeats the same four stages, in this order, without stopping.
- Read inputs. The CPU reads every input module and copies the on or off state (or analog value) into the input image table. From here until the next input read, the program sees this snapshot, even if a terminal changes in the meantime.
- Execute the program. The CPU solves the user program using values from the input image table and its internal memory. In ladder logic, rungs are solved from top to bottom and each rung left to right. The results go into the output image table.
- Write outputs. The output image table is copied to the output modules, and only now do contactors, valves and lamps change state.
- Housekeeping. The CPU handles communication with the programming device, HMI and network, runs self diagnostics and resets the watchdog timer. Then the cycle starts again at stage 1.
Because rungs are solved in order, a bit written in one rung is already new when a rung below it reads it. A rung above it only sees the new value on the next scan. The PLC ladder logic lesson uses this when it explains seal-in circuits and why a coil should be written in only one rung.
Step 4: Understand scan time and the watchdog
Scan time is the time taken for one full cycle, stages 1 to 4 together. It depends mainly on:
- program length and the instructions used (maths and data handling take longer than simple contacts);
- the number of I/O modules to read and write;
- communication load in the housekeeping stage;
- CPU speed.
Scan time is usually measured in milliseconds, and it is not fixed. It changes when different parts of the program run, for example when a branch of logic is only executed during a fault.
The CPU guards the scan with a watchdog timer. If one scan takes longer than the watchdog setting, the CPU declares a fault and stops executing the program. This protects the machine from a CPU stuck in a loop.
Step 5: See how scan time affects response time
The time from a field input changing to the field output reacting is the I/O response time. It is made up of three parts:
- the input module delay (its filter time);
- the time spent in the scan cycle;
- the output module delay (a relay output is slower than a transistor output).
The worst case happens when an input changes just after stage 1 has finished. The change waits almost one full scan to be read, and then needs one more scan to be solved and written out. So the worst-case response is roughly the input delay, plus two scan times, plus the output delay.
There is a second consequence. If an input pulse turns on and off between two input reads, the program never sees it. A pulse is only reliably caught if it lasts longer than one scan plus the input filter time. For short pulses, PLCs use high-speed counter modules, interrupt inputs or immediate I/O instructions that read the terminal directly.
Step 6: Meet the IEC 61131-3 languages
IEC 61131-3:2013 is the standard that defines PLC programming languages. Vendor software follows it to different degrees, so a program written for one brand rarely moves to another unchanged, but the concepts carry over.
The languages are:
- Ladder Diagram (LD): contacts and coils between two power rails, based on relay drawings.
- Function Block Diagram (FBD): blocks wired together, common in process control.
- Structured Text (ST): a high-level text language with IF, CASE and loops, good for calculations.
- Sequential Function Chart (SFC): steps and transitions for sequences.
- Instruction List (IL): a low-level text language, kept in the 2013 edition but marked as deprecated.
The standard also defines how a program is organised. Code is written as program organisation units: functions, function blocks and programs. Programs are assigned to tasks, which can run cyclically at a set interval or when an event occurs. A configuration and its resources describe the PLC hardware that runs those tasks.
Practice task: scan time and response time for a conveyor
A box detector on a conveyor stops a pusher motor. Use the scan cycle to check how fast the PLC can react. The values below are assumptions for the exercise, not from any datasheet.
Given
- Input read (stage 1): 0.3 ms
- Program: 6000 instructions at an average of 0.4 µs each
- Output write (stage 3): 0.3 ms
- Housekeeping and communication (stage 4): 1.0 ms
- Input filter delay: 3 ms
- Output: relay module with 10 ms switching delay
- Conveyor speed: 0.5 m/s
- The detector gives a 3 ms pulse when a narrow part passes
Find
- The scan time.
- The worst-case I/O response time.
- How far the conveyor moves in that time.
- Whether the 3 ms pulse will always be seen by the program.
Assumptions: scan time is constant, and the worst case is an input change just after stage 1.
Solution
- Program time = 6000 × 0.4 µs = 2400 µs = 2.4 ms. Scan time = 0.3 + 2.4 + 0.3 + 1.0 = 4.0 ms.
- Worst-case response = input delay + 2 × scan + output delay = 3 + 2 × 4.0 + 10 = 21 ms.
- Distance = 0.5 m/s × 0.021 s = 0.0105 m = 10.5 mm.
- The 3 ms pulse is shorter than the 4.0 ms scan, so it can fall entirely between two input reads. It will not always be seen.
Answer: scan time 4.0 ms, worst-case response 21 ms, conveyor travel 10.5 mm, and the 3 ms pulse can be missed. Wire that detector to a high-speed counter or interrupt input, or make the pulse longer than the scan plus the filter time.
Limitations: real scan times vary from scan to scan and instruction times differ between instructions and CPUs. Use the manufacturer’s figures for a real design. The 10 ms relay delay, the 3 ms filter delay and the 2 × scan rule are estimates for teaching.
Related reading
Frequently asked questions
Can a PLC miss an input signal?
Yes. The program only sees inputs at the start of each scan, so a pulse that turns on and off between two input reads is never seen. Short pulses need a high-speed counter or interrupt input, or a longer pulse from the sensor.
What happens if the PLC scan takes too long?
The CPU runs a watchdog timer on every scan. If one scan runs longer than the watchdog setting, for example because of an endless program loop, the CPU raises a fault and stops running the program, and the outputs go to their defined safe state.
Is ladder logic the only way to program a PLC?
No. IEC 61131-3 defines Ladder Diagram, Function Block Diagram, Structured Text and Sequential Function Chart. Instruction List is still listed in the 2013 edition but marked as deprecated. Many projects mix languages, for example SFC for the sequence and ladder for interlocks.
References
- IEC 61131-1:2003 Programmable controllers, Part 1: General information
- IEC 61131-3:2013 Programmable controllers, Part 3: Programming languages
- F. D. Petruzella, Programmable Logic Controllers, 5th ed., McGraw-Hill
- W. Bolton, Programmable Logic Controllers, 6th ed., Newnes
Get one engineering email a week
New articles, worked examples and study notes every week. Free, no spam, unsubscribe any time.