When a process is controlled by a PLC it uses inputs from sensors to make decisions and update outputs to drive actuators, as shown in below Figure. The process is a real process that will change over time.
Actuators will drive the system to new states (or modes of operation). This means that the controller is limited by the sensors available, if an input is not available, the controller will have no way to detect a condition.
The control loop is a continuous cycle of the PLC reading inputs, solving the ladder logic, and then changing the outputs. Like any computer this does not happen instantly.
The above Figure shows the basic operation cycle of a PLC. When power is turned on initially the PLC does a quick sanity check to ensure that the hardware is working properly. If there is a problem the PLC will halt and indicate there is an error.
For example, if the PLC power is dropping and about to go off this will result in one type of fault. If the PLC passes the sanity check it will then scan (read) all the inputs.
After the inputs values are stored in memory the ladder logic will be scanned (solved) using the stored values - not the current values. This is done to prevent logic problems when inputs change during the ladder logic scan.
When the ladder logic scan is complete the outputs will be scanned (the output values will be changed). After this the system goes back to do a sanity check, and the loop continues indefinitely.
Unlike normal computers, the entire program will be run every scan. Typical times for each of the stages is in the order of milliseconds.