Ladder Logic vs Structured Text: Complete PLC Language Comparison with Code Examples

Ladder Logic vs Structured Text — PLC Language Comparison — circuit diagram showing component connections+-12V SupplyControl SwitchKRelay CoilFlyback DiodeRelay Contact (NO)Lamp (Load)Relay Control CircuitFlyback diode protects coilNO contact closes when coil energized
Ladder Logic vs Structured Text: Complete PLC Language Comparison with Code Examples — interactive diagram. Open it in the editor to customise components and wiring.

This is a free printable ladder logic vs structured text: download the diagram as SVG or open it and print to paper or PDF.

Ladder logic (LD) and structured text (ST) are both IEC 61131-3 PLC programming languages, but they express control logic in fundamentally different ways — LD as a graphical relay-circuit metaphor and ST as a Pascal-inspired text language. This guide compares them on readability, complexity handling, performance, and industry suitability, with identical code examples in both languages so you can make an informed choice for your project.

IEC 61131-3 defines five official PLC programming languages: Ladder Diagram (LD), Structured Text (ST), Function Block Diagram (FBD), Sequential Function Chart (SFC), and Instruction List (IL, now deprecated). All five are standardised equivalents — any logic expressible in one can be expressed in the others. Most modern PLC platforms support at least LD and ST; many support all five. The choice of language is therefore a design decision, not a technical constraint.

What is Ladder Logic (LD)?

Ladder logic is a graphical language where programs are drawn as a series of horizontal rungs suspended between two vertical power rails, mimicking the relay panel circuits that PLCs were designed to replace. Each rung contains contacts (inputs) and coils (outputs) connected by horizontal wires. Current is said to flow from the left rail through contacts to energise coils on the right. A rung evaluates to TRUE (energised) when a continuous path of TRUE contacts connects left rail to right rail.

LD is the dominant language for discrete manufacturing and machine control. Its visual nature means that an electrician who can read a relay panel drawing can read a ladder program with minimal additional training. This makes maintenance straightforward in environments where the programming staff and the maintenance staff are different people.

What is Structured Text (ST)?

Structured text is a high-level text language whose syntax closely resembles Pascal (and is broadly readable to anyone who knows C, Python, or Java). Programs consist of variable declarations and statements: assignments, IF/THEN/ELSE conditionals, WHILE loops, FOR loops, CASE statements, and function calls. ST code is compact, precise, and arbitrarily expressive — any algorithm implementable in a general-purpose language can be written in ST.

ST is growing rapidly in adoption due to the rise of software engineers entering the automation industry, the growth of IIoT and edge-computing integration where data manipulation matters more than relay logic, and the dominance of platforms like Codesys that treat ST as their primary language.

Side-by-side code comparison — Motor Start/Stop:

The same motor start/stop circuit with seal-in in LD consists of three rungs: Rung 1: XIC Start (I0.0) parallel with XIC Motor_Run (M0.0), in series with XIO Stop (I0.1) and XIO OL (I0.2) → OTE Motor_Run (M0.0) Rung 2: XIC Motor_Run (M0.0) → OTE Motor_Output (Q0.0)

The equivalent in ST (IEC 61131-3 syntax):

IF (Start OR Motor_Run) AND NOT Stop AND NOT OL THEN Motor_Run := TRUE; ELSE Motor_Run := FALSE; END_IF; Motor_Output := Motor_Run;

The LD version is immediately readable by any maintenance electrician. The ST version is 5 lines that any software developer can read at a glance, but requires understanding of variable types and program structure that a relay-trained technician may not have.

Side-by-side — TON timer:

In LD, a TON timer is a graphical block on a rung: XIC Enable → TON (Timer, PT := T#10S) → XIC Timer.Q → OTE Output.

In ST:

MyTimer(IN := Enable, PT := T#10S); Output := MyTimer.Q;

The ST version shows the timer as a function block call — the programmer declares an instance variable (MyTimer : TON) in the variable declaration section, calls it like a function, and accesses the output pin (.Q) as a struct member. This is more concise but requires understanding function block instantiation.

Side-by-side — FOR loop processing 10 analog inputs:

In LD, processing ten analog input channels through the same scaling formula requires ten separate rungs, each with a MOVE and MUL instruction referencing a different address. This is 20+ rungs of near-identical logic — maintainable only if every rung is identically structured.

In ST, the same operation is 4 lines:

FOR i := 0 TO 9 DO ScaledValue[i] := (RawADC[i] - Offset) * ScaleFactor; END_FOR;

This is the single clearest advantage of ST over LD: when the same operation must be applied to a collection of data items, ST's loop constructs are far superior. LD has no native loop construct; it must be simulated with counters and indirect addressing, which most technicians find confusing.

Readability and online monitoring: LD's greatest practical advantage in the field is online monitoring. When a PLC is running in online mode, energised rungs are highlighted in colour (typically green) and contact/coil states are visible in real time without any special debugging setup. A technician can stand at a laptop next to the machine, watch the rung states, and immediately identify which contact is blocking a rung from energising. ST offers variable watch tables and breakpoints, but these require deliberate configuration and are less immediately intuitive for a maintenance electrician tracing a fault.

Complexity scaling: LD programs above 200–300 rungs become difficult to navigate. The flat list of rungs with no inherent hierarchy forces engineers to scroll through long programs to understand program flow. ST programs scale better because they can be organised into functions (reusable subroutines), function blocks (stateful reusable objects), and program organisation units (POUs) with clear interfaces.

Performance and memory: on modern PLCs both LD and ST are compiled to the same machine code before execution, so for pure Boolean logic the scan time difference is negligible. For complex math, ST's compiled arithmetic typically executes faster than equivalent LD math-instruction blocks because the compiler can optimise register usage more aggressively. Memory footprint is also smaller for complex ST programs because a 4-line FOR loop compiles to fewer bytes than twenty equivalent LD rungs.

Can you mix LD and ST in one project? Yes — IEC 61131-3 explicitly permits multiple languages within a single project. The standard approach is to use LD for discrete I/O control, machine interlocks, and start/stop circuits where online monitoring is valued, while using ST for data processing, scaling, PID loops, string handling, and algorithm-heavy control. Siemens TIA Portal calls their ST dialect SCL (Structured Control Language); Allen-Bradley Studio 5000 calls it Structured Text. Both allow free mixing between LD and ST program organisation units.

Document your ladder programs for presentations, FDS, or panel drawings using circuitdiagrammaker's free online ladder diagram tool — export to SVG or PDF at any time.

How to wire ladder logic vs structured text

  1. Identify the nature of your control task Discrete on/off control with few conditions (motor starters, valve control, simple sequences): favour LD for its online monitoring advantage. Data processing, PID loops, analog scaling, array operations, or complex algorithms: favour ST for its concise expressive power.
  2. Map out your program organisation units (POUs) Divide the program into functional blocks: I/O handling, safety interlocks, sequences, and data processing. Safety interlocks and I/O handling POUs are good LD candidates. Data processing and loop-based operations are good ST candidates.
  3. Write the LD sections — contacts and coils In LD, draw your rungs from the I/O allocation table. XIC contacts for normally open conditions, XIO contacts for normally closed / interlock conditions. Place OTE coils at the right end. Seal-in contacts for latching motor circuits. Use SET/RESET (OTL/OTU) coils for state-machine state bits.
  4. Write the ST sections — variables and statements In ST, declare all variables at the top of the POU with their types (BOOL, INT, REAL, TIME, etc.). Write assignment statements, IF/THEN/ELSE for conditional logic, and FOR/WHILE loops for iterative operations. Call function blocks (TON, CTU, PID) by instantiation and method call.
  5. Interface LD and ST POUs through shared variables In most platforms, a global variable list holds shared data between POUs. An LD POU writes a BOOL flag to a global variable; an ST POU reads that flag and processes data accordingly. This clean interface keeps the two languages decoupled.
  6. Test LD sections with online monitoring Download the program to the PLC or simulator and switch to online mode for the LD POUs. Watch rung states highlight as inputs change. Force input bits to verify every interlock path.
  7. Test ST sections with watch tables Open a watch table in the PLC software and add the key variables used in ST POUs. Step through the logic by forcing inputs and observing intermediate variable values. Use breakpoints for complex algorithms that are difficult to trace with watch tables alone.

Specifications

IEC 61131-3 language designationLD — Ladder Diagram; ST — Structured Text
Syntax styleLD: graphical (rungs, contacts, coils); ST: text (Pascal-like statements)
Primary metaphorLD: relay panel circuit; ST: Pascal/C program
Online monitoringLD: native rung highlighting, immediate visual; ST: watch table / variable monitor, requires setup
Discrete on/off controlLD: excellent; ST: good (more verbose)
Mathematical / algorithmic logicLD: limited, unwieldy; ST: excellent (loops, arrays, conditions)
Loop constructsLD: none native (counter + indirect addressing workaround); ST: FOR, WHILE, REPEAT
Complexity scalabilityLD: manageable to ~200 rungs; ST: scales to thousands of lines with function/POU organisation
Audience familiarityLD: electricians and relay-trained technicians; ST: software developers and engineers
Code reuse mechanismLD: copy/paste rungs (fragile); ST: functions and function blocks (reusable, instantiable)
Memory footprint (complex logic)LD: larger (many rungs compile to many instructions); ST: smaller (loops and optimised expressions)
Primary industry useLD: discrete manufacturing, machine control; ST: process control, motion, data-intensive applications

Safety warnings

Tools needed

Common mistakes

Troubleshooting

ST program compiles but the BOOL output variable never goes TRUE
Cause: The IF condition contains an implicit type mismatch (e.g. comparing INT to BOOL) or the variable scope is wrong (local variable with the same name as a global, shadowing it) Fix: Check the variable type declarations. Use the IDE's cross-reference to confirm which instance of the variable is being read by the IF statement. Add a temporary watch variable to log the intermediate expression value.
LD rung appears energised online but the motor does not start
Cause: The output coil address in the LD POU writes to a local variable, but the motor contactor output is mapped to a global variable or a different physical output address Fix: Check the I/O mapping configuration in the PLC project. Confirm the OTE coil address matches the actual Q (output) address assigned to the contactor. Use the cross-reference tool to verify no duplicate OTE for the same address.
PLC watchdog fault during ST execution
Cause: A WHILE loop in the ST POU has an exit condition that is never met, causing the scan cycle to exceed the watchdog timeout Fix: Add a maximum iteration counter to every WHILE loop as a safety backstop. Switch to a FOR loop with a bounded count where possible. Review all unbounded loops in the ST code.
Shared variable between LD and ST POUs has unexpected value
Cause: Both POUs write to the same global variable in the same scan cycle — the last POU to execute overwrites the other's result. POU execution order matters. Fix: Restructure so only one POU writes to each global variable (single writer principle). If both must write, place them in the correct execution order in the task configuration and document the dependency.

Frequently asked questions

What is the main difference between ladder logic and structured text?

Ladder logic is a graphical language that represents control logic as relay circuit rungs — visual, intuitive for electricians, and excellent for online fault tracing. Structured text is a text-based language resembling Pascal, better suited for algorithms, data processing, loops, and large programs where text-code organisation is more scalable.

Is structured text faster than ladder logic?

For pure Boolean rung logic they compile to effectively identical machine code on modern PLCs and scan time differences are negligible. For complex math and loop-based operations, ST's compiler can optimise more aggressively, resulting in faster execution and smaller memory footprint.

Can I mix ladder logic and structured text in the same PLC program?

Yes. IEC 61131-3 explicitly permits multiple languages within one project. Both Siemens TIA Portal (SCL for ST) and Allen-Bradley Studio 5000 allow LD and ST POUs in the same project sharing global variables. The standard practice is LD for I/O control and ST for data processing.

Which PLC language should a beginner learn first?

Ladder logic. Its visual nature maps directly to relay panel concepts that most automation training programmes cover, and its online monitoring capability makes debugging immediately accessible. After mastering LD basics (contacts, coils, timers, counters), learning ST is straightforward because the underlying Boolean and procedural logic concepts are identical.

Is ladder logic being replaced by structured text?

Ladder logic retains a dominant position in discrete manufacturing where electricians are the primary maintenance staff, because its visual online monitoring is unmatched for fault tracing. ST adoption is growing strongly in process control, motion, and IIoT-connected applications. In practice the two languages are increasingly used together rather than one replacing the other.

Which is better for PID control — ladder logic or structured text?

Structured text (or Function Block Diagram) is strongly preferred for PID control. A PID function block in ST is two lines: a declaration and a call with parameter assignments. The equivalent in LD would require dozens of math instruction rungs that are nearly impossible to maintain. Most PLC platforms implement the built-in PID block as an FBD or ST function block that can be called from any language.

Does structured text run on all PLCs?

Most modern PLCs support ST as defined by IEC 61131-3. Major platforms with full ST support include Siemens TIA Portal (SCL), Allen-Bradley Studio 5000, Codesys-based PLCs (Wago, Beckhoff, Schneider), and OpenPLC. Some smaller or older PLCs support only LD and IL; check the manufacturer's language support table.

How hard is it to switch from ladder logic to structured text?

Engineers with programming backgrounds typically find ST easy after learning the IEC variable types and function block call syntax. Electricians coming from a relay background find LD far more natural and may find ST initially counterintuitive. Most successful automation engineers develop proficiency in both.

Related diagrams

Free electrical calculators

Edit this diagram free in the online editor