動作氣壓缸A往復3次,氣壓缸B延時3秒
全域符號表 global .csv
Class,Identifiers,Address,Type,Initial Value,Comment
VAR,state,,INT,0,
VAR,pbStart,X0.0,BOOL,,啟動
VAR,lsA0,X0.1,BOOL,,極限開關a0
VAR,lsA1,X0.2,BOOL,,極限開關a1
VAR,lsB0,X0.3,BOOL,,極限開關b0
VAR,lsB1,X0.4,BOOL,,極限開關b1
VAR,svA1,Y0.1,BOOL,,雙邊電磁閥A+ [單邊電磁閥A+-]
VAR,svA0,Y0.2,BOOL,,雙邊電磁閥A-
VAR,svB1,Y0.3,BOOL,,雙邊電磁閥B+ [單邊電磁閥B+-]
VAR,svB0,Y0.4,BOOL,,雙邊電磁閥B-
區域符號表 cnt.csv
Class,Identifiers,Address,Type,Initial Value,Comment
VAR,CNT0,,WORD,,計數器
VAR,CNT0_Q,,BOOL,,計數器輸出
ST程式
(* [A+ A-]3 B+ T0 B- *)
(* 狀態機 *)
CASE state OF
0: (* S0 *)
IF pbStart
THEN state := 1; (* next state *)
END_IF;
1: (* S1 -> A+ *)
svA0 := FALSE; (* output rst svA- *)
svA1 := TRUE; (* output set svA+ *)
IF lsA1
THEN state := 2; (* next state *)
END_IF;
2: (* S2 -> A- *)
svA1 := FALSE; (* output rst svA+ *)
svA0 := TRUE; (* output set svA- *)
IF lsA0
THEN state := 3; (* next state *)
END_IF;
3: (* S3 -> CNT0 *)
svA0 := FALSE; (* output rst svA- *)
CNT0 := CNT0 + 1; (* counter +1 *)
IF CNT0 = 3 (* counter = 3 ? *)
THEN CNT0_Q := TRUE; (* yes CNT0-Q on *)
ELSE CNT0_Q := FALSE; (* no CNT0-Q off *)
END_IF;
IF CNT0_Q
THEN state := 4; (* next state B+ *)
ELSE state := 1; (* next state A+ *)
END_IF;
4: (* S4 -> B+ *)
CNT0 := 0; (* rst CNT0 *)
CNT0_Q := FALSE; (* rst CNT0-Q *)
svA0 := FALSE; (* output rst svA- *)
svB1 := TRUE; (* output set svB+- *)
IF lsB1
THEN state := 5; (* next state *)
END_IF;
5: (* S5 -> T0 *)
TMR (T0, 30); (* output Timer on *)
IF T0
THEN state := 6; (* next state *)
END_IF;
6: (* S6 -> B- *)
svB1 := FALSE; (* output rst svB+- *)
T0 := FALSE; (* output rst T0 *)
IF lsB0
THEN state := 0; (* next state *)
END_IF;
ELSE state := 0;
END_CASE;