PLC Programming · Lab Manual

PLC Scan Cycle Explained: Lab Manual for Input Image, OB1, Outputs and Cycle Time

A PLC does not run your program once – it runs it every few milliseconds, against a snapshot of the inputs. This lab manual follows that scan through all six stages, measures the cycle time, and lets you watch a short pulse disappear between two scans and a double write overrule a rung.

2,500+ engineers trained 4.9/5 Google rating 21+ years, Chinchwad, Pune Next batch: contact for dates
Quick answer

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

PhaseWhat happensConsequence
1 Read inputsAll input values copied into the process imageThe program sees one frozen snapshot per scan
2 Execute OB1Networks run top to bottom, calling FCs and FBsOrder matters; the last write wins
3 Write outputsProcess image copied to the output modulesOutputs change once per scan
4 CommunicationHMI, PG and system tasksHeavy 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.

Lab manual flow: field input to tested HMI screenSix stages: field device and PLC tag, input mapping to DB_IO, PLC logic, HMI tags, graphics linking, and perform and test.1Field + tags%I6.4 B31_Fastfast sensor2Input mappingNetwork 1fixed scan order3LogicFC_CycleTimeRUNTIME, max4HMI tagsDB_Diag_*cycle data5GraphicsDiag fieldsLevel 4 screen6Perform + testSimulatorpulses, double writeAddress rule for every lesson: %I only in FC_InputMapping, %Q only in FC_OutputMapping, symbolic DB members everywhere else – including the HMI.
Figure 1 – Six-stage lab flow for this lesson.

Stage 1Field Signal and PLC Tags

PLC tagAddressTypeDevice / comment
B31_Fast%I6.4BoolFast proximity sensor, pulses of a few ms
K31_Lamp%Q3.2BoolIndicator 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 tagPLC memberUsed by
DB_Diag_CycleTime_ms"DB_Diag".CycleTime_msOutput field
DB_Diag_CycleMax_ms"DB_Diag".CycleMax_msOutput field
DB_Diag_ResetMax"DB_Diag".ResetMaxButton

Stage 5Link the Graphics

#ObjectPropertiesTag / event
①Output field cycle timeFormat 999.9 msDB_Diag_CycleTime_ms
②Output field maximumFormat 999.9 ms; appearance red outline above 100 msDB_Diag_CycleMax_ms
③Button RESET MAXSetBitWhileKeyPressedDB_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.

CPU scan
HMI · Diagnostics
CPU diagnosticsOB1
Cycle time
Max cycle time
Pulses fired
Pulses counted

Troubleshooting

SymptomLikely causeFirst check
Output ignores its rungDouble write later in the programCross reference of the output
Counter misses partsPulse shorter than scan + input filterPulse length, use HSC or hardware interrupt
CPU goes to STOP under loadCycle monitoring time exceededDiagnostic buffer, loops in OB1
Logic reacts one scan lateMapping FC called after the logicBlock order in OB1

Hands-On Lab: Measure the Scan and Find Its Faults

Hands-on
Before you start
  • TIA Portal with an S7-1200 or PLCSIM
  • Estimated time: 60 minutes
1

Wire and declare the fast sensor

Wire B31 to %I6.4 and the lamp K31 to %Q3.2 and declare them.

B31 and K31 are declared.
2

Map at the start of OB1

Call FC_InputMapping in network 1 and FC_OutputMapping in the last network.

OB1 starts with the input mapping and ends with the output mapping.
3

Measure the cycle time

Store current and maximum cycle time in DB_Diag every scan.

Cycle time and maximum update every scan.
4

Link HMI tags

Show cycle time, maximum and the pulse counts on the panel.

The HMI shows current and maximum cycle time.
5

Display the diagnostics

Add output fields and a reset-maximum button.

RESET MAX restarts the maximum.
6

Prove the faults

Miss a short pulse, create a double write and exceed the cycle monitoring time in PLCSIM.

A short pulse is missed, a double write wins, and a long loop stops the CPU with a buffer entry.
Checkpoint—how to know you did it right

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.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience

Get the full syllabus + free demo class

Share your details—a Softwell training advisor will contact you with batch dates, fees and hardware-practice options.

No spam. Used only to share course details for this enquiry.

Learn with practical industrial examples

Join live online, Pune classroom or corporate in-plant automation training.

Request Course Details
Verified learning pathway

Discuss the PLC Scan Cycle

Explore practical curriculum, software, hardware and batch options for this technology.

Content reviewed: 16 October 2026

Siemens PLC & TIA Portal Learning Path

Continue with the related Siemens PLC tutorials in this practical learning series.

  1. SCL vs Ladder Logic
  2. Upload PLC Program
  3. TIA Selection Tool
  4. Analog Input Scaling
  5. PLC Counters
  6. PLC Timers
  7. Addressing & Data Types
  8. Hardware & PLC Tags
  9. OB, FB, FC & DB
☎ Call WhatsApp ✉ Email Enquire Now