Basic Structured Text Programming
Structured Text (ST)
PLC programmers have traditionally developed applications using Ladder Logic. PLC manufactures have controllers capable of accepting programs written in the 5 recognized standards as specified in Part 3 of the IEC 61131. The five supported languages are:
- Ladder diagram (LD), graphical
- Function block diagram (FBD), graphical
- Structured text (ST), textual
- Instruction list (IL), textual
- Sequential function chart (SFC), graphical
Structured Text (ST) is a high level textual language that is a Pascal like language. It is based on the IEC 61131-3 standard, which standardizes programming languages for programmable controllers (PLC). Structured Text is very flexible and intuitive for writing control algorithms.
Structured Text uses operators such as logical branching, multiple branching, and loops. People trained in computer programming languages often find it the easiest language to use for programming control logic. When symbolic addressing is used, ST programs resemble sentences, making it highly intelligible to beginner users as well.
Benefits of Structured Text
- People trained in computer languages can easily program control logic
- Tag Structure UDT (User Defined Tags), local variables and other ST programming conventions make the programs easy to understand
- Programs can be created in any text editor
- State-Model or Power Programming is easily entered with the Case statement
This article presents a very common programming technique often incorporated in a typical PLC program. The method is for creating a Toggle On / Toggle Off control with a single input. The traditional Ladder Diagram technique for this sequence is shown in the graphic below. The Structured Text method is presented below. Start_Stop is the single input, ON_OFF is the output that will Toggle ON / Toggle OFF. The other tags are local symbols used to help support the logic. The tag or symbol ONS_Trig is known as a one shot operator. A one shot is true for only one scan while the control or operand is maintained true.
Basic Structured Text (ST) Example:
// Start of Logic <-- Programming remark initiated with the double // slash
// Catch the Rising Edge One Shot of the Start_Stop input
ONS_Trig := Start_Stop AND NOT Rising_ONS;
// Main Logic for Run_Contact -- Toggle ON / Toggle OFF ---
ON_OFF := (ONS_Trig AND NOT ON_OFF) OR (ON_OFF AND NOT ONS_Trig);
// Rising One Shot logic
Rising_ONS := Start_Stop;