IMDHMIControls LibraryShop main store

Comparison

When to use structured text instead of ladder logic in a PLC

PLC programming Published 6 min read By IMDHMI controls team

Short answer

Use ladder logic for machine-facing interlocks, permissives and outputs, because maintenance reads power flow under time pressure. Use structured text for arrays, structures, iteration and calculations, where a loop replaces a jump-heavy network. Both languages come from IEC 61131-3, so the practical decision is where each function lives and what crosses the boundary between them.

On this page
  1. What IEC 61131-3 actually defines
  2. Keep interlocks and permissives in ladder
  3. Move arrays, structures and iteration into structured text
  4. The decision table
  5. Draw the boundary between the two languages
  6. Hand the program to maintenance
  7. The decision for each case
  8. Questions asked

Put machine-facing Boolean logic — interlocks, permissives, mode handling, output commands — in ladder, and put arrays, structures, iteration and calculations in structured text. Ladder wins where the diagnosis question is "which condition is blocking this output", because a technician reads it as power flow under time pressure. Structured text wins where the logic repeats over data, because one loop statement replaces a jump-heavy ladder network. The decision below gives the rule, the worked example, and the boundary that keeps both readable.

What IEC 61131-3 actually defines #

IEC 61131-3 defines the languages a PLC programmer chooses between: ladder diagram (LD), function block diagram (FBD) and sequential function chart (SFC) as graphical forms, and structured text (ST) as the textual form. Structured text uses a Pascal-like syntax, and vendor implementations conform to the EN 61131-3 standard, with the usual vendor-specific differences in how data types are handled. Because both languages are part of the same standard, most controllers let one project mix them: a ladder rung can call a function block whose body is written in structured text. That mixing is the whole basis of the decision — you are not choosing one language for the plant, you are choosing the right form per function. For how the languages behave in one cyclic controller, the article on which IEC 61131-3 language fits a cyclic machine controller walks through the same trade-off from the scan side.

Keep interlocks and permissives in ladder #

A start permissive chain, a guard interlock, a fault latch, a mode selector — these are Boolean decisions with a handful of inputs, and their maintenance question is always "which input is wrong right now". Ladder answers it visually: the open contact in the rung is the blocking condition, and an electrician with a laptop sees it without reading a line of text. That is why customer programming standards so often demand "what can be in ladder, stays in ladder" for machine control; the people on the floor, not the author of the code, are its real audience. When you name what each condition does — a trip stops the machine, an interlock prevents an unsafe state, a permissive allows a start — the distinction between those functions matters for how you document them, and the knowledge-base page on how interlocks, trips and permissives define different actions sets out that vocabulary. Keep this layer in ladder even on projects that are mostly structured text.

Move arrays, structures and iteration into structured text #

Data processing is where ladder collapses. The canonical case is searching an array for one value. Here is the structured text version, using illustrative variable names written in generic IEC 61131-3 syntax:

VAR
    codes   : ARRAY[0..999] OF INT;  // fault codes written by the machine layer
    wanted  : INT := 407;            // the code to find (example value)
    i       : INT := 0;
    foundAt : INT := -1;             // stays -1 when the code is absent
    found   : BOOL := FALSE;
END_VAR

FOR i := 0 TO 999 DO
    IF codes[i] = wanted THEN
        foundAt := i;
        found := TRUE;
        EXIT;
    END_IF;
END_FOR

The arithmetic that justifies this choice: the loop makes at most 1000 comparisons and, because the EXIT halts on the first match, it makes exactly the comparisons up to the match. Test it by placing the value 407 at index 537 of codes: after one scan, found is TRUE and foundAt holds 537 — 538 comparisons done. Leave 407 out of the array and found stays FALSE with foundAt still -1, which is the absence case the ladder version usually forgets to handle.

The ladder equivalent needs a compare element per array position, chained down a rung with a jump that closes the cycle back to the first element. That network evaluates all 1000 compare positions on every pass, gives you no early exit worth trusting, and hands the technician a screen of jumps — the construct nobody who maintains machines wants to inherit. The same rule covers sorting, averaging over a buffer, string assembly, recipe tables and any operation on structures. The article on replacing a 16-branch ELSIF chain with one indexed array read shows the same consolidation applied to selection logic, and the one on how a REPEAT loop runs in structured text covers the other loop form when the exit condition belongs at the end.

The decision table #

Control responsibility Preferred form Decision basis
Permissives, interlocks, fault latches, output commands Ladder Maintenance reads power flow and finds the blocking contact during a breakdown.
Simple machine sequencing Ladder or SFC Pick the form that shows the active state and the blocking transition most clearly.
Reusable machine functions Function block (either body) Encapsulation removes repetition while keeping a visible interface.
Array search, sort, filtering, scaling tables, string work Structured text One loop replaces a jump-driven network that grows with every element.
Structures and record-style data Structured text Field access by name beats a chain of moved words.
Safety-related functions The form the certified safety system supports Do not move a safety function into ordinary code; its language and configuration follow the safety controller and the risk assessment, and SIL and PL are separate ratings.

Draw the boundary between the two languages #

The hybrid works only if the boundary is explicit. Ladder calculates start permission, mode, actuator commands and fault conditions, then calls the structured text block with a command word and reads back a status word, a result and a fault code. Structured text processes the data and never touches an output directly. Every value crossing that boundary gets a name, a type and a documented meaning, so a technician can diagnose the machine from ladder plus the block status without stepping into the loop. When you configure how permissives and faults gate a sequence, the knowledge-base page on configuring sequence permissives, interlocks and faults covers the same interface discipline for sequence logic. One safety note belongs here: a safety function stays in the code form and hardware configuration that its risk assessment and certified safety controller support — it is never a candidate to be rewritten into ordinary structured text for convenience.

Hand the program to maintenance #

  1. Name who must diagnose each function during production: plant maintenance, the integrator, or a software specialist.
  2. List the observable conditions that explain why the function is running, stopped, inhibited or faulted.
  3. If those conditions are Boolean and few, put the function in ladder so power flow answers the question.
  4. If the function repeats over data or handles structures, put it in structured text and expose its status and result at the interface.
  5. Write the boundary: every command, status, result and fault crossing between the layers, with type and meaning.
  6. Check the plant programming standard first — if it requires ladder wherever practical, that requirement is a design constraint, not a suggestion.
  7. Confirm the people on call can open and read every deployed language with the software and access they actually have.

The decision for each case #

An existing machine whose faults are traced by maintenance technicians: keep the control logic in ladder, and only rewrite a specific function into structured text when it demonstrably handles arrays, structures or iteration. A new data-heavy function — code lookup, buffering, calculation — write it in structured text behind a function block interface from the first line. A project mixing both: ladder on the machine layer, structured text behind documented blocks, nothing hidden. A safety function: whatever the certified safety system provides, in its own validated configuration. And if a candidate high-level language or runtime enters the discussion, treat it as unproven for cyclic control until the controller documentation confirms the toolchain, task behavior and diagnostics for that controller and version — language choice inside IEC 61131-3 is the decision this article settles, and it stays settled by who has to read the code during the next breakdown.

Questions asked

Will high-level languages replace ladder logic in PLC programming?

No. Ladder stays the fastest form for a technician to trace which contact is blocking an output during a breakdown, and no runtime tool replaces that visual diagnosis. High-level and textual languages earn their place on data processing, not on Boolean machine logic. The realistic outcome is hybrid projects, where each function sits in the language that answers its diagnosis question fastest.

How do I combine ladder logic and structured text in one PLC project?

Write the structured text as a function block with defined inputs and outputs, then call that block from a ladder rung like any other function block. Across the boundary pass commands, status words, results, completion flags and fault codes. Maintenance then diagnoses the machine logic by power flow in ladder and reads the block status online, without stepping through the loop inside it.

Is structured text harder for maintenance technicians to read?

For Boolean interlocks and permissives, yes: a text expression hides which condition is false, while ladder shows it as an open contact. For data processing the comparison reverses, because the ladder equivalent of a loop is a long chain of compare elements and jumps that nobody wants to debug. Match the language to who has to diagnose the function at 3 a.m.

What belongs in structured text rather than ladder?

Anything with repetition or structured data: array searches and sorts, recipe handling, averaging and filtering over sample buffers, string building, scaling tables, and fault-code lookup. A FOR loop over an array is one statement in structured text; in ladder it becomes a jump-driven network that grows with every element. Keep the interface values visible to the ladder layer that commands the machine.

Keep reading

  • Comparison

    Which IEC 61131-3 language fits a cyclic machine controller

    For a cyclic machine controller such as a telescope dome, write the control in structured text or ladder on the native IEC 61131-3 cyclic task and add SFC only for the step sequence. The interlock must be ANDed into each output every scan, so a lost permissive clears the drive command within one sweep, typically 10 to 20 ms. Reserve a TwinCAT C++ module for numeric work structured text cannot express, not for the interlock layer.

    PLC programming

  • Selection guide

    Which IEC 61131-3 PLC language to use for each control task

    Match each control task to the IEC 61131-3 language whose form shows its dominant data path: ladder for discrete interlocks, structured text for calculations and data handling, function block diagram for connected signal functions, SFC for phased sequences. Instruction List is deprecated, so new code uses the other four, and the controller's supported languages set the final limit.

    PLC programming

  • Selection guide

    S7-300 vs Q series IEC 61131-3 language support

    Both platforms meet IEC 61131-3 once you buy the right toolchain: S7-GRAPH gives the S7-300 sequential function chart with function block calls from steps, and GX Works3 gives the Q series the SFC nesting that IEC Developer V5.0 lacked. With languages equal, integrated motion decides: one QD77MS16 module synchronizes 16 axes over SSCNET III/H at a 0.222 ms cycle, while the S7-300's 4-axis FM 357-2 is discontinued. Choose Q with GX Works3 for new multi-axis machines; stay with Siemens only inside an installed S7-300 base.

    PLC programming

Search a CompactLogix INT array for one fault code with FSC