PLC Programming · Technical Blog

PLC Scan Cycle Explained: Input, Logic, Output and OB1 Timing

Almost every strange PLC behaviour traces back to the scan cycle. This guide walks through one complete scan, then shows how cycle time, interrupt OBs and rung order decide what your program actually does.

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

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

  1. Read inputs: every physical input is copied into the process image input table. From here on, the program sees this frozen copy.
  2. Execute the program: OB1 runs from the first network to the last, calling function blocks and functions as it goes.
  3. Write outputs: the process image output table is transferred to the physical output modules in one operation.
  4. 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.

ContributorEffectWhat to do
Loops over large arraysLarge, sometimes very largeSplit work across several scans
Heavy REAL mathsModerateMove to a cyclic interrupt or reduce frequency
Many HMI and SCADA tagsModerate, in the communication portionGroup tags into structures, slow the update rate
Distributed I/O over the networkDepends on the update time configuredSet realistic PROFINET update times
Blocks called that are not neededSmall each, large in totalCall 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.

Book a Free Demo Class

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.

OBCalled whenUse for
OB1Every cycleMain machine logic
Startup OB100Once on transition to RUNInitialising states and clearing commands
Cyclic interrupt OB30 to OB38At a fixed intervalPID control, filtering, precise timing
Hardware interruptOn a defined input eventHigh speed capture, fast reactions
Time error OB80Cycle monitoring exceededControlled reaction instead of CPU stop
Diagnostic error OB82Module fault reportedCapturing 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
Before you start
  • TIA Portal with an S7-1200 or S7-1500 CPU, or PLCSIM
  • A simple test program you can modify freely
  • Estimated time: 35 minutes
1

Read the cycle time

Go online and record current, minimum and maximum cycle time from the CPU status.

Three values are noted as a baseline.
2

Load the CPU

Add a loop that performs several thousand REAL calculations each scan, then read the cycle time again.

Maximum cycle time increases measurably.
3

Create a double write

Write the same output in two networks with opposite conditions and observe which wins.

The later network determines the output, regardless of the earlier logic.
4

Add edge detection

Replace a level-triggered counter input with a rising edge instruction.

The counter increments once per press instead of continuously.
5

Add a cyclic interrupt

Move the calculation into OB30 with a 100 ms cycle and compare OB1 cycle time.

OB1 cycle time drops and the calculation still runs at a fixed interval.
Checkpoint—how to know you did it right

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.

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 PLC Scan Cycle Explained

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

Content reviewed: 09 September 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