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.
| Signal | Meaning |
START_PB | TRUE while Start is pressed (momentary) |
STOP_PB | TRUE while Stop is not pressed. The button is normally closed, so pressing it, or a broken wire, makes it FALSE |
LEVEL_HIGH | High-level switch: TRUE while the liquid is at or above the full mark |
LEVEL_LOW | Low-level switch: TRUE while the liquid covers the low switch; FALSE when the tank is empty |
INLET_VALVE, HEATER, DRAIN_VALVE | TRUE opens the inlet, switches the heater on, opens the drain |
FAULT_LAMP | TRUE lights the fault lamp |
The program keeps the active step in STEP, a whole-number integer (INT):
| Step | STEP | Outputs on | Moves on when | To |
| Idle | 0 | None | Start is pressed | Fill |
| Fill | 10 | INLET_VALVE | The high-level switch turns on | Heat |
| 5000 ms in Fill without that (the timeout) | Fault | |||
| Heat | 20 | HEATER | 3000 ms of heating | Drain |
| Drain | 30 | DRAIN_VALVE | The low-level switch releases (tank empty) | Idle |
| Fault | 90 | FAULT_LAMP | Only Stop leaves it | Idle |
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.
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.
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.
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)STEPintoSCAN_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) ofSCAN_STEPwith one step's number, in series with that step's condition, followed by a move of the next step's number intoSTEP. Only the rungs of the active step can pass.Rung 7 is the reset. A normally closed contact on
STOP_PBmoves 0 intoSTEP. 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:
STEPequal to 10 enablesFILL_TIMER, andSTEPequal to 20 enablesHEAT_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
STEPequals 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 changeSTEP. 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_TIMERruns only in Fill. If the high-level switch has not turned on after 5000 ms, the timeout transition moves 90 intoSTEP. 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 closedSTEPPEDcontact and setsSTEPPEDwhen it fires, so after one transition no other can fire in that scan.The Stop rung sets
S_IDLEand 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 number | One bit per step | |
| Where the state lives | One INT tag | One BOOL per step |
| Reading a rung | An equal comparison with a number | A contact on a step bit |
| Two steps active at once | Impossible: STEP holds one number | Possible if a transition forgets a reset coil |
| Showing the step on an HMI or in a log | One number | One lamp per step |
| One transition per scan | Compare a copy taken at the top of the scan | A "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.
Set
LEVEL_LOWandLEVEL_HIGHTRUE: the tank is already full. Press Pause.Set
START_PBTRUE and press Step one scan once.STEPjumps from 0 to 20 in that single scan, andINLET_VALVEwas never on. The Fill step was skipped.Find the
fill-to-heatrung. Its equal comparison readsSTEP. The Idle rung just above it has already moved 10 intoSTEPin this scan, so this rung sees 10 and moves on again. Change the comparison to readSCAN_STEP, like the other transitions.The program restarts at Idle after an edit. With
START_PBstill TRUE, step once:STEPis 10 andINLET_VALVEis on. Step again:STEPis 20. SetSTART_PBFALSE 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.
| Step | STEP | Outputs on | Moves on when | To |
| Idle | 0 | None | Start is pressed | 10 |
| Fill | 10 | INLET_VALVE | The high-level switch turns on | 20 |
| Drain | 20 | DRAIN_VALVE | The low-level switch releases | 0 |
| 3000 ms in Drain without that (the timeout) | 90 | |||
| Fault | 90 | FAULT_LAMP | Only Stop leaves it | 0 |
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
Move
STEPintoSCAN_STEP.SCAN_STEPequal to 0 and a normally openSTART_PBcontact: move 10 intoSTEP.SCAN_STEPequal to 10 and a normally openLEVEL_HIGHcontact: move 20 intoSTEP.SCAN_STEPequal to 20 and a normally closedLEVEL_LOWcontact: move 0 intoSTEP.SCAN_STEPequal to 20 and a normally openDRAIN_TIMER.Donecontact: move 90 intoSTEP.A normally closed
STOP_PBcontact: move 0 intoSTEP.STEPequal to 20 enables the on-delay timerDRAIN_TIMER, preset 3000 ms.STEPequal to 10 drivesINLET_VALVE, 20 drivesDRAIN_VALVE, and 90 drivesFAULT_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
STEPinstead 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: compareSCAN_STEPin 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_PBin series with the outputs instead of a rung that moves 0 intoSTEP. 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.