Give each step a number in tens, act only in the active step, and move on only when its transition condition is true. Add hold (freeze and resume), abort (safe step needing reset) and a recovery path home before commissioning, and publish step, waiting-for condition and step time to the HMI.
- One active step, one transition condition, numbered in tens.
- Hold resumes; abort needs reset and a recovery path.
- Every machine-driven step gets a watchdog time.
Why a Step Sequence Beats Ad-Hoc Logic
Set/reset bits scattered over twenty networks work until the machine stops halfway and nobody can tell where it is. A state machine has exactly one active step, one condition to leave it, and one place to read both – which is also what the operator needs on the HMI.
| Step | Action | Transition |
|---|---|---|
| 0 | Idle, home | START and A0 and B0 |
| 10 | A+ (YA) | A1 |
| 20 | B+ (YA, YB) | B1 |
| 30 | B− (YA) | B0 |
| 40 | A− | A0 → 0 |
| 90 | Aborted, safe | RESET → 100 |
| 100 | Recovery home | A0 and B0 → 0 |
Lab Flow: From Cylinder Sensors to a Recoverable Sequence
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.
Stage 1Field Signals and PLC Tags
| PLC tag | Address | Type | Device / comment |
|---|---|---|---|
A0_Ret / A1_Ext | %I7.2 / %I7.3 | Bool | Cylinder A reed switches |
B0_Ret / B1_Ext | %I7.4 / %I7.5 | Bool | Cylinder B reed switches |
YA_Ext | %Q3.7 | Bool | Valve A, monostable |
YB_Ext | %Q4.0 | Bool | Valve B, monostable |
Stage 2Input Mapping into DB_IO
// FC_InputMapping "DB_IO".A0_Ret := "A0_Ret"; "DB_IO".A1_Ext := "A1_Ext"; "DB_IO".B0_Ret := "B0_Ret"; "DB_IO".B1_Ext := "B1_Ext";
Stage 3Logic: FB_SeqAB as a CASE State Machine
// FB_SeqAB – STAT: Step : Int; tStep : TON_TIME;
#tStep(IN := NOT "DB_SeqAB".Hold AND (#Step = "DB_SeqAB".Step), PT := T#3S);
IF "DB_SeqAB".Cmd_Abort AND #Step < 90 THEN #Step := 90; END_IF;
CASE #Step OF
0: IF "DB_SeqAB".Cmd_Start AND "DB_IO".A0_Ret AND "DB_IO".B0_Ret THEN #Step := 10; END_IF;
10: IF "DB_IO".A1_Ext AND NOT "DB_SeqAB".Hold THEN #Step := 20; END_IF;
20: IF "DB_IO".B1_Ext AND NOT "DB_SeqAB".Hold THEN #Step := 30; END_IF;
30: IF "DB_IO".B0_Ret AND NOT "DB_SeqAB".Hold THEN #Step := 40; END_IF;
40: IF "DB_IO".A0_Ret AND NOT "DB_SeqAB".Hold THEN #Step := 0; END_IF;
90: IF "DB_SeqAB".Cmd_Reset THEN #Step := 100; END_IF; // aborted: safe state
100: IF "DB_IO".A0_Ret AND "DB_IO".B0_Ret THEN #Step := 0; END_IF; // recovery to home
END_CASE;
"DB_SeqAB".Step := #Step;
"DB_SeqAB".Timeout := #tStep.Q AND #Step >= 10 AND #Step <= 40;
// Outputs per step (written to DB, mapped in FC_OutputMapping)
"DB_SeqAB".YA := #Step = 10 OR #Step = 20 OR #Step = 30;
"DB_SeqAB".YB := #Step = 20;Add the collective fault from PLC interlocks as an automatic abort, and use the watchdog pattern from PLC timers.
Stage 4Link PLC Tags to the HMI
| HMI tag | PLC member | Used by |
|---|---|---|
DB_SeqAB_Step | "DB_SeqAB".Step | Step text list |
DB_SeqAB_Hold / _Cmd_* | "DB_SeqAB".Hold, Cmd_Start, Cmd_Abort, Cmd_Reset | Buttons |
DB_SeqAB_Timeout | "DB_SeqAB".Timeout | Alarm |
Stage 5Link the Graphics
The complete sequence screen – step boxes, waiting-for text, step time bar against the watchdog, cycle data and AUTO/STEP mode – is built object by object in the HMI sequence status screen. For this lab, a minimum version is enough:
| # | Object | Properties | Tag / event |
|---|---|---|---|
| ① | Symbolic output field step | Text list TL_StepAB | DB_SeqAB_Step |
| ② | Buttons START, HOLD, ABORT, RESET | HOLD uses InvertBit; others SetBit, cleared by the PLC | DB_SeqAB_* |
Stage 6Perform and Test: A+ B+ B− A− with Hold, Abort and Recovery
Two cylinders run the classic A+ B+ B− A− cycle as a CASE state machine. HOLD freezes and resumes; ABORT goes to a safe step that needs RESET and a recovery path home. Jam cylinder B to see the step watchdog.
Troubleshooting
| Symptom | Likely cause | First check |
|---|---|---|
| Sequence skips a step | Two transitions true in one scan in ladder set/reset logic | Use CASE with one active step |
| Machine stuck, no alarm | No step watchdog | Add timeout per step |
| After abort the machine restarts mid-cycle | No recovery path | Abort → reset → recovery → home |
Hands-On Lab: A+ B+ B− A− State Machine
Hands-on- TIA Portal with an S7-1200 or PLCSIM
- Two cylinders on the trainer kit or simulated sensors
- Estimated time: 75 minutes
Wire and declare the cylinder signals
Declare A0, A1, B0, B1 and the valves YA and YB.
Map into DB_IO
Copy the four sensors in FC_InputMapping.
Write FB_SeqAB
CASE steps 0 – 40 with transitions, hold, abort to step 90, recovery step 100 and step timer.
Link HMI tags
Publish step, waiting-for code, step time and commands.
Build the sequence screen
Step text, waiting-for, step time and START, HOLD, ABORT, RESET buttons.
Test every path
Run cycles, hold mid-cycle, abort, reset, and jam cylinder B.
The sequence always knows where it is, hold and abort behave as designed, and a stuck step becomes a named timeout.
Frequently asked questions
Should I write sequences in GRAPH, SCL or ladder?
SCL with a CASE statement is the most portable and easiest to review. GRAPH is excellent for visual step sequences but ties you to that language, and ladder becomes unwieldy beyond a few steps.
Why number steps in tens?
So a step discovered during commissioning can be inserted without renumbering the sequence and the HMI text list that depends on it.
What is the difference between hold and abort?
Hold freezes the cycle and resumes from the same step. Abort jumps to a defined safe state and requires a reset, normally followed by a recovery path back to home.
How do I stop a machine waiting forever at one step?
Give every machine-driven step a maximum time and raise a warning when it is exceeded, naming both the step and the transition condition that has not been met.
What should the outputs do in hold?
Usually keep their state so nothing moves unexpectedly, but this is a machine decision: a gripper must keep gripping, a heater may need to switch off. Write it down per step.
Why a separate recovery path after abort?
Because the machine can be anywhere when it is aborted. A recovery sequence brings every actuator to home in a known order before a new cycle may start.