Each cycle the CPU reads all physical inputs into the process image, executes OB1 top to bottom, writes the process image to the physical outputs, then handles communication and system tasks. A signal shorter than one scan can be missed, an output written twice takes the value from the last rung executed, and time-critical logic belongs in a cyclic interrupt OB, not OB1.
- Inputs are a snapshot, not a live signal; a pulse shorter than the scan time may never be seen.
- The last write wins, so an output driven from two places is decided by rung order.
- Anything needing constant timing goes in a cyclic interrupt OB, because OB1 cycle time varies with load.
One Complete Scan, Step by Step
- Read inputs: every physical input is copied into the process image input table. From here on, the program sees this frozen copy.
- Execute the program: OB1 runs from the first network to the last, calling function blocks and functions as it goes.
- Write outputs: the process image output table is transferred to the physical output modules in one operation.
- System tasks: communication with HMI, SCADA and programming devices, plus internal diagnostics.
Two practical consequences follow immediately. First, an input that turns on and off again within a single scan is invisible to your program, because the snapshot happened before it changed. Second, an output does not physically change the moment you set it in the logic; it changes at the end of the scan.
Direct peripheral access with :P bypasses the process image for the rare cases where this matters, at the cost of extra communication time on every access.
Cycle Time and What Makes It Grow
Typical cycle times run from one to ten milliseconds on modern CPUs. What pushes them up is rarely the logic itself.
| Contributor | Effect | What to do |
|---|---|---|
| Loops over large arrays | Large, sometimes very large | Split work across several scans |
| Heavy REAL maths | Moderate | Move to a cyclic interrupt or reduce frequency |
| Many HMI and SCADA tags | Moderate, in the communication portion | Group tags into structures, slow the update rate |
| Distributed I/O over the network | Depends on the update time configured | Set realistic PROFINET update times |
| Blocks called that are not needed | Small each, large in total | Call blocks conditionally |
Watch the actual value online rather than guessing. TIA Portal shows current, minimum and maximum cycle time in the CPU online status. The maximum matters most, because it is where a watchdog trip comes from.
The cycle monitoring time is set in the CPU properties. Exceed it and the CPU calls the time error OB or goes to STOP, which on a production machine means a line down.
Rung Order, Double Writes and Edge Detection
The program executes top to bottom, so order is logic.
Double writes
If Motor_Run is written in network 3 and again in network 40, only network 40 matters; network 3's result was overwritten before the outputs were transferred. The symptom is an output that ignores what looks like perfectly good logic. Use the cross reference list to find every write to a tag before you go hunting through networks.
Edge detection
Because the program sees a level rather than an event, a rising edge instruction is how you detect a change. It compares the current state against a stored bit from the previous scan and produces a true output for exactly one cycle.
- Give each edge instruction its own memory bit; sharing one between two rungs produces silent, intermittent faults.
- Use a rising edge to accept an HMI command once, then clear the command bit.
- Use edges for counting, not level detection, or a held button counts thousands of times per second.
The counter side of this is covered in PLC counters and production counting.
Understand the CPU properly
Practical Siemens sessions covering scan behaviour, OBs, interrupts and cycle time optimisation.
Startup, Cyclic Interrupt and Error OBs
OB1 is the main cyclic block, but it is not the only one. Organisation blocks let the CPU call your code on defined events.
| OB | Called when | Use for |
|---|---|---|
| OB1 | Every cycle | Main machine logic |
| Startup OB100 | Once on transition to RUN | Initialising states and clearing commands |
| Cyclic interrupt OB30 to OB38 | At a fixed interval | PID control, filtering, precise timing |
| Hardware interrupt | On a defined input event | High speed capture, fast reactions |
| Time error OB80 | Cycle monitoring exceeded | Controlled reaction instead of CPU stop |
| Diagnostic error OB82 | Module fault reported | Capturing I/O faults for the alarm system |
The cyclic interrupt is the one most often missed. Closed-loop control needs a constant sampling time, and OB1 does not provide one because its duration changes with load. The PID setup is covered in the PID_Compact guide.
Keep interrupt OBs short. Whatever runs inside them delays OB1, and a heavy calculation in a 10 ms interrupt will push the main cycle past its monitoring time.
Hands-On Lab: Measure the Scan and Catch a Short Pulse
Hands-on- TIA Portal with an S7-1200 or S7-1500 CPU, or PLCSIM
- A simple test program you can modify freely
- Estimated time: 35 minutes
Read the cycle time
Go online and record current, minimum and maximum cycle time from the CPU status.
Load the CPU
Add a loop that performs several thousand REAL calculations each scan, then read the cycle time again.
Create a double write
Write the same output in two networks with opposite conditions and observe which wins.
Add edge detection
Replace a level-triggered counter input with a rising edge instruction.
Add a cyclic interrupt
Move the calculation into OB30 with a 100 ms cycle and compare OB1 cycle time.
You can state your CPU's cycle time, demonstrate a double write, prove edge detection works, and explain why timing-critical code belongs in a cyclic interrupt.
Frequently asked questions
What is a typical PLC scan time?
One to ten milliseconds on a modern S7-1200 or S7-1500 for normal machine logic. Watch the maximum rather than the current value, because that is what triggers cycle monitoring.
Why is my output ignoring its logic?
Almost always a double write. The tag is being written somewhere else later in the program. Use the cross reference list to find every write.
Can the PLC miss a short input pulse?
Yes. Inputs are sampled once per scan, so a pulse shorter than the cycle time can fall entirely between two snapshots. Use a hardware interrupt or a high-speed counter input for fast signals.
When should I use a cyclic interrupt OB?
For anything needing constant timing: PID control, filtering, integration or precise measurement. OB1 cycle time varies with load and is unsuitable for these.
