定时可用于在触发或关闭同一电机时产生延迟,或在不同电机之间产生打开或关闭延迟。这是一项用于保护电机的功能,可避免以非常短的间隔驱动。在警报情况下,电机会自动禁用(随着时间的推移优先)以避免进一步损坏。
通过创建一个子例程来读取机器的状态来启动我的代码,这将告诉我它是打开还是关闭。然后创建一个读取处于警报状态的机器的子程序,然后我检查了机器是否处于警报状态。在这段代码下面,我创建了一个驱动电机的例程,然后创建一个例程来触发必须连接电机上的输出,我用一个 else 完成了我的代码,它关闭了电机。
VAR_INPUT
ENABLE : BOOL := FALSE; (*ENABLES THE BLOCK OPERATION*)
DEV_STS1 : BOOL := FALSE; (*REPRESENTS MOTOR STATUS 1 ON / OFF*)
DEV_STS2 : BOOL := FALSE; (*REPRESENTS MOTOR STATUS 2 ON / OFF*)
DEV_STS3 : BOOL := FALSE; (*REPRESENTS MOTOR STATUS 3 ON / OFF*)
DEV_STS4 : BOOL := FALSE; (*REPRESENTS MOTOR STATUS 4 ON / OFF*)
DEV_STS5 : BOOL := FALSE; (*REPRESENTS MOTOR STATUS 5 ON / OFF*)
DEV_STS6 : BOOL := FALSE; (*REPRESENTS MOTOR STATUS 6 ON / OFF*)
DEV_ALA1 : BOOL := FALSE; (*REPRESENTS MOTOR ALARM CONDITION 1*)
DEV_ALA2 : BOOL := FALSE; (*REPRESENTS MOTOR ALARM CONDITION 2*)
DEV_ALA3 : BOOL := FALSE; (*REPRESENTS MOTOR ALARM CONDITION 3*)
DEV_ALA4 : BOOL := FALSE; (*REPRESENTS MOTOR ALARM CONDITION 4*)
DEV_ALA5 : BOOL := FALSE; (*REPRESENTS MOTOR ALARM CONDITION 5*)
DEV_ALA6 : BOOL := FALSE; (*REPRESENTS MOTOR ALARM CONDITION 6*)
T_MIN_ON : REAL := 0.0; (*MINIMUM TIME ON ONE SAME MOTOR / RANGE 0.0 ~ 9999.0 **)
T_MIN_OFF : REAL := 0.0; (*MINIMUM TIME OFF OF SAME MOTOR / RANGE 0.0 ~ 9999.0*)
T_ON_ON : REAL := 0.0; (*MINIMUM TIME BETWEEN TWO PARTS OF THE SAME MOTOR / RANGE 0.0 ~ 9999.0*)
T_ON_OTHER : REAL := 0.0; (*TIME BETWEEN TURN ON DIFFERENT MOTORS / RANGE 0.0 ~ 9999.0*)
T_OFF_OTHER : REAL := 0.0; (*TIME BETWEEN TURN OFF DIFFERENT MOTORS / RANGE 0.0 ~ 9999.0*)
END_VAR
VAR_OUTPUT
REQ_DEV1 : BOOL := FALSE; (*STATUS D0 MOTOR 1 (COMPRESSOR) ACCORDING TO THE TIMER LOGIC*)
REQ_DEV2 : BOOL := FALSE; (*STATUS D0 MOTOR 2 (COMPRESSOR) ACCORDING TO THE TIMER LOGIC*)
REQ_DEV3 : BOOL := FALSE; (*STATUS D0 MOTOR 3 (COMPRESSOR) ACCORDING TO THE TIMER LOGIC*)
REQ_DEV4 : BOOL := FALSE; (*STATUS D0 MOTOR 4 (COMPRESSOR) ACCORDING TO THE TIMER LOGIC*)
REQ_DEV5 : BOOL := FALSE; (*STATUS D0 MOTOR 5 (COMPRESSOR) ACCORDING TO THE TIMER LOGIC*)
REQ_DEV6 : BOOL := FALSE; (*STATUS D0 MOTOR 6 (COMPRESSOR) ACCORDING TO THE TIMER LOGIC*)
END_VAR
VAR
DEV_STS : ARRAY[1..6] OF BOOL; (*MOTOR STATUS READING ARRAY*)
DEV_ALA : ARRAY[1..6] OF BOOL; (*ARRAY READING OF MOTORS ALARMS*)
REQ_DEV : ARRAY[1..6] OF BOOL; (*ARRAY TO MANIPULATE MOTORS STATES*)
FLAG_STS : ARRAY[1..6] OF BOOL; (*ARRAY FOR PREVIOUS STATUS CONTROL OF MOTORS*)
IDX : USINT := 0; (*GENERIC INDEX TO HANDLE ARRAY*)
DEV_ON : USINT := 0; (*AMOUNT OF MOTORS MUST BE TURN ON*)
T_ON_INT : ARRAY[1..6] OF REAL; (*INTERNAL TIME ON A SAME MOTOR*)
T_OFF_INT : ARRAY[1..6] OF REAL; (*INTERNAL TIME OFF A SAME MOTOR*)
T_CYCLE : ARRAY[1..6] OF REAL; (*CYCLE TIME OF SAME MOTOR*)
END_VAR
IF ENABLE THEN
(*==================================================================================*)
(*READINGS OF MOTORS STATUS*)
(*==================================================================================*)
DEV_STS[1] := DEV_STS1;
DEV_STS[2] := DEV_STS2;
DEV_STS[3] := DEV_STS3;
DEV_STS[4] := DEV_STS4;
DEV_STS[5] := DEV_STS5;
DEV_STS[6] := DEV_STS6;
(*==================================================================================*)
(*READINGS OF THE MOTORS ALARM STATUS*)
(*==================================================================================*)
DEV_ALA[1] := DEV_ALA1;
DEV_ALA[2] := DEV_ALA2;
DEV_ALA[3] := DEV_ALA3;
DEV_ALA[4] := DEV_ALA4;
DEV_ALA[5] := DEV_ALA5;
DEV_ALA[6] := DEV_ALA6;
(*==================================================================================*)
(*CHECK IF ANY MOTOR IS ALARMED*)
(*==================================================================================*)
FOR IDX := 0 TO 6 BY 1 DO
IF DEV_ALA[IDX] = TRUE THEN
REQ_DEV[IDX] := FALSE;
END_IF;
END_FOR;
(*==================================================================================*)
(*CHECKING WHAT MOTOR SHOULD BE TURN ON*)
(*==================================================================================*)
FOR IDX := 0 TO 6 BY 1 DO
IF DEV_STS[IDX] = TRUE THEN
DEV_ON := DEV_ON + 1;
END_IF;
END_FOR;
(*==================================================================================*)
(*ACTING A MOTOR*)
(*==================================================================================*)
FOR IDX := 0 TO 6 DO
T_CYCLE[IDX] := T_ON_INT[IDX] + T_OFF_INT[IDX];
IF DEV_STS[IDX] = TRUE AND FLAG_STS[IDX] = FALSE THEN
IF T_CYCLE[IDX] > T_ON_ON THEN
IF T_ON_INT[IDX] < T_MIN_OFF THEN
REQ_DEV[IDX] := TRUE;
END_IF;
END_IF;
END_IF;
IF DEV_STS[IDX] = FALSE AND FLAG_STS[IDX] = TRUE THEN
IF T_ON_INT[IDX] >= T_MIN_ON THEN
REQ_DEV[IDX] := FALSE;
END_IF;
END_IF;
IF DEV_STS[IDX] = TRUE AND FLAG_STS[IDX] = TRUE THEN
T_ON_INT[IDX] := T_ON_INT[IDX] + 1.0;
END_IF;
END_FOR;
(*==================================================================================*)
(*LEADING OUTPUTS*)
(*==================================================================================*)
REQ_DEV1 := REQ_DEV[1] ;
REQ_DEV2 := REQ_DEV[2] ;
REQ_DEV3 := REQ_DEV[3] ;
REQ_DEV4 := REQ_DEV[4] ;
REQ_DEV5 := REQ_DEV[5] ;
REQ_DEV6 := REQ_DEV[6] ;
(*==================================================================================*)
(*FLAG*)
(*==================================================================================*)
FLAG_STS[1] := REQ_DEV1;
FLAG_STS[2] := REQ_DEV2;
FLAG_STS[3] := REQ_DEV3;
FLAG_STS[4] := REQ_DEV4;
FLAG_STS[5] := REQ_DEV5;
FLAG_STS[6] := REQ_DEV6;
ELSE
REQ_DEV1 := FALSE;
REQ_DEV2 := FALSE;
REQ_DEV3 := FALSE;
REQ_DEV4 := FALSE;
REQ_DEV5 := FALSE;
REQ_DEV6 := FALSE;
END_IF;
我还没有测试代码。但是我一般用CFC来测试。