日本語 English

ST Language (Structured Text)

What Is ST?

ST (Structured Text) is a programming language defined in IEC 61131-3 that can be mixed with ladder
Writing calculations, FOR statements and IF statements in ST makes them easier to write and read

What you can do with ST

ST language
FunctionsExample
Conditional branchingIF
RepetitionFOR
LoopsWHILE
CASE branchingCASE
Formulas+ - * /
Function callsFunction

Differences between ladder and ST

Comparison
ItemLadder logicST
Readability○○
Complex calculations△◎
FOR statement×◎
CASE statement×◎
Maintainability○○

Example

Calculating a triangle
Calculating the area of a triangle in ST

Writing this in ladder requires variables to temporarily hold intermediate values, making it harder to read
Calculating the area of a triangle in ladder

Basic ST syntax

IF statement

IF Value > 10 THEN
	Judge := TRUE;
ELSE
	Judge := FALSE;
END_IF;

FOR statement

FOR i := 0 TO 9 DO
	Sum := Sum + Data[i];
END_FOR;

CASE statement

CASE Step OF
0:
	Start();
1:
	Run();
2:
	Stop();
END_CASE;

Notes

Points to note when handling flags with IF statements

Consider turning Judge ON when the area of a triangle is 10 or more
Example of flag handling with an IF statement
It is tempting to write it like this, but then once Judge turns ON it stays ON even if the area is less than 10, so always add ELSE as below to turn Judge OFF when it is less than 10
Flag handling using ELSE

Inline ST is skipped when its start condition is OFF

When flg, the start condition of the inline ST, turns OFF, the inline ST is not executed
Therefore variables inside the inline ST keep their previous values, so Judge stays at its previous value; note that if it was ON, it will never change to OFF
If you want Judge to turn OFF when flg is OFF, the simple way seems to be doing only the calculation in ST and moving the IF statement outside the inline ST (adjust the approach to the situation)
Effect of inline ST execution conditions

Comments