Skip to content

ST Supported Functions Coming Soon

This section lists all the supported IEC 61131-3 Structured Text functions.

Standard Functions

InstructionExampleDescription
ABSA := ABS(B);Absolute value.
SQRTA := SQRT(B);Square root.
LNA := LN(B);Natural logarithm.
LOGA := LOG(B);Logarithm base 10.
EXPA := EXP(B);Natural exponential.
SINA := SIN(B);Sine of input in radians.
COSA := COS(B);Cosine in radians.
TANA := TAN(B);Tangent in radians.
ASINA := ASIN(B);Principal arc sine.
ACOSA := ACOS(B);Principal arc cosine.
ATANA := ATAN(B);Principal arc tangent.

Arithmetic Functions

InstructionSymbolExampleDescription
ADD+A := ADD(B,C); or A := B+C;Adds two or more numerical values.
MUL*A := MUL(B,C); or A := B*C;Multiplies two or more numerical values.
SUB-A := SUB(B,C); or A := B-C;Subtracts the second numerical value from the first.
DIV/A := DIV(B,C); or A := B/C;Divides the first numerical value by the second.
MODA := MOD(B,C);Computes the remainder of division of the first numerical value by the second.
EXPT**A := EXPT(B,C); or A := B**C;Raises the first numerical value to the power of the second.
MOVE:=A := B;Assigns the value of one variable to another.

Bit Shift Functions

InstructionExampleDescription
SHLA := SHL(IN:=B, N:=5);Left shifted by N bits, zero filled on the right.
SHRA := SHR(IN:=B, N:=5);Right shifted by N bits, zero filled on the left.
RORA := ROR(IN:=B, N:=5);Right rotated by N bits, circular.
ROLA := ROL(IN:=B, N:=5);Left rotated by N bits, circular.

Bitwise Boolean Functions

InstructionSymbolExampleDescription
AND&A := AND(B,C); or A := B & C;Logical conjunction operator. Returns TRUE if both operands are TRUE, otherwise FALSE.
ORA := OR(B,C); or A := B OR C;Logical disjunction operator. Returns TRUE if at least one operand is TRUE, otherwise FALSE.
XORA := XOR(A,B); or A := B XOR C;Logical exclusive OR operator. Returns TRUE if exactly one operand is TRUE, otherwise FALSE.
NOTA := NOT(B); or A := NOT B;Logical negation operator. Inverts the value of the operand. If the operand is TRUE, NOT returns FALSE; if the operand is FALSE, NOT returns TRUE.

Selection Functions

InstructionExampleDescription
SELA := SEL(G:=0,IN0:=X,IN1:=5);Selects between two inputs based on a Boolean condition. If the condition (G) is true (1), it outputs IN1; if false (0), it outputs IN0.
MAXA := MAX(B,C,D);Returns the maximum value among all its inputs.
MINA := MIN(B,C,D);Returns the minimum value among all its inputs.
LIMITA := LIMIT(IN:=B,MN:=0,MX:=5);Limits an input (IN) value between a minimum (MN) and a maximum (MX) bound.
MUXA := MUX(0, B, C, D);Selects one of several inputs based on the index (K) and outputs it.

Comparison Functions

InstructionSymbolExampleDescription
GT>A := IN1>IN2;Output TRUE if one input is greater than another. Otherwise false.
GE>=A := IN1>=IN2;Output TRUE if one input is greater than or equal to another. Otherwise false.
EQ=A := IN1=IN2;Output TRUE if one input is exactly equal to another. Otherwise false.
LE<=A := IN1<=IN2;Output TRUE if one input is less than or equal to another. Otherwise false.
LT<A := IN1<IN2;Output TRUE if one input is less than another. Otherwise false.
NE<>A := IN1 <> IN2;Output TRUE if one input is exactly not equal to another. Otherwise, false.

Character String Functions

InstructionExampleDescription
LENA := LEN('ASTRING');Returns the length of a string.
LEFTA := LEFT(IN:='ASTR',L:=3);Extracts a specified number of characters from the beginning (left side) of a string. It requires two parameters: the string and the number of characters to extract.
RIGHTA := RIGHT(IN:='ASTR',L:=3);Extracts a specified number of characters from the end (right side) of a string. Similar to LEFT, it requires the string and the number of characters to extract.
MIDA := MID(IN:='ASTR',L:=2,P:=2);Retrieves a substring from a string, starting at a specified position and with a specified length. It requires three parameters: the original string, the start position, and the number of characters to extract.
CONCATA := CONCAT('AB','CD','E');Concatenates two or more strings into one. It takes two or more string parameters and returns a single string that is the combination of all the inputs.
INSERTA:=INSERT(IN1:='ABC',IN2:='XY',P=2 );Inserts a string into another string at a specified position. It requires three parameters: the string to insert, the target string, and the position at which to insert the first string into the second.
DELETEA := DELETE(IN:='ABXYC',L:=2, P:=3);Removes a specified number of characters from a string, starting at a specified position. It requires three parameters: the original string, the start position, and the number of characters to delete.
REPLACEA := REPLACE(IN1:='ABCDE',IN2:='X', L:=2, P:=3)Replaces part of a string with another string. It typically requires four parameters: the original string, the substring to replace, the replacement string, and sometimes the start position for the replacement.
FINDA := FIND(IN1:='ABCBC',IN2:='BC')Searches for a substring within another string and returns the position of the first occurrence. If the substring is not found, it returns 0. It requires at least two parameters: the substring to find and the string to search within.

Functions of Time Data Types

InstructionExampleDescription
ADD_TIMEA := ADD_TIME(IN1:=T#2h20m, IN2:=T#30m);Adds a time interval to a time value.
ADD_TOD_TIMEA := ADD_TOD_TIME(IN1:=TOD#14:00:00, IN2:=T#2h);Adds a time interval to a time-of-day value, resulting in a new time-of-day value.
ADD_DT_TIMEA := ADD_DT_TIME(IN1:=DT#2024-04-01-15:00:00, IN2:=T#24h);Adds a time interval to a datetime value, resulting in a new datetime value.
SUB_TIMEA := SUB_TIME(IN1:=T#2h, IN2:=T#30m);Subtracts a time interval from a time value.
SUB_DATE_DATEA := SUB_DATE_DATE(IN1:=D#2024-04-10, IN2:=D#2023-04-01);Subtracts one date from another, resulting in a time interval that represents the difference.
SUB_TOD_TIMEA := SUB_TOD_TIME(IN1:=TOD#15:00:00, IN2:=T#2h);Subtracts a time interval from a time-of-day value, resulting in a new time-of-day value.
SUB_TOD_TODA := SUB_TOD_TOD(IN1:=TOD#17:00:00, IN2:=TOD#15:00:00);Subtracts one time-of-day value from another, resulting in a time interval that represents the difference.
SUB_DT_TIMEA := SUB_DT_TIME(IN1:=DT#2024-04-02-12:00:00, IN2:=T#12h);Subtracts a time interval from a datetime value, resulting in a new datetime value.
SUB_DT_DTA := SUB_DT_DT(IN1:=DT#2024-04-02-12:00:00, IN2:=DT#2024-04-01-12:00:00)Subtracts one datetime value from another, resulting in a time interval that represents the difference.
MULTIMEA := MULTIME(IN1:=T#1h, IN2:=3);Multiplies a time interval by a factor, resulting in a new time interval.
DIVTIMEA := DIVTIME(IN1:=T#1h, IN2:=2);Divides a time interval by a factor, resulting in a new time interval.
CONCAT_DATE_TODA := CONCAT_DATE_TOD(IN1:=D#2024-04-01, IN2:=TOD#12:00:00);Combines a date and a time-of-day value into a single datetime value.
DT_TO_TODA := DT_TO_TOD(IN:=DT#2024-04-01-15:00:00);Converts a datetime value into a time-of-day value, essentially extracting the time portion of a datetime.
DT_TO_DATEA := DT_TO_DATE(IN:=DT#2023-04-01-15:00:00);Converts a datetime value into a date value, essentially extracting the date portion of a datetime.

Bistable Function Blocks

InstructionExampleDescription
SRSR(S:=Set, R:=Reset, Q=>Output);Sets its output (Q) to TRUE when the Set (S) input is activated. The output remains TRUE until the Reset (R) input is activated, which then sets the output to FALSE. If both inputs are active, the Set input has priority.
RSRS(R:=Reset, S:=Set, Q=>Output);Resets its output (Q) to FALSE when the Reset (R) input is activated. The output remains FALSE until the Set (S) input is activated, which then sets the output to TRUE. If both inputs are active, the Reset input has priority.

Edge Detection Function Blocks

InstructionExampleDescription
R_TRIGR_TRIG(CLK:=InputSignal, Q=>OutputPulse);Activates its output for one scan cycle when its input changes from FALSE to TRUE.
F_TRIGF_TRIG(CLK:=InputSignal, Q=>OutputPulse);Activates its output for one scan cycle when its input changes from TRUE to FALSE.

Counter Function Blocks

InstructionExampleDescription
CTUCTU(CU:=IncrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Increments its count value on the rising edge of its input.
CTU_DINTCTU(CU:=IncrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Increments its count value on the rising edge of its input. Uses a double integer (DINT) for the counter value.
CTU_LINTCTU(CU:=IncrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Increments its count value on the rising edge of its input. Uses a long integer (LINT) for the counter value.
CTU_DINTCTU(CU:=IncrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Increments its count value on the rising edge of its input. Uses a long integer (DINT) for the counter value.
CTU_UDINTCTU(CU:=IncrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Increments its count value on the rising edge of its input. Uses a unsigned double integer (UDINT) for the counter value.
CTU_ULINTCTU(CU:=IncrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Increments its count value on the rising edge of its input. Uses a unsigned long integer (ULINT) for the counter value.
CTDCTD(CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Decrements its count value on the rising edge of its input.
CTD_DINTCTD(CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Decrements its count value on the rising edge of its input. Uses a double integer (DINT) for the counter value.
CTD_LINTCTD(CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Decrements its count value on the rising edge of its input. Uses a long integer (LINT) for the counter value.
CTD_UDINTCTD(CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Decrements its count value on the rising edge of its input. Uses a unsigned double integer (UDINT) for the counter value.
CTD_ULINTCTD(CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Decrements its count value on the rising edge of its input. Uses a unsigned long integer (ULINT) for the counter value.
CTUDCTUD(CU:=IncrementSignal, CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Can count both up and down, controlled by separate inputs for each direction.
CTUD_DINTCTUD(CU:=IncrementSignal, CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Can count both up and down, controlled by separate inputs for each direction. Uses a double integer (DINT) for the counter value.
CTUD_LINTCTUD(CU:=IncrementSignal, CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Can count both up and down, controlled by separate inputs for each direction. Uses a long integer (LINT) for the counter value.
CTUD_ULINTCTUD(CU:=IncrementSignal, CD:=DecrementSignal, PV:=10, Q=>OutputEnable, CV=>CurrentCount);Can count both up and down, controlled by separate inputs for each direction. Uses a unsigned long integer (ULINT) for the counter value.

Timer Function Blocks

InstructionExampleDescription
TPTP(IN:=StartTimer, PT:=T#5s, Q=>TimerActive);Activates its output for a specified duration when its input is TRUE, then turns off regardless of the input state.
TONTON(IN:=StartTimer, PT:=T#5s, Q=>TimerActive);Begins timing when its input is TRUE, and after the specified delay, turns its output TRUE.
TOFTOF(IN:=StartTimer, PT:=T#5s, Q=>TimerActive);Keeps its output TRUE as long as its input is TRUE, and starts timing when the input becomes FALSE. After the specified delay, it turns its output FALSE.

Datatype Conversions

Need to add.

IF Statement

Example

ST
D := B*B - 4*A*C;
IF D < 0.0 THEN 
    NROOTS := 0; 
ELSIF D = 0.0 THEN
    NROOTS := 1;
    X1 := - B/(2.0*A); 
ELSE
    NROOTS := 2 ;
    X1 := (- B + SQRT(D))/(2.0*A); 
    X2 := (- B - SQRT(D))/(2.0*A);
END_IF ;

CASE Statement

Example

ST
TW := BCD_TO_INT(THUMBWHEEL);
TW_ERROR := 0;
CASE TW OF
    1,5: DISPLAY := OVEN_TEMP;
    2: DISPLAY := MOTOR_SPEED;
    3: DISPLAY := GROSS - TARE; 4,6..10: DISPLAY := STATUS(TW - 4);
ELSE DISPLAY := 0 ; 
        TW_ERROR := 1;
END_CASE;
QW100 := INT_TO_BCD(DISPLAY);

FOR Loops

Example

ST
J := 101;
FOR I := 1 TO 100 BY 2 DO
    IF WORDS[I] = 'KEY' THEN 
        J := I;
        EXIT;
    END_IF; 
END_FOR;

WHILE Loops

Example

ST
J := 1;
WHILE J <= 100 & WORDS[J] <> 'KEY' DO
    J := J+2; 
END_WHILE;

REPEAT Loops

Example

ST
J := -1; 
REPEAT
    J := J+2;
UNTIL J = 101 OR WORDS[J] = 'KEY' 
END_REPEAT;

RETURN statement

Example

ST
RETURN;

EXIT statement

Example

ST
EXIT;

EMPTY statement

ST
;