A PLC, like a computer has a central processing unit or CPU, memory for the program & data and a communications interface. Additionally and more importantly, it has an interface to analog and digital inputs and outputs.
The CPU can be programmed using a programming software usually hosted on a PC or personal computer.
When a program is downloaded, the user sets the PLC to ‘Run’ mode. This allows the CPU to start executing the program.
During execution, the controller:
- Reads inputs connected
- Execute the program (written in ladder or FBD or Structure Text)
- Writes the outputs connected
It also executes communication with external systems like HMIs or PCs or other PLCs and housekeeping activities like diagnostics.
This execution, called a Scan, can be set to happen periodically or continuously in a loop or based on a programmed event (like an input from field or operator input from HMI).
If the program is written in Ladder, the Scan starts from the top first rung at the last rung at the bottom. The inputs are always to the left and outputs to the right. So the Scan also runs from top to bottom and left to right of every rung.
If the program is written using Function Blocks, usually a sequence execution number is assigned.
Small PLCs usually have only continuous scans. Larger systems can have all three (event, continuous or periodic). A watchdog to monitor if the Scan is completing within a defined time or not is set during the setup stage.
Inputs are written to an area called input image table and outputs are written to an area called the output image table.
When a programmer completes writing the code in either of the graphical programming languages, the programming & configuration software from PLC vendor compiles this and writes or downloads to the CPU.
Using the same software, the programmer can access the code ‘online’ with the PLC and make online modifications. This means the downloaded code can be changed without stopping the operation being controlled.
So in essence:
- Programmer writes code in any of the graphic programming languages for PLC Programming (LD/FBD/ST/SFC)
- Programmer downloads code that is compiled by the programming and configuration software
- PLC when set in ‘Run’ mode, reads all connected inputs
- Downloaded program is executed
- PLC writes all the processed outputs to the connected output modules
- Points 3 to 5 are completed in what is called a PLC ‘Scan’ which can be either continuous or periodic or event based
- Programmer can also access the active or online code and make modifications