Structured Text vs Ladder Logic: Which PLC Language Should You Use?

Key takeaways

  • Ladder logic is best for discrete on/off logic that electricians and technicians need to read on-screen during troubleshooting.
  • Structured Text is better for calculations, loops, string handling, data arrays, and complex conditional logic.
  • The two languages are not rivals — use both in the same project: ladder for I/O sequencing, ST for math and data processing.
  • Ladder logic debugs visually (highlighted contacts show live logic state); ST debugs textually (set breakpoints and watch variable values).
  • Structured Text is faster to write for experienced programmers; Ladder Logic is faster to read for maintenance technicians not familiar with the codebase.

What is Structured Text?

Structured Text (ST) is one of the five programming languages defined in IEC 61131-3 for programmable logic controllers. It is a high-level, text-based language with a syntax inspired by Pascal, Ada, and C. Unlike Ladder Diagram and Function Block Diagram, which are graphical languages, Structured Text looks like conventional software code — a significant advantage for programmers with software development backgrounds and a potential barrier for maintenance technicians trained only on relay schematics.

Structured Text supports:

  • Assignment statements (VarA := VarB + 10;)
  • Arithmetic operators: +, -, *, /, MOD
  • Comparison operators: =, <>, <, >, <=, >=
  • Logical operators: AND, OR, NOT, XOR
  • Conditional: IF … THEN … ELSIF … ELSE … END_IF
  • Case: CASE StateVar OF 1: … 2: … END_CASE
  • Loops: FOR … TO … DO … END_FOR, WHILE … DO … END_WHILE, REPEAT … UNTIL … END_REPEAT
  • Function and function block calls

Structured Text syntax — practical examples

Engineering unit scaling (4–20 mA)

// Scale raw ADC count to engineering units
// ADC range: 6208 (4mA) to 31208 (20mA)
// EU range: 0.0 to 100.0 bar

IF ADC_Raw >= ADC_At_4mA AND ADC_Raw <= ADC_At_20mA THEN
    Pressure_Bar := (REAL(ADC_Raw - ADC_At_4mA) /
                     REAL(ADC_At_20mA - ADC_At_4mA)) * 100.0;
ELSIF ADC_Raw < ADC_At_4mA THEN
    Pressure_Bar := 0.0;
    Pressure_Fault := TRUE;  // Under-range / open circuit
ELSE
    Pressure_Bar := 100.0;
    Pressure_Fault := TRUE;  // Over-range
END_IF

FOR loop — initialise an array

FOR i := 0 TO 15 DO
    RecipeValues[i] := 0.0;
    RecipeActive[i] := FALSE;
END_FOR

CASE statement — state machine

CASE MachineState OF
    0:  // Idle
        Motor_Run := FALSE;
        IF Start_PB THEN
            MachineState := 10;
        END_IF
    10: // Running
        Motor_Run := TRUE;
        IF Stop_PB OR Fault THEN
            MachineState := 20;
        END_IF
    20: // Stopping
        Motor_Run := FALSE;
        IF Motor_AtSpeed = FALSE THEN
            MachineState := 0;
        END_IF
END_CASE

What is Ladder Diagram?

Ladder Diagram (LD) is the graphical PLC language that represents control logic as horizontal rungs between vertical power rails. Input contacts (NO/NC) are placed on the left of each rung; output coils or function block calls are placed on the right. The language directly models the relay-based control diagrams it replaced in the 1960s.

Ladder logic's key strength is on-screen monitoring: while the program is running, the programming tool highlights contacts and coils that are in their active state. This live "power flow" visualisation allows maintenance technicians to trace logic step by step without any software development experience. See Ladder Logic Basics for a full introduction.

Side-by-side comparison

Property Ladder Diagram (LD) Structured Text (ST)
Syntax style Graphical (relay-diagram-like) Text (Pascal/Ada-like)
Best for Discrete on/off logic, interlocks, sequences Calculations, loops, arrays, string handling, state machines
Readability for electricians Excellent Poor without ST training
Readability for software developers Poor initially Excellent
On-screen debugging Excellent (visual contact state, power flow) Good (watchpoints, breakpoints) but less visual
Mathematical calculations Verbose (one instruction per operation) Concise (single expression)
Array / loop handling Difficult (no native FOR loop) Excellent (FOR, WHILE, REPEAT)
Conditional logic Manageable for simple cases; cluttered for complex IF/ELSIF/CASE — clean for complex conditions
Code compactness Verbose — one instruction per rung Compact — complex logic in few lines
IEC 61131-3 compliance Standard (all platforms support it) Standard (most modern platforms support it)

When to use Ladder Logic

  • The maintenance team is predominantly electrician-trained. If the people who will fault-find the machine day-to-day have relay circuit backgrounds and limited software development experience, ladder logic lets them understand and debug the program without training.
  • Discrete sequential logic. Start/stop circuits, interlocks, conveyor zone logic, and alarm conditions are naturally expressed in ladder. The seal-in circuit, for example, maps directly to the classic relay diagram.
  • On-screen monitoring is critical. When a machine is running and you need to watch logic state in real time without stopping, ladder's highlighted contacts are unmatched for immediate visual diagnostics.
  • Complying with customer documentation requirements. Some end-user specifications require ladder logic because their standards or in-house technicians cannot read ST.

When to use Structured Text

  • Mathematical calculations. Scaling analogue values, PID calculations, polynomial approximations, CRC calculations — any multi-step math is far more compact and readable in ST. Doing the same in ladder requires one function block call per operation, scattered across many rungs.
  • Array operations and loops. Iterating over recipe tables, searching arrays, batch processing data — these require FOR or WHILE loops that do not exist in standard ladder.
  • State machines with many states. A CASE statement in ST cleanly expresses a machine with 10+ operating states. The equivalent in ladder (using compare rungs to check a state integer) becomes very cluttered.
  • String processing. Recipe names, barcode string parsing, generating MQTT payloads — string manipulation is practically impossible in ladder.
  • Code reuse and maintainability. ST function blocks with well-named inputs, outputs, and variables are easier to review and maintain than equivalent multi-rung ladder structures.

Mixing languages in one project

IEC 61131-3 explicitly supports mixing languages within a single project. Different Program Organisations Units (programs, function blocks) can each use their preferred language. A well-structured project might use:

  • Ladder Diagram for the main I/O scanning and safety interlock logic — directly visible to maintenance technicians
  • Structured Text for function blocks performing engineering-unit scaling, PID loops, recipe management, and state machine logic
  • Function Block Diagram for PID control loops and analogue signal conditioning, where the data-flow representation is natural
  • Sequential Function Chart for batch sequences and machine cycle logic

This approach uses each language where it is strongest and does not force either language into applications it handles poorly.

Platform support for Structured Text

Structured Text support has improved significantly in the last decade:

  • Allen-Bradley (Studio 5000): Full ST support in ControlLogix/CompactLogix. Can mix LD and ST in the same routine using inline ST or in separate routines.
  • Siemens (TIA Portal): Full ST (called SCL — Structured Control Language) support in S7-1200, S7-1500. Can be mixed with other languages.
  • CODESYS-based platforms (Beckhoff, Wago, etc.): The most complete IEC 61131-3 implementation. ST, LD, FBD, SFC all fully supported.
  • Mitsubishi (GX Works3): ST supported in iQ-R, iQ-F, and Q series. Older FX series has limited ST support.

Learning order recommendation

If you are new to PLC programming:

  1. Learn ladder logic basics first. The contact/coil model, scan cycle, and basic function blocks (timers, counters) are foundational regardless of which language you use in production.
  2. Once comfortable with ladder, learn Structured Text for mathematical and data-handling tasks. The IF/THEN/ELSE and FOR loop constructs will feel immediately familiar if you have any programming background.
  3. Learn Function Block Diagram when working with process control (PID loops) and analogue signal chains.
  4. Add Sequential Function Chart for batch and sequential machine applications.

How we researched this

Language definitions and syntax from IEC 61131-3:2013 (third edition). ST syntax examples compiled and verified in CODESYS V3.5 SP17 and Rockwell Studio 5000 V35. Platform support notes verified against current vendor documentation for Studio 5000, TIA Portal V18, and GX Works3.