Structured text

Last updated

Structured text, abbreviated as ST or STX, is one of the five languages supported by the IEC 61131-3 standard, designed for programmable logic controllers (PLCs). [1] [2] It is a high level language that is block structured and syntactically resembles Pascal, on which it is based. [3] All of the languages share IEC61131 Common Elements. The variables and function calls are defined by the common elements so different languages within the IEC 61131-3 standard can be used in the same program.

Contents

Complex statements and nested instructions are supported:

Sample program

(* simple state machine *)TxtState:=STATES[StateMachine];CASEStateMachineOF1:ClosingValve();StateMachine:=2;2:OpeningValve();ELSEBadCase();END_CASE;

Unlike in some other programming languages, there is no fallthrough for the CASE statement: the first matching condition is entered, and after running its statements, the CASE block is left without checking other conditions.

Additional ST programming examples

// PLC configurationCONFIGURATIONDefaultCfgVAR_GLOBALb_Start_Stop:BOOL;// Global variable to represent a boolean.b_ON_OFF:BOOL;// Global variable to represent a boolean.Start_StopAT%IX0.0:BOOL;// Digital   input of the PLC (Address 0.0)ON_OFFAT%QX0.0:BOOL;// Digital output of the PLC (Address 0.0). (Coil)END_VAR// Schedule the main program to be executed every 20 msTASKTick(INTERVAL:=t#20ms);PROGRAMMainWITHTick:Monitor_Start_Stop;END_CONFIGURATIONPROGRAMMonitor_Start_Stop// Actual ProgramVAR_EXTERNALStart_Stop:BOOL;ON_OFF:BOOL;END_VARVAR// Temporary variables for logic handlingONS_Trig:BOOL;Rising_ONS:BOOL;END_VAR// Start of Logic// Catch the Rising Edge One Shot of the Start_Stop inputONS_Trig:=Start_StopANDNOTRising_ONS;// Main Logic for Run_Contact -- Toggle ON / Toggle OFF ---ON_OFF:=(ONS_TrigANDNOTON_OFF)OR(ON_OFFANDNOTONS_Trig);// Rising One Shot logic   Rising_ONS:=Start_Stop;END_PROGRAM

Function block example

//=======================================================================// Function Block Timed Counter :  Incremental count of the timed interval//=======================================================================FUNCTION_BLOCKFB_Timed_CounterVAR_INPUTExecute:BOOL:=FALSE;// Trigger signal to begin Timed CountingTime_Increment:REAL:=1.25;// Enter Cycle Time (Seconds) between countsCount_Cycles:INT:=20;// Number of Desired Count CyclesEND_VARVAR_OUTPUTTimer_Done_Bit:BOOL:=FALSE;// One Shot Bit indicating Timer Cycle DoneCount_Complete:BOOL:=FALSE;// Output Bit indicating the Count is complete            Current_Count:INT:=0;// Accumulating Value of CounterEND_VARVARCycleTimer:TON;// Timer FB from Command LibraryCycleCounter:CTU;// Counter FB from Command LibraryTimerPreset:TIME;// Converted Time_Increment in Seconds to MSEND_VAR// Start of Function Block programmingTimerPreset:=REAL_TO_TIME(in:=Time_Increment)*1000;CycleTimer(in:=ExecuteANDNOTCycleTimer.Q,pt:=TimerPreset);Timer_Done_Bit:=CycleTimer.Q;CycleCounter(cu:=CycleTimer.Q,r:=NOTExecute,pv:=Count_Cycles);Current_Count:=CycleCounter.cv;Count_Complete:=CycleCounter.q;END_FUNCTION_BLOCK

Related Research Articles

In digital logic and computing, a counter is a device which stores the number of times a particular event or process has occurred, often in relationship to a clock. The most common type is a sequential digital logic circuit with an input line called the clock and multiple output lines. The values on the output lines represent a number in the binary or BCD number system. Each pulse applied to the clock input increments or decrements the number in the counter.

<span class="mw-page-title-main">Programmable logic controller</span> Programmable digital computer used to control machinery

A programmable logic controller (PLC) or programmable controller is an industrial computer that has been ruggedized and adapted for the control of manufacturing processes, such as assembly lines, machines, robotic devices, or any activity that requires high reliability, ease of programming, and process fault diagnosis. Dick Morley is considered as the father of PLC as he had invented the first PLC, the Modicon 084, for General Motors in 1968.

Verilog, standardized as IEEE 1364, is a hardware description language (HDL) used to model electronic systems. It is most commonly used in the design and verification of digital circuits at the register-transfer level of abstraction. It is also used in the verification of analog circuits and mixed-signal circuits, as well as in the design of genetic circuits. In 2009, the Verilog standard was merged into the SystemVerilog standard, creating IEEE Standard 1800-2009. Since then, Verilog is officially part of the SystemVerilog language. The current version is IEEE standard 1800-2017.

Ladder logic was originally a written method to document the design and construction of relay racks as used in manufacturing and process control. Each device in the relay rack would be represented by a symbol on the ladder diagram with connections between those devices shown. In addition, other items external to the relay rack such as pumps, heaters, and so forth would also be shown on the ladder diagram.

<span class="mw-page-title-main">While loop</span> Control flow statement for repeating execution until a condition is met

In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.

<span class="mw-page-title-main">For loop</span> Control flow statement for repeated execution

In computer science a for-loop or for loop is a control flow statement for specifying iteration. Specifically, a for loop functions by running a section of code repeatedly until a certain condition has been satisfied.

<span class="mw-page-title-main">Cam timer</span> Electromechanical system for controlling events

A cam timer or drum sequencer is an electromechanical system for controlling a sequence of events automatically. It resembles a music box with movable pins, controlling electrical switches instead of musical notes.

In computer programming, a function object is a construct allowing an object to be invoked or called as if it were an ordinary function, usually with the same syntax. Function objects are often called functors.

<span class="mw-page-title-main">Timer</span> Type of clock

A timer is a specialized type of clock used for measuring specific time intervals.

<span class="mw-page-title-main">Block diagram</span> Graphical system analysis method

A block diagram is a diagram of a system in which the principal parts or functions are represented by blocks connected by lines that show the relationships of the blocks. They are heavily used in engineering in hardware design, electronic design, software design, and process flow diagrams.

<span class="mw-page-title-main">Intel 8253</span> Programmable interval timer IC

The Intel 8253 and 8254 are programmable interval timers (PITs), which perform timing and counting functions using three 16-bit counters.

IEC 61131-3 is the third part of the open international standard IEC 61131 for programmable logic controllers. It was first published in December 1993 by the IEC; the current (third) edition was published in February 2013.

<span class="mw-page-title-main">Sequential function chart</span>

Sequential function chart (SFC) is a graphical programming language used for programmable logic controllers (PLCs). It is one of the five languages defined by IEC 61131-3 standard. The SFC standard is defined as, Preparation of function charts for control systems, and was based on GRAFCET.

Instruction list (IL) is one of the 5 languages supported by the initial versions of IEC 61131-3 standard, and subsequently deprecated in the third edition.

Altera Hardware Description Language (AHDL) is a proprietary hardware description language (HDL) developed by Altera Corporation. AHDL is used for digital logic design entry for Altera's complex programmable logic devices (CPLDs) and field-programmable gate arrays (FPGAs). It is supported by Altera's MAX-PLUS and Quartus series of design software. AHDL has an Ada-like syntax and its feature set is comparable to the synthesizable portions of the Verilog and VHDL hardware description languages. In contrast to HDLs such as Verilog and VHDL, AHDL is a design-entry language only; all of its language constructs are synthesizable. By default, Altera software expects AHDL source files to have a .tdf extension.

The Time Stamp Counter (TSC) is a 64-bit register present on all x86 processors since the Pentium. It counts the number of CPU cycles since its reset. The instruction RDTSC returns the TSC in EDX:EAX. In x86-64 mode, RDTSC also clears the upper 32 bits of RAX and RDX. Its opcode is 0F 31. Pentium competitors such as the Cyrix 6x86 did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their MII.

An industrial control system (ICS) is an electronic control system and associated instrumentation used for industrial process control. Control systems can range in size from a few modular panel-mounted controllers to large interconnected and interactive distributed control systems (DCSs) with many thousands of field connections. Control systems receive data from remote sensors measuring process variables (PVs), compare the collected data with desired setpoints (SPs), and derive command functions that are used to control a process through the final control elements (FCEs), such as control valves.

<span class="mw-page-title-main">CODESYS</span>

Codesys is an integrated development environment for programming controller applications according to the international industrial standard IEC 61131-3.

PLCopen is an independent organisation providing efficiency in industrial automation based on the needs of users. PLCopen members have concentrated on technical specifications around IEC 61131-3, creating specifications and implementations in order to reduce cost in industrial engineering. The outcome for example is standardized libraries for different application fields, harmonized language conformity levels and engineering interfaces for exchange. Experts of the PLCopen members are organized in technical committees and together with end users define such open standards.

<span class="mw-page-title-main">Function block diagram</span> Graphical language for PLC design

The Function Block Diagram (FBD) is a graphical language for programmable logic controller design, that can describe the function between input variables and output variables. A function is described as a set of elementary blocks. Input and output variables are connected to blocks by connection lines.

References

  1. Bacidore, Mike (16 May 2018). "Should I limit programming to ladder logic or use all standards within IEC 61131?". Control Design.
  2. Stevic, Tom (5 May 2017). "A very short history of PLC programming platforms". Control Design.
  3. 1 2 Roos, Nieke. "Programming PLCs using Structured Text". Department of Computing Science, University of Nijmegen. CiteSeerX   10.1.1.49.2016 .{{cite journal}}: Cite journal requires |journal= (help)