Skip to main content

The Scan Cycle

A PLC does not run your program once. It runs it over and over, in a fast loop called the scan. Understanding that loop explains almost everything about when an output changes — and it works the same whether you write in Ladder Logic or Structured Text.

The loop

Each scan, the PLC does three things in order:

  1. Read all inputs into memory.
  2. Evaluate your whole program, top to bottom.
  3. Write all output results out.

Then it starts again — typically many times a second. (In rungs.dev the simulator runs one scan every 100 ms, ten scans a second.)

Because the entire program is re-evaluated every scan, outputs always reflect the latest inputs. There is no "stuck" logic: an output turns off automatically the moment its condition becomes false — unless you deliberately latch it.

Top to bottom, every scan

Step 2 — "evaluate top to bottom" — is the part that surprises people. The PLC works through your program in order:

  • In Ladder Logic, it solves rung 0, then rung 1, then rung 2, and so on.
  • In Structured Text, it runs the first statement, then the next, down the routine.

As it goes, it updates the bits each rung or statement writes, and everything below sees those updated values right away. Everything above has already run for this scan, using the values from before.

Later wins

One direct consequence: if two places write the same output, the last one to run wins, because its write is the one that survives to the end of the scan.

  • In Ladder Logic, the lower rung wins.
  • In Structured Text, the later statement wins.

The fix is the same in both: drive each output from exactly one place.

Why order matters more than it looks

"Later wins" is the easy case — two writes to the same bit. The subtler case is when one rung or statement reads a bit that another one writes. Then the order decides whether the read is fresh or a scan old — and an output can end up changing one scan early or late even though the logic looks correct.

That is the next page: Scan Order and One-Scan Delays.

Summary

  • A PLC runs your program in a loop: read inputs, evaluate top to bottom, write outputs, repeat.
  • Rungs (Ladder) and statements (Structured Text) both run top to bottom, every scan.
  • If two places write the same output, the later one wins — drive each output from one place.
  • The order in which things run decides the timing of your outputs, not just the logic.