Beckhoff Automation GmbH & Co. KG TX1200 — 2.2.3 Structured Text (ST)

A Brief Introduction to TwinCAT PLC Control Instruction in structured text The name already indicates, the structured text is designed for structure programming, i.e. ST offers predetermined structures for certain often used constructs such as loops for programming. This offers the advantages of low error probability and increased clarity of the program. For example, let us compare two equally significant program sequences in IL and ST: A loop for calculating powers of two in IL: Loop: LD Counter EQ 0 JMPC end LD Var1 MUL 2 ST Var1 LD Counter SUB 1 ST Counter JMP Loop End: LD Var1 ST ERG TX1200 19 Version:

1.3 Instruction Example Assignment A:=B; CV := CV + 1; C:=SIN(X); Calling a function block and use of the FB version CMD TMR(IN := %IX5, PT := 300);A:=CMD TMR.Q; _ _ RETURN RETURN; IF IF D CASE CASE INT1 OF 1: BOOL1 := TRUE; 2: BOOL2 := TRUE; ELSE BOOL1 := FALSE; BOOL2 := FALSE; END CASE; _ FOR FOR I:=1 TO 100 BY 2 DO IF ARR[I] = 70 THEN J:=I; EXIT; END IF; _ END FOR; _ WHILE WHILE J 70 DO J:=J+2; END WHILE; _ REPEAT REPEAT J:=J+2; UNTIL J= 101 OR ARR[J] = 70 END REPEAT; _ EXIT EXIT; Empty instruction ;