PLC Programming · Lab Manual

PLC Step Sequence Programming in TIA Portal: State Machine Lab Manual with Hold, Abort and Recovery

Ad-hoc set/reset logic works until the first unexpected stop. This lab manual builds a proper state machine for two cylinders through all six stages – numbered steps, transitions, hold, abort, recovery and a step watchdog – and lets you run, hold, abort and jam it live.

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

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.

StepActionTransition
0Idle, homeSTART and A0 and B0
10A+ (YA)A1
20B+ (YA, YB)B1
30B− (YA)B0
40A−A0 → 0
90Aborted, safeRESET → 100
100Recovery homeA0 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.

Lab manual flow: field input to tested HMI screenSix stages: field device and PLC tag, input mapping to DB_IO, PLC logic, HMI tags, graphics linking, and perform and test.1Field + tags%I7.2 .. %I7.5reed switches2Input mappingFC_InputMapping→ DB_IO3LogicFB_SeqABCASE, hold, abort4HMI tagsDB_SeqAB_*step, commands5GraphicsSequence screenstep text6Perform + testSimulatorhold, abort, jamAddress rule for every lesson: %I only in FC_InputMapping, %Q only in FC_OutputMapping, symbolic DB members everywhere else – including the HMI.
Figure 1 – Six-stage lab flow for this lesson.

Stage 1Field Signals and PLC Tags

PLC tagAddressTypeDevice / comment
A0_Ret / A1_Ext%I7.2 / %I7.3BoolCylinder A reed switches
B0_Ret / B1_Ext%I7.4 / %I7.5BoolCylinder B reed switches
YA_Ext%Q3.7BoolValve A, monostable
YB_Ext%Q4.0BoolValve 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 tagPLC memberUsed by
DB_SeqAB_Step"DB_SeqAB".StepStep text list
DB_SeqAB_Hold / _Cmd_*"DB_SeqAB".Hold, Cmd_Start, Cmd_Abort, Cmd_ResetButtons
DB_SeqAB_Timeout"DB_SeqAB".TimeoutAlarm

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:

#ObjectPropertiesTag / event
①Symbolic output field stepText list TL_StepABDB_SeqAB_Step
②Buttons START, HOLD, ABORT, RESETHOLD uses InvertBit; others SetBit, cleared by the PLCDB_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.

Cylinders and PLC
HMI · Sequence
Station AB
Step
Waiting for
Step timeCycles

Troubleshooting

SymptomLikely causeFirst check
Sequence skips a stepTwo transitions true in one scan in ladder set/reset logicUse CASE with one active step
Machine stuck, no alarmNo step watchdogAdd timeout per step
After abort the machine restarts mid-cycleNo recovery pathAbort → reset → recovery → home

Hands-On Lab: A+ B+ B− A− State Machine

Hands-on
Before you start
  • TIA Portal with an S7-1200 or PLCSIM
  • Two cylinders on the trainer kit or simulated sensors
  • Estimated time: 75 minutes
1

Wire and declare the cylinder signals

Declare A0, A1, B0, B1 and the valves YA and YB.

Sensors and valves are declared.
2

Map into DB_IO

Copy the four sensors in FC_InputMapping.

DB_IO follows the reed switches.
3

Write FB_SeqAB

CASE steps 0 – 40 with transitions, hold, abort to step 90, recovery step 100 and step timer.

The CASE sequence runs A+ B+ B− A− and stops in step 0.
4

Link HMI tags

Publish step, waiting-for code, step time and commands.

Step and commands reach the HMI.
5

Build the sequence screen

Step text, waiting-for, step time and START, HOLD, ABORT, RESET buttons.

The step text and buttons work.
6

Test every path

Run cycles, hold mid-cycle, abort, reset, and jam cylinder B.

Hold resumes in place; abort needs reset and recovery; a jam raises a timeout.
Checkpoint—how to know you did it right

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.

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 Step Sequence Programming

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

Content reviewed: 16 October 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