Structured Text for people who think in ladder
The translation is mostly mechanical, and four constructs cover the majority of real code.
Short answer
Map the concepts directly: a rung becomes an assignment guarded by a boolean expression, a series of contacts becomes AND, a parallel branch becomes OR in brackets, and a latch becomes an IF block rather than an assignment. Timers become function block instances that must be declared, which is the one genuinely new idea.
If you can read a rung, you can read Structured Text after about an hour. The mapping is close to mechanical.
A rung is an assignment
XIC(Start) XIO(Stop) OTE(Motor) becomes Motor := Start AND NOT Stop;.
Series is AND. A normally-closed contact is NOT. The coil is the assignment target.
A branch is OR, and the brackets matter
A seal-in becomes Motor := (Start OR Motor) AND NOT Stop;.
Leave the brackets out and AND binds tighter, producing Start OR (Motor AND NOT Stop), which latches on and never releases. This is the single most common ST bug written by ladder programmers.A latch is an IF, not an assignment
OTL(Motor) becomes IF Condition THEN Motor := TRUE; END_IF;.
Writing Motor := Condition; instead clears the bit whenever the condition goes false, which is the opposite of a latch.
Timers need declaring
This is the genuinely new idea. In ladder the timer instance was created for you. In ST you declare Warmup : TON; and then call Warmup(IN := Heater_On, PT := T#5s);, reading Warmup.Q for the done bit.
Forgetting the declaration is the first compile error every ladder programmer meets.
Common questions
- What is the Structured Text equivalent of a seal-in circuit?
- Motor := (Start OR Motor) AND NOT Stop; The brackets are essential. Without them, AND binds tighter than OR, so the expression becomes Start OR (Motor AND NOT Stop), which latches on and never releases.
- How do timers work in Structured Text?
- As function block instances. You declare an instance, for example MyTimer : TON;, then call it with MyTimer(IN := Condition, PT := T#5s); and read MyTimer.Q for the done bit. The declaration is the part ladder programmers forget, because ladder created the instance implicitly.
Keep reading
- Safety
SIL or PL: which one does your machine need?
Two standards, two scales, and one machine. Which one applies, how they map to each other, and why the answer is usually ISO 13849.
- Safety
Categories B, 1, 2, 3 and 4, in plain terms
Five architectures, what a single fault does to each, and the practical wiring that goes with them.
- Safety
Safety relay or safety PLC: how to decide
One is a wiring decision, the other is a programming one. The count of safety functions, not the size of the machine, is what settles it.