Structured Text Programming
▪ Structured Text better PLC
programming language,
textual programming language,
utilizing statements to determine what to
execute
▪ Follows more conventional programming
protocols
▪ A series of statements (logic), expressing
assignments and relationships using several
operators is constituted.
List of structured text operators
▪ What is Structured Text (ST) Programming?
- Text-based PLC program takes up much smaller space,
Flow/logic easier to read, understand.
Example: 1 line of code can scale an analog input or output
or set an alarm for a SCADA system solution
- Added advantage: Combination of different programming languages, function
blocks containing functions written in ST.
- With ST, standardized programming language gives option to program different
PLC brands.
Most common PLC (Europe) Siemens S7 PLCs.
- Syntax of ST is developed to look like syntax of a high-level programming language
with loops, variables, conditions, and operators.
▪ The Flow of Structured Text
- 1st thing to learn structure or syntax of Structured Text.
PROGRAM stexample
Structure understood - flow of program.
VAR x : BOOL;
- Whole program begins with PROGRAM and ends
with END_PROGRAM delimiting keywords for END_VAR
program declarations. x := TRUE;
Everything in between is PLC program.
REPEAT
- When PLC reaches END_PROGRAM, PLC scan cycle
starts over again, and program repeats itself. UNTIL x := FALSE;
END_REPEAT;
- Flow control in ST same as in ladder logic:
execute 1 line at a time. END_PROGRAM;
▪ In ST, use of PROGRAM/ END_PROGRAM is not essential already done by
PLC programming software.
❖ Starting with the Syntax of Structured Text
▪ Structured Text- full of colons, semicolons, other symbols.
All symbols have meanings and are used to represent something.
Some are operators, some are functions, statements, or variables.
▪ General rules for syntax of Structured Text
- All statements are separated by semicolons
- The language is not case-sensitive
- Spaces have no function- should be used for readability.
PLC program written in Structured Text – computer translates that to understandable
language of PLC. Structured Text PLC program uploaded to PLC- programming
software compiles program translation to a machine code, executable by PLC.
▪ Comment Syntax
In textual programming, writing text that doesn’t get executed is possible comments
Comments are good for a beginner, make it easier to understand code later.
In Structured Text, either 1-line or multiple line comments.
Single line comment:
// comment
Comment after end of ST line:
<expression>; /* comment */
or
<statement>; (* comment *)
Multiple line comment:
/* start comment
...
end comment */
or
(* start comment
...
end comment *)
▪ Data Types in Structured Text
All standard data types are defined by PLC Open Organization and part of PLC
programming languages.
Every PLC programming software with Structured Text includes these data types.
IEC standard - data types are of 2 categories:
Elementary data types, Derived data types.
Elementary data types
Integers
Floating points
Time
Strings
Bit strings
Each elementary data types has several IEC data types defined in IEC 61131-3
Integers: Floating points:
IEC Data Type Format Range IEC Data Type Format Range
SINT Short Integer -128 … 127 REAL Real ±10^±38
INT Integer -32768 … 32767 Numbers
DINT Double Integer -2^31 … 2^31-1 LREAL Long Real ±10^±308
Numbers
LINT Long Integer -2^63 … 2^63-1
USINT Unsigned Short 0 … 255
Integer
UINT Unsigned Integer 0 … 2^16-1
LDINT Long Double 0 … 2^32-1
Integer
ULINT Unsigned Long 0 … 2^64-1
Integer
Time:
IEC Data Type Format Use
TIME Duration of time after an event T#10d4h38m57s12ms
TIME#10d4h38m
DATE Calendar date D#1989-05-22
DATE#1989-05-22
TIME_OF_DAY Time of day TOD#14:32:07
TIME_OF_DAY#14:32:07.77
DATE_AND_TIME Date and time of day DT#1989-06-15-13:56:14.77
DATE_AND_TIME#1989-06-15-
13:56:14.77
Strings:
IEC Data Type Format Range
STRING Character String ‘My string’
Bit strings:
IEC Data Type Format Range
BOOL Boolean 1 bit
BYTE Byte 8 bits
WORD Word 16 bits
DWORD Double Word 32 bits
LWORD Long Word 64 bits
Derived data types
• Structured data types
• Enumerated data types
• Sub-ranges data types
• Array data types
Derived data types custom data types.
All derived data types are built by making construction of keywords TYPE & END_TYPE .
Different data types hold different data formats and different values.
▪ Operators and Expressions in STL
- Variables are used with statements and operators. Operators manipulate data,
expression yields a value when evaluated
Example- A contains value 10 and B contains 8.
Result of expression A+B: 18. Instead of A+B, compiler puts in value 18.