A complete course · 24 chapters · free
Structured Text: Zero to Advanced
Learn Structured Text the way a PLC runs it. Every example on these pages is a live program on a real ST engine: change it, run it, watch every variable scan by scan.
How each chapter works
- Run it — Examples are live programs. Flip the inputs, edit the code and watch the engine execute it one 100 ms scan at a time.
- Predict it — Before the answer, commit to a guess. A wrong guess shows you what you expected — that is where the learning is.
- Prove it — Challenges are graded by a plant test bench: several cases, in order, on a virtual clock. Typing the answer in will not pass.
Contents
Part 1 · First contact
Read and write a working PROGRAM, and know what one scan does.
- Your first program and the scan
Write a PROGRAM that runs, and learn the read–execute–write scan that every line of Structured Text lives inside.
- Variables and data types
Declare BOOL, INT, DINT, REAL, TIME and STRING variables, give them initial values and choose the type that fits the signal.
- Expressions and operators
Arithmetic, precedence, integer division, MOD and type conversion — and the rounding mistakes that hide in them.
- Boolean logic and interlocks
AND, OR, NOT and XOR as machine permissives: seal-in circuits, fail-safe stops and interlocks you can read aloud.
Part 2 · Decisions
Make the program choose — cleanly, at the boundary, without surprises.
- IF, ELSIF and ELSE
Choose between paths with IF, order ELSIF branches by priority, and avoid the missing-ELSE trap that latches outputs.
- Comparisons and thresholds
Compare at the right boundary, add hysteresis and dead bands, and use LIMIT, MIN, MAX and SEL instead of long IF chains.
- CASE statements
Select one behaviour from many with CASE: label lists, ranges, ELSE, and mode selectors that stay readable.
- Edges, latches and memory
Detect rising and falling edges, set and reset latches with clear priority, and decide what the program must remember.
Part 3 · Time and counting
Use timers, counters and states to control what happens next.
- On-delay timers (TON)
Use TON for delays, debouncing and confirmation times, and read its IN, PT, Q and ET pins scan by scan.
- Off-delay and pulse timers
Keep things running after a signal drops with TOF, fire fixed pulses with TP, and build a flasher from two timers.
- Counters
Count parts and events with CTU, CTD and CTUD, reset them deliberately, and count edges instead of scans.
- State machines
Turn a machine sequence into named states and transitions with CASE, timers and clear entry conditions.
Part 4 · Data
Hold many values at once and process them inside one scan.
- Arrays and FOR loops
Store many readings in an ARRAY and process them with FOR: totals, averages, minimum and maximum, all inside one scan.
- WHILE, REPEAT and EXIT
Loop until a condition with WHILE and REPEAT, leave early with EXIT, and never use a loop to wait for the machine.
- STRUCT and ENUM types
Group related values into a STRUCT, name states with an ENUM, and build arrays of structures for real equipment.
- Strings and time values
Build messages with STRING functions, compute with TIME values, and keep text out of the control decisions.
Part 5 · Reusable code
Package logic as functions and blocks, and control real signals.
- Functions
Write FUNCTIONs that turn inputs into one result with no memory, and use them for scaling, limits and checks.
- Function blocks
Write FUNCTION_BLOCKs with inputs, outputs and memory, create instances, and reuse one motor block for many motors.
- Analog signals and alarms
Scale 4–20 mA raw counts to engineering units, filter noise, detect broken wires and raise delayed alarms.
- Ramps and closed-loop control
Ramp setpoints, close a loop with proportional and PI control, and limit the output so the actuator survives.
Part 6 · Professional ST
Write programs other engineers trust, test and maintain.
- Program structure and style
Name, comment and organise ST so it reads like the machine, and carry it across CODESYS, TwinCAT, TIA and Studio 5000.
- Alarms and fault handling
Detect faults, latch alarms until acknowledged, record the first-out cause and drive every output to a safe state.
- Testing and debugging
Test ST with plant cases before the machine exists, watch values online, and debug from a hypothesis instead of guessing.
- Capstone: a bottle filling line
Build a complete filling-line controller in ST — modes, sequence, timers, counts, alarms and tests — then plan what to learn next.
Where this course fits
This course teaches the language. When you want to practise, design a machine or go further, these sit next to it: