Sequencing in Ladder

The Core Idea

A sequence organizes machine behavior into steps with defined work and transition conditions. The program stores the active step so it knows what to do now and when it may move on.

What you will learn

  • Run a machine one step at a time with a step number: equal comparisons pick the active step, and moves change it.

  • Build the same sequence with one bit per step, and compare the two ways.

  • Make a sequence dependable: one transition per scan, a timeout that moves a stuck step to a fault step, and a defined reset to idle.

Why it matters

A machine that fills, heats, and drains needs the right order as well as the right outputs. Explicit steps also give you a place to define faults and recovery.

The problem

A batch tank runs the same three operations every time: fill it, heat it, drain it. Each operation must finish before the next begins, and a batch must not go wrong silently.

SignalMeaning
START_PBTRUE while Start is pressed (momentary)
STOP_PBTRUE while Stop is not pressed. The button is normally closed, so pressing it, or a broken wire, makes it FALSE
LEVEL_HIGHHigh-level switch: TRUE while the liquid is at or above the full mark
LEVEL_LOWLow-level switch: TRUE while the liquid covers the low switch; FALSE when the tank is empty
INLET_VALVE, HEATER, DRAIN_VALVETRUE opens the inlet, switches the heater on, opens the drain
FAULT_LAMPTRUE lights the fault lamp

The program keeps the active step in STEP, a whole-number integer (INT):

StepSTEPOutputs onMoves on whenTo
Idle0NoneStart is pressedFill
Fill10INLET_VALVEThe high-level switch turns onHeat
5000 ms in Fill without that (the timeout)Fault
Heat20HEATER3000 ms of heatingDrain
Drain30DRAIN_VALVEThe low-level switch releases (tank empty)Idle
Fault90FAULT_LAMPOnly Stop leaves itIdle

Pressing Stop at any step returns the sequence to Idle with every output off. The numbers go up in tens so a step can be added later without renumbering the others.

There is no live tank in the simulator yet, so you operate the two level switches by hand. A tank that fills and drains by itself will come in a later update. A real heater also needs protection that does not depend on the sequence, such as a low-level interlock and a high-temperature cutout; this lesson leaves them out to keep the sequence small. This Stop is an ordinary operating stop. Emergency stops belong to a separate safety system, such as a safety relay or a safety-rated controller, not to ordinary programmable logic controller (PLC) logic.

This lesson uses the equal comparison from Comparison Instructions and the on-delay timer from Timer Patterns.

Predict

Hold START for a moment. Click LOW LEVEL on (the liquid covers the low switch), then HIGH LEVEL on (the tank is full). While the HEATER lamp is lit, click HIGH LEVEL off and on again, and watch STEP and the lamps.

Try it

Keep using the demo above. It appears once you lock in a prediction. HIGH LEVEL and LOW LEVEL are switches: click to change them; lit means the switch reports TRUE.

  1. Finish the batch. After 3000 ms of heating, STEP shows 30 and DRAIN lights. Click HIGH LEVEL off (the level falls past the high switch), then LOW LEVEL off (the tank is empty). STEP returns to 0 and every lamp goes out.

  2. A stuck step. Hold START and leave HIGH LEVEL off, as if the high-level switch had failed. FILL TIME counts up. At 5000 ms, STEP shows 90, the inlet closes, and FAULT lights. Now click HIGH LEVEL on: nothing happens. The Fault step waits for a person.

  3. Reset. Press STOP. STEP returns to 0 and FAULT goes out. Start another batch and press STOP during Heat: everything turns off, and releasing Stop does not resume the batch. Start begins a new one.

Look closer

Pause and use Step one scan around a step change. The scan stepper shows STEP, SCAN_STEP, and both timers.

  • Rung 1 moves (MOVE) STEP into SCAN_STEP: a copy of the step number taken at the top of the scan.

  • Rungs 2–6 are the transitions. Each is an equal comparison (EQ) of SCAN_STEP with one step's number, in series with that step's condition, followed by a move of the next step's number into STEP. Only the rungs of the active step can pass.

  • Rung 7 is the reset. A normally closed contact on STOP_PB moves 0 into STEP. This rung acts when Stop is pressed, and pressing a normally closed button makes its input FALSE, so the rung uses a normally closed contact. A broken Stop wire sends the sequence to Idle and keeps it there.

  • Rungs 8–9 time the steps: STEP equal to 10 enables FILL_TIMER, and STEP equal to 20 enables HEAT_TIMER. Leaving the step disables the timer and clears it, so every visit starts again from 0 ms.

  • Rungs 10–13 are the actions: each output is on while STEP equals its step's number.

Three details make the sequence dependable:

  • One transition per scan. Every transition compares SCAN_STEP, which stays the same for the whole scan, while the moves change STEP. So a transition made in this scan cannot be followed by another one until the next scan. Every step is active for at least one full scan: its outputs are written and its timer starts, even when the next condition is already true. You will see what goes wrong without this in Change it.

  • A timeout to a fault step. FILL_TIMER runs only in Fill. If the high-level switch has not turned on after 5000 ms, the timeout transition moves 90 into STEP. The Fault step has no transition of its own, so the sequence stays there, with the inlet closed and the lamp lit, until someone presses Stop.

  • A defined reset to Idle. The Stop rung sits below the transitions, so in a scan where both happen, Stop wins. It changes the step itself, not just the outputs, so nothing resumes when Stop is released.

The same sequence with one bit per step

Here each step has its own BOOL (Boolean): S_IDLE, S_FILL, S_HEAT, S_DRAIN, and S_FAULT. Exactly one of them is TRUE at a time; S_IDLE starts TRUE.

  • A transition rung has a normally open contact on the current step bit and the step's condition. It sets the next step bit and resets the current one, with a set coil and a reset coil in parallel.

  • The one-transition guard is the bit STEPPED. The first rung resets it at the top of every scan. Every transition rung also needs a normally closed STEPPED contact and sets STEPPED when it fires, so after one transition no other can fire in that scan.

  • The Stop rung sets S_IDLE and resets every other step bit.

  • Each output, and each step timer, is driven by a normally open contact on its step bit.

Run the same batch, the same timeout, and the same reset. The lamps behave exactly as before.

A step numberOne bit per step
Where the state livesOne INT tagOne BOOL per step
Reading a rungAn equal comparison with a numberA contact on a step bit
Two steps active at onceImpossible: STEP holds one numberPossible if a transition forgets a reset coil
Showing the step on an HMI or in a logOne numberOne lamp per step
One transition per scanCompare a copy taken at the top of the scanA "transition done" bit, cleared at the top of the scan

Change it

This practice program is the step-number version with one rung changed. Use the editor's tag list; while the program is paused, values you set there stay set until you change them.

  1. Set LEVEL_LOW and LEVEL_HIGH TRUE: the tank is already full. Press Pause.

  2. Set START_PB TRUE and press Step one scan once. STEP jumps from 0 to 20 in that single scan, and INLET_VALVE was never on. The Fill step was skipped.

  3. Find the fill-to-heat rung. Its equal comparison reads STEP. The Idle rung just above it has already moved 10 into STEP in this scan, so this rung sees 10 and moves on again. Change the comparison to read SCAN_STEP, like the other transitions.

  4. The program restarts at Idle after an edit. With START_PB still TRUE, step once: STEP is 10 and INLET_VALVE is on. Step again: STEP is 20. Set START_PB FALSE and press Validate.

Show the guided change

In the fill-to-heat rung, change the equal comparison's first value from STEP to SCAN_STEP. SCAN_STEP was copied before any transition ran, so it still holds 0 when this rung runs, and the rung cannot pass in the scan that entered Fill. On the next scan SCAN_STEP is 10, the high-level switch is on, and the sequence moves to Heat. Fill lasts one scan, 100 ms here, and its inlet output and timer run during it.

Check yourself

Build a two-step tank sequence driven by a step number. The challenge editor opens with the tags START_PB, STOP_PB, LEVEL_HIGH, LEVEL_LOW, STEP, SCAN_STEP, DRAIN_TIMER, INLET_VALVE, DRAIN_VALVE, and FAULT_LAMP, and no rungs.

StepSTEPOutputs onMoves on whenTo
Idle0NoneStart is pressed10
Fill10INLET_VALVEThe high-level switch turns on20
Drain20DRAIN_VALVEThe low-level switch releases0
3000 ms in Drain without that (the timeout)90
Fault90FAULT_LAMPOnly Stop leaves it0

Stop returns STEP to 0 from any step, and at most one transition may happen per scan. Fill has no timeout here. Use the human-machine interface (HMI) buttons, or set the tags in the editor's tag list. The checks include a tank that is already full at Start, a blocked drain, Stop during Fill and in the Fault step, and a Start press during Drain. Run them as often as you need.

Hint 1

Which rungs change the step, and which rungs only read it? What must every transition rung read so that two transitions cannot happen in the same scan?

Hint 2

Copy STEP into SCAN_STEP first. Each transition is an equal comparison of SCAN_STEP with its step's number, the condition, and a move of the next number into STEP. Put the Stop rung below the transitions. STEP equal to 20 enables the drain timer.

Hint 3

The drain timeout is a transition like the others: SCAN_STEP equal to 20, in series with a normally open DRAIN_TIMER.Done contact, moves 90 into STEP. The Stop rung is a normally closed STOP_PB contact moving 0 into STEP.

Show the worked solution

  1. Move STEP into SCAN_STEP.

  2. SCAN_STEP equal to 0 and a normally open START_PB contact: move 10 into STEP.

  3. SCAN_STEP equal to 10 and a normally open LEVEL_HIGH contact: move 20 into STEP.

  4. SCAN_STEP equal to 20 and a normally closed LEVEL_LOW contact: move 0 into STEP.

  5. SCAN_STEP equal to 20 and a normally open DRAIN_TIMER.Done contact: move 90 into STEP.

  6. A normally closed STOP_PB contact: move 0 into STEP.

  7. STEP equal to 20 enables the on-delay timer DRAIN_TIMER, preset 3000 ms.

  8. STEP equal to 10 drives INLET_VALVE, 20 drives DRAIN_VALVE, and 90 drives FAULT_LAMP, one rung each.

With a full tank at Start, step 10 lasts exactly one scan, because rung 3 reads the copy taken before rung 2 changed STEP. The timer runs only in Drain and clears whenever the step changes, so every drain is timed from 0 ms. The timer and output rungs also work above the transitions; the outputs then follow one scan later.

What happened and why

A sequence is a state machine. The step number, or the set of step bits, is the program's memory of where the machine is in its cycle. In each scan, only the active step's transitions are checked and only its outputs are on. That is why the wave on the high-level switch did nothing during Heat, and why a Start press in the middle of a batch is ignored: no rung of the active step reads it.

Three rules turn that idea into a sequence you can trust:

  • One transition per scan keeps every step real. Each step is active for at least one complete scan, so its outputs and timers always run, the step can be seen on an HMI or in a log, and the order of the rungs cannot make the sequence skip ahead.

  • Timeouts turn a silent stall into a visible fault. Without one, a failed switch leaves the sequence waiting forever with the inlet open. A fault step that holds everything off until a person resets it makes the problem impossible to miss.

  • A defined reset brings the machine back to a known state. Stop changes the step, not just the outputs, and timers driven by the step clear with it.

IEC 61131-3 (the international standard for programmable controller languages) has a graphical language for exactly this, the Sequential Function Chart (SFC): steps drawn as boxes, transitions as bars between them. The one-bit-per-step version is close to how an SFC is built. In Structured Text, the step-number version becomes a CASE statement on STEP; a Structured Text view of this sequence is planned. What a sequence should do after a power loss, resume or return to Idle, is a separate decision covered in a later lesson on power loss and retentive memory.

Common mistakes

  • Transitions that compare the live step number. Cause: a transition rung compares STEP instead of the copy taken at the top of the scan. Symptom: when the next condition is already true, a step is skipped; with a full tank, the inlet never opens. Fix: compare SCAN_STEP in every transition.

  • No timeout. Symptom: a failed switch leaves the sequence waiting forever, with the step's outputs still on. Fix: time each step that waits for a sensor and add a transition to the Fault step.

  • Putting the timeout on the wrong step. Cause: the timer is enabled by, or compared in, a different step. Symptom: a slow step faults while the step that is actually stuck never does. Fix: enable the timer with the same step number its timeout transition compares.

  • A Stop that only switches the outputs off. Cause: STOP_PB in series with the outputs instead of a rung that moves 0 into STEP. Symptom: the batch carries on as soon as Stop is released. Fix: reset the step itself.

  • A Start that does not check for Idle. Symptom: a Start press during a batch jumps back to Fill. Fix: compare the step number with 0 in the Start transition.

  • A transition that does not reset the old step bit (one bit per step). Symptom: two steps are active, so the inlet stays open while the heater runs. Fix: every transition sets the next bit and resets the current one, and Stop resets every bit except Idle.

Platform notes

The editor's palette lists the equal comparison as EQ (Equal) on its Compare tab and the move as MOVE on its Math tab, their IEC names.

The equal comparison is EQU and the move is MOV. Logix controllers can also run sequences written as Sequential Function Chart routines.

In LAD (ladder), the equal comparison is the CMP (Compare) == box and the move is MOVE. The S7-1500 also offers GRAPH, Siemens' Sequential Function Chart language, for sequences.

Enable JavaScript to run the embedded simulator and complete the interactive exercises.