What a PLC is & the scan cycle
A programmable logic controller is an industrial computer that reads sensors, runs your program and switches outputs, over and over, many times a second. Understanding that repeating scan is the key to everything else in this course.
By the end of this module you can
- Name the parts of a PLC system and what each one does
- Describe the scan cycle: read inputs, execute the program, write outputs
- Explain why a very short input pulse can be missed
- Recognise how Siemens, Rockwell, Mitsubishi and Logivyx organise the program that runs every scan
- Read the scan time of a running Logivyx Soft-PLC
Before PLCs, machines were controlled by cabinets full of relays, timers and hard-wired logic. Changing the machine's behaviour meant rewiring. In 1968 General Motors asked for a programmable replacement, and the PLC was born: the logic moved into software, and the wiring was reduced to connecting each sensor and actuator once.
| Relay logic | PLC | Office PC | |
|---|---|---|---|
| Change behaviour | Rewire | Edit and download the program | Edit software |
| Built for | Cabinet, 24/7 | Cabinet, heat, vibration, electrical noise, 24/7 for decades | Desk |
| Timing | Fixed by hardware | Repeating scan, predictable response | Not predictable |
| I/O | Direct wiring | Industrial I/O modules, fieldbus | None built in |
A soft PLC, such as the Logivyx Soft-PLC, runs the same kind of program on an industrial PC or HMI panel instead of dedicated controller hardware, and drives remote I/O over the network. You will use it for every lab in this course.
A PLC does not react to an input the moment it changes. It works in a loop called the scan:
- Read inputs. The state of every input is copied into memory, the input image (or process image).
- Execute the program. The program runs from top to bottom using that frozen copy, and writes results into the output image.
- Write outputs. The output image is copied to the output modules. Then communication and housekeeping, and the loop starts again.
Because the program works on a snapshot, every rung sees the same input values during one scan, and outputs change only at the end. Step through it below.
One scan, slowed down
Flip the switch at any moment and watch when the PLC notices it, and when the lamp follows.
Lamp := I0;The time for one loop is the scan time or cycle time. Small hardware PLCs typically scan in 1–20 ms, depending on program size. The Logivyx Soft-PLC runs its logic at a scan rate you set; 50–100 ms suits most machines. A watchdog stops the controller if a scan takes far too long, for example because a loop never ends.
Scan time has two practical effects:
- Response time. In the worst case an input changes just after it was read, so the output reacts up to about two scans later.
- Missed pulses. A signal that turns on and off again between two input reads is never seen. Fast encoders and short sensor pulses need high-speed counter inputs or interrupt inputs instead of the normal scan.
Every PLC has a place for the code that runs every scan, a place for start-up code, and ways to run code at fixed intervals. The names differ:
IEC 61131-3 organises a project into POUs (program organisation units: programs, function blocks and functions) and tasks that run them cyclically or on an event.
Logivyx: the logic engine runs the Main routine every scan. Main calls other routines with CALL Name;. STARTUP runs once before the first scan, SHUTDOWN once when Run mode ends. Scan rate is set in Tools → Logic Editor….
OB1 (Program cycle) runs every scan. OB100 (Startup) runs once at STOP→RUN. Cyclic interrupt OBs (e.g. OB30–OB38, OB35 in S7-300) run at fixed intervals such as 100 ms. Inputs and outputs go through the process image (%I / %Q), updated at the start and end of each OB1 cycle; :P accesses read the module directly.
The cycle time and the maximum cycle time (watchdog, default 150 ms) are set in the CPU properties.
A Continuous task runs over and over; Periodic tasks run at a fixed rate (e.g. every 10 ms) and interrupt it; Event tasks run on a trigger. Each task holds programs, and each program has a MainRoutine that calls the others with JSR.
Important difference: in ControlLogix and CompactLogix, I/O data is updated asynchronously at the module's RPI (requested packet interval), not once per scan. An input can change halfway through your logic, so copy it to an internal tag at the start if you need a stable snapshot.
Programs are registered as scan programs (every cycle), initial programs (once at RUN), fixed-scan programs (at a set interval) or event programs. At the end of each scan, END processing refreshes the I/O (X inputs, Y outputs) and handles communication.
The special relay SM402 is ON for the first scan only and SM400 is always ON; the scan time is shown in SD520–SD526 (current, minimum, maximum).
A standard PLC, hardware or soft, is not a safety controller. A software fault, a stuck output transistor or a network loss must never be able to stop an emergency stop from working.
- Emergency stops, guard doors and light curtains go through certified safety hardware: a safety relay or a safety PLC (Siemens F-CPU, GuardLogix, MELSEC iQ-R Safety…). The standard PLC only reads their status.
- The Logivyx Soft-PLC runs on a general-purpose operating system: use it for machine control and training, and keep safety functions in safety hardware.
You need the Logivyx Development Tool installed (Logivyx course, module 02). This lab uses the demo project that ships with it, so nothing needs to be built yet.
Scan time in the Logivyx demo
- Start the Development Tool and open the demo with Help → Open Demo Project….
- Open Tools → Logic Editor…. Note that Enable Logic Engine is ticked and the scan rate, then look at the routine list:
Mainruns every scan and calls the others. Close the window. - Press F5 to enter Run mode. (If your edition has no ▶ Run button, open the project in the Logivyx Runtime instead.) Run mode connects the project's controller by itself.
- Click 🧮 Logic Diag in the bar at the bottom. Find the last and maximum scan times. They are also available to screens as the system tags
_Last_Scan_Timeand_Max_Scan_Time. - Press Esc to leave Run mode. Close the project without saving.