← Resources
Languages·7 min read·

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.

The five IEC 61131-3 languagesLDLadder Diagramgraphical, relay heritageFBDFunction Block Diagramgraphical, signal flowSFCSequential Function Chartsteps and transitionsSTStructured Texttextual, Pascal-likeILInstruction Listtextual, deprecatedOne standard, five notations. Most projects use two.

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