Anda di halaman 1dari 7

Programming in ST

Basic instructions in ST: IF Condition (Condition that has to be true before an Action can take place) THEN Action := TRUE; (Action is performed if the condition is true) ELSE Action := FALSE; (Action is performed if the condition is not true) END_IF (End If instruction) The := is an assignment. When the variable is TRUE it becomes a 1 When the variable is FALSE it becomes a 0
DC-B/Holtmann, Martin PLC371 - Programming in ST March 8, 2013

Semi-Colon ; is used to end an action, and a declaration.

A Semi-Colon ; is the shortest possible program that can be written in ST and downloaded to the controller.

Programming in ST
Example: IF Start AND Stop THEN L_Work := TRUE; ELSE L_Work := FALSE; END_IF If the start is actuated then the L_Work will go on if the Start is released then L_Work will go off. In ST the Set and Reset functions does not exist. Example: IF Start OR L_Work AND Stop THEN L_Work := TRUE; ELSE L_Work := FALSE; END_IF This method will work but has one danger. It is Set dominant. In ST the AND is processed before the OR. The control is done by simultaneously actuation of the Start and the Stop In this case L_Work will go on, 1

DC-B/Holtmann, Martin

PLC371 - Programming in ST

March 8, 2013

Programming in ST
Example: IF ( Start OR L_Work ) AND Stop THEN L_Work := TRUE; ELSE L_Work := FALSE; END_IF The brackets are used to form an AND function with the Stop. The instructions between the brackets will be processed first and the result will be used with the AND. Order of Boolean processing: Brackets NOT AND OR

This is a Reset dominant. The control is done by simultaneously actuation of the Start and the Stop In this case L_Work will go off, 0
DC-B/Holtmann, Martin PLC371 - Programming in ST March 8, 2013 3

Programming in ST
Loops can be created in various ways. CASE Name OF 1: L_Error := True; Fault_Counter:=Fault_Counter+ 1; 2: L_Error := True; Fault_Counter:=Fault_Counter + 1; ELSE Fault_report := unknown L_Error : False; END_CASE FOR I=1 to 25 DO IF Then .. END_IF END_FOR Each time the loop is completed I is automatically increased. Using the Exit function a loop can be exited

DC-B/Holtmann, Martin

PLC371 - Programming in ST

March 8, 2013

Programming in ST
WHILE . DO. END_WHILE A condition is first processed before the loop will be repeated REPEAT UNTIL END_REPEAT The loop will continuously repeat UNTIL a condition is met. Using the Exit function a loop can be exited

DC-B/Holtmann, Martin

PLC371 - Programming in ST

March 8, 2013

Calling a function block in ST


Example of a counter
Block_5

Bij de variabelen moet de variabele Blok_5 To_Count defined = 0 counter CTU Var_1 is the count pulse (CU) Var_2 is the reset puls (RESET) To_count (PV) is the preset amount of counts wanted Q is the output of the counter which will go to a state of 1when the counted pulses is equal to the Te_tellen Value (CV) is the amount of conted pulses

Value = 0

In the program we write, CAL Block_5 (CU:=Var_1, RESET:=Var_2, PV:= To_Count) The variables must be given a Type. Block_5 : CTU; Var_1: BOOL; Var_2: BOOL; PV: INT; LD Block_5.Q ST Lamp LD Block_5.CV ST Value Lamp: BOOL; Value: INT;
March 8, 2013 6

DC-B/Holtmann, Martin

PLC371 - Programming in ST

Calling a function block in IL


PROGRAM PLC_PRG VAR Block_5: CTU; Var_1: BOOL; Var_2: BOOL; To_Count: INT; Lamp: BOOL; Value: INT; END_VAR (* Program body: *) LD 5 ST To_Count Blok_5 (CU:=Var_1, RESET:=Var_2, PV:= To Count) LD Block_5.Q ST Lamp LD Block_5.CV ST Value (* When activating the reset the CV will go to 0 and Q will go to a 0 state. *)

DC-B/Holtmann, Martin

PLC371 - Programming in ST

March 8, 2013

Anda mungkin juga menyukai