Table of Contents
ToggleLadder logic is great for interlocks, but maths, loops and recipes quickly turn into pages of rungs. A few lines of text based code can do the same job with far better clarity and reuse.
This language is the high level, Pascal like language of IEC 61131 3. It suits calculations, data handling and state machines that are awkward to draw in ladder logic.
What Is Structured Text?
Structured text is a high level textual PLC language defined in IEC 61131 3, with a syntax similar to Pascal. It is one of the five standard PLC programming languages, alongside ladder diagram, function block diagram, instruction list and sequential function chart.
PLC Academy notes that PLCopen maintains the language inside IEC 61131 3. Code runs top to bottom every scan, just like rungs in ladder.

Each statement ends with a semicolon, and assignments use the := operator. Execution still follows the PLC scan cycle, so outputs update after the program finishes.
Rockwell, Siemens SCL, Codesys, Beckhoff and Schneider all support the language with small dialect differences. Code written carefully can move between platforms with little rework.
Core Syntax and Statements
| Element | Example | Purpose |
|---|---|---|
| Assignment | Motor := Start AND NOT Stop; | Set a value |
| IF | IF Level > 80.0 THEN Pump := TRUE; END_IF; | Conditional logic |
| CASE | CASE Step OF 1: Fill := TRUE; END_CASE; | State machines |
| FOR | FOR i := 1 TO 10 DO Sum := Sum + A[i]; END_FOR; | Loops over arrays |
| WHILE | WHILE x < 100 DO x := x * 2; END_WHILE; | Conditional loop |
| Comment | (* Tank fill logic *) | Documentation |
Comparison and maths operators replace separate instructions such as those in PLC compare instructions and PLC math instructions. One line can hold what needs several rungs.
CASE statements are ideal for sequences, because each step becomes a numbered branch. That makes a batch or machine sequence very easy to follow.
Data Types and Variables
PLC Academy lists 8 integer types from SINT to ULINT and 2 floating types, REAL and LREAL. See PLC data types for their ranges and memory use.
Declare variables with clear names and types in the variable table. Mixing INT and REAL without conversion is a common compile error.
Timers and Counters in Text Code
Timers are called as function block instances, for example TON_1(IN := Start, PT := T#5S);. The behaviour matches the TON, TOF and RTO timers used in ladder.
Counters work the same way, with CU, R and PV inputs, as explained in CTU and CTD counters. Call each instance only once per scan to avoid confusing results.
7 Essential Structured Text Coding Rules
A long WHILE loop can exceed the scan time and fault the controller, explained in PLC watchdog timer. Always add an exit counter.
Many plants mix languages, with interlocks in ladder and calculations in text. Choose the language that makes each piece easiest to troubleshoot.
Worked Example: Analog Scaling
Example, 4 to 20 mA input on a 16 bit card:
RawMin = 6242, RawMax = 31208, Raw = 18725
EUMin = 0 bar, EUMax = 10 bar
EU = 12483 × 10 ÷ 24966 = 5.0 bar
The same formula is described in PLC analog scaling. In text form it fits on one readable line, and it can be wrapped in a reusable function.
Add a check for RawMax equal to RawMin, or the division will fault the processor.
Structured Text vs Ladder Logic
- Compact maths and data handling.
- Easy loops and arrays.
- Clean state machines with CASE.
- Portable between vendors.
- Visual power flow for electricians.
- Easy online monitoring of contacts.
- Simple interlocks.
- Familiar to maintenance teams.
Beginners usually start with ladder logic, then add text routines for calculations. Function block diagrams sit between the two, see function block programming.
Scaling Calculator
Use the result to check your code during simulation before downloading. Compare it with the value shown on the HMI.
PDH Online Structured Text Course PDF
Studio 5000 ST Tutorial Video
Structured Text FAQ
Related Articles
- PLC Programming Languages
- Ladder Logic for Beginners
- 9 PLC Data Types Explained
- PLC Analog Scaling
- Free PLC Programming Software
External References
What We Learn Today
- Structured text is the Pascal like language of IEC 61131 3.
- IF, CASE and loops make maths and sequences compact.
- Clear names, bounded loops and comments keep code maintainable.
