Each cycle the CPU copies all inputs into the process image, executes OB1 top to bottom, writes the process image to the outputs, then handles communication. Call FC_InputMapping first and FC_OutputMapping last in OB1, keep a single write per tag, measure the cycle time, and move fast or time-critical work into interrupts or a cyclic interrupt OB.
- A pulse shorter than one scan can be missed.
- The last write in the scan wins – one write per tag.
- Mapping FCs frame the scan: inputs first, outputs last.
One Complete Scan, Step by Step
| Phase | What happens | Consequence |
|---|---|---|
| 1 Read inputs | All input values copied into the process image | The program sees one frozen snapshot per scan |
| 2 Execute OB1 | Networks run top to bottom, calling FCs and FBs | Order matters; the last write wins |
| 3 Write outputs | Process image copied to the output modules | Outputs change once per scan |
| 4 Communication | HMI, PG and system tasks | Heavy communication lengthens the scan |
Lab Flow: From a Fast Sensor to a Measured Scan
Every lesson in the Softwell PLC lab manual series follows the same six stages and the same address rule, so the code you write here plugs straight into the HMI lessons.
Stage 1Field Signal and PLC Tags
| PLC tag | Address | Type | Device / comment |
|---|---|---|---|
B31_Fast | %I6.4 | Bool | Fast proximity sensor, pulses of a few ms |
K31_Lamp | %Q3.2 | Bool | Indicator lamp |
The input module itself filters the signal (input delay, typically a few ms, set in device configuration). Anything shorter than filter plus one scan needs a hardware interrupt or a high-speed counter.
Stage 2Input Mapping: Fixing the Scan Order
OB1 Network 1 CALL "FC_InputMapping" // copy %I → DB_IO once, at the start OB1 Network 2…n application FCs / FBs // work only on DB_IO and DBs OB1 Network n+1 CALL "FC_OutputMapping" // copy DBs → %Q once, at the end
This frame is used in every lesson of the series, from the first start/stop circuit to the alarm word.
Stage 3Logic: Measure the Cycle Time
// FC_CycleTime – called first in OB1 (S7-1200/1500)
// TEMP: #t : LReal; DB_Diag: CycleTime_ms, CycleMax_ms : Real; ResetMax : Bool; tStamp : LReal;
#t := RUNTIME(MEM := "DB_Diag".tStamp); // seconds since the last call
"DB_Diag".CycleTime_ms := LREAL_TO_REAL(#t * 1000.0);
IF "DB_Diag".CycleTime_ms > "DB_Diag".CycleMax_ms OR "DB_Diag".ResetMax THEN
"DB_Diag".CycleMax_ms := "DB_Diag".CycleTime_ms;
END_IF;Set the cycle monitoring time in the CPU properties (default 150 ms). Time-critical work such as PID belongs in a cyclic interrupt OB – see PID_Compact in OB30.
Stage 4Link PLC Tags to the HMI
| HMI tag | PLC member | Used by |
|---|---|---|
DB_Diag_CycleTime_ms | "DB_Diag".CycleTime_ms | Output field |
DB_Diag_CycleMax_ms | "DB_Diag".CycleMax_ms | Output field |
DB_Diag_ResetMax | "DB_Diag".ResetMax | Button |
Stage 5Link the Graphics
| # | Object | Properties | Tag / event |
|---|---|---|---|
| ① | Output field cycle time | Format 999.9 ms | DB_Diag_CycleTime_ms |
| ② | Output field maximum | Format 999.9 ms; appearance red outline above 100 ms | DB_Diag_CycleMax_ms |
| ③ | Button RESET MAX | SetBitWhileKeyPressed | DB_Diag_ResetMax |
A diagnostics screen like this is a Level 4 screen in the HMI display hierarchy.
Stage 6Perform and Test: Scan Cycle, Short Pulses and Double Writes
Set the cycle time and the pulse length, then fire pulses from sensor B31. Any pulse shorter than one scan can fall between two input snapshots. Add a double write and a heavy loop to see the other two classic scan-cycle faults.
Troubleshooting
| Symptom | Likely cause | First check |
|---|---|---|
| Output ignores its rung | Double write later in the program | Cross reference of the output |
| Counter misses parts | Pulse shorter than scan + input filter | Pulse length, use HSC or hardware interrupt |
| CPU goes to STOP under load | Cycle monitoring time exceeded | Diagnostic buffer, loops in OB1 |
| Logic reacts one scan late | Mapping FC called after the logic | Block order in OB1 |
Hands-On Lab: Measure the Scan and Find Its Faults
Hands-on- TIA Portal with an S7-1200 or PLCSIM
- Estimated time: 60 minutes
Wire and declare the fast sensor
Wire B31 to %I6.4 and the lamp K31 to %Q3.2 and declare them.
Map at the start of OB1
Call FC_InputMapping in network 1 and FC_OutputMapping in the last network.
Measure the cycle time
Store current and maximum cycle time in DB_Diag every scan.
Link HMI tags
Show cycle time, maximum and the pulse counts on the panel.
Display the diagnostics
Add output fields and a reset-maximum button.
Prove the faults
Miss a short pulse, create a double write and exceed the cycle monitoring time in PLCSIM.
You can measure the scan, explain why a short pulse was missed, find a double write with the cross reference, and keep the cycle time well below the monitoring limit.
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 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 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.
Why does the input mapping FC have to run first?
So every block in the scan works on the same, fresh copy of the inputs. If logic runs before the mapping, it uses last scan's values and the program behaves one cycle late.
How do I show the cycle time on the HMI?
Read the last cycle time in OB1 (for example with the RUNTIME instruction or the OB1 start information), store current and maximum in a DB and display them as output fields.