01Getting started
What is Structured Text, and when to use it instead of ladder
What Structured Text is, where it sits in IEC 61131-3 among the five PLC languages, and when ST beats ladder logic.
A text language inside the controller
Structured Text (ST) is a high-level text language for programmable logic controllers. You write lines such as:
Pump := (Start OR Pump) AND NOT Stop;instead of drawing a contact and a coil on a rung. It reads much like Pascal: expressions, IF, CASE, FOR and WHILE.
Where it sits in the standard
IEC 61131-3 is the international standard that made PLC programming look the same across vendors. It defines five languages:
Language | Kind | Best for |
|---|---|---|
LD · Ladder Diagram | graphical | contacts, interlocks, maintenance teams |
FBD · Function Block Diagram | graphical | signal flow and analogue loops |
SFC · Sequential Function Chart | graphical | step sequences |
ST · Structured Text | text | maths, loops, state machines, data handling |
IL · Instruction List | text | legacy, removed in the third edition |
Why ST
- One line replaces ten rungs. Scaling, filtering or a runtime counter is two lines.
- It travels between vendors. The same idea runs on Siemens, CODESYS, Rockwell, Beckhoff, Schneider and Omron, with only naming differences.
- It diffs and reviews. Text goes into Git and you can see what changed between versions; a drawing cannot.
- It scales with repetition. A
FORloop over 64 motors instead of copying the logic 64 times.
When ladder is still better
When the logic is simple interlocks that a maintenance technician reads standing in front of the panel at night. The common practice in plants is ladder for interlocks and safety, ST for maths and sequences, both in the same project.
How you will learn it here
Every lesson has a complete program you open in the ST lab on this site: an editor, a virtual tank with a pump and a valve, a watch table and an export to Siemens SCL. No PLC and nothing to install.
Try it in the lab
The lab runs in your browser: an ST editor, a virtual tank with a pump and a valve, a watch table, and export to Siemens SCL.
What to try
- Press "Download & run", then press the green START button.
- Watch the tank level and the Pump value in the watch table.
- Press STOP and see the pump stop.
Terms in this lesson
People find this lesson by searching
what is structured textstructured text plcIEC 61131-3 languagesST vs ladder logicplc programming languageslearn structured textstructured text tutorial
Course outline
- 01What is Structured Text, and when to use it instead of ladder
- 02How a PLC runs your code: the scan cycle and the process image
- 03Program structure: POUs, PROGRAM, FUNCTION and FUNCTION_BLOCK
- 04Your first program: starting a pump with seal-in logic
- 05Data types: BOOL, INT, REAL, TIME and the rest
- 06Declaring variables: VAR, VAR_INPUT and RETAIN
- 07Literals and constants: 16#FF, 2#1010 and T#5s
- 08Type conversion and scaling a 4-20 mA signal
- 09Assignment and arithmetic in ST: := and operator precedence
- 10Boolean logic, comparisons and bit operations
- 11Standard functions: ABS, SQRT, MIN, MAX, LIMIT, SEL, MUX
- 12IF, ELSIF and ELSE: the rules and when to avoid them
- 13The CASE statement and your first state machine
- 14The FOR loop and the watchdog
- 15WHILE, REPEAT, EXIT, CONTINUE and RETURN
- 16Edge detection: R_TRIG, F_TRIG and the "it fired every scan" bug
- 17Timers: TON, TOF and TP
- 18Counters: CTU, CTD and CTUD
- 19SR and RS flip-flops: which one wins
- 20Writing your own function
- 21Writing a function block
- 22Arrays in Structured Text
- 23Structs and enumerations
- 24References and pointers
- 25The state machine pattern: a batch sequence that cannot get stuck
- 26Alarm management to ISA-18.2: delay, deadband, latch, acknowledge, first-out
- 27Analogue signal processing: counts to engineering units, NE43 and filtering
- 28Closed-loop control in ST: hysteresis first, then a practical PID
- 29Motors and valves in practice: permissives, feedback and travel time
- 30The same ST on every platform: SCL, Studio 5000, CODESYS, TwinCAT
- 31Testing and debugging ST: the watch table, forcing and simulation
- 32An ST style guide: naming, comments, constants and version control
- 33Final project: a complete tank station with a state machine and alarms
- 3420 interview questions on ST and PLC programming, with answers