I cannot reset multiple timers from one program

I have the following code:
PROGRAM _INIT
(* Insert code here *)

END_PROGRAM

PROGRAM _CYCLIC
(* Insert code here *)
FOR i := 0 TO 11 DO
IF i = 0 THEN
Timers_v[i].IN := TRUE;
ELSE
Timers_v[i].IN := Timers_v[i-1].Q;
END_IF;
Timers_v[i].PT := 100;

IF Timers_v[i].Q = TRUE THEN
	DO_V[i] := TRUE;
	IF i > 0 THEN
		DO_V[i-1] := FALSE;
	END_IF;
ELSE
	DO_V[i] := FALSE;
END_IF;
	Timers_v[i]();
END_FOR;

Timer_TOT.IN := Timers_v[11].Q;
Timer_TOT.PT := 100;
IF Timer_TOT.Q THEN
	FOR i := 0 TO 11 DO
		DO_V[i] := TRUE;
	END_FOR;
END_IF;
Timer_TOT();

Timer_TOT_STINS.IN := Timer_TOT.Q;
Timer_TOT_STINS.PT := 100;
IF Timer_TOT_STINS.Q = TRUE THEN
	FOR i := 0 TO 11 DO
		DO_V[i] := FALSE;
		Timers_v[i].IN := FALSE;
	END_FOR;
	Timer_TOT.IN := FALSE;
	Timer_TOT_STINS.IN := FALSE;
END_IF;
Timer_TOT_STINS();

END_PROGRAM

PROGRAM _EXIT
(* Insert code here *)

END_PROGRAM

When I inject it on the plc it works as required but only once, then the timers are not reset except for the last one which ends up running by itself in an infinite loop, but I want the whole process to start over.

Hey there - I don’t see a reset condition for the “Timers_v” array of timers. The Timers_v[i].IN are set to TRUE, but not reset afterwards.

IF Timer_TOT_STINS.Q = TRUE THEN
FOR i := 0 TO 11 DO
DO_V[i] := FALSE;
Timers_v[i].IN := FALSE;
END_FOR;
Timer_TOT.IN := FALSE;
Timer_TOT_STINS.IN := FALSE;
END_IF;

I have it here at the end of the code.

I solved the problem with this assignment:
Timers_v[i].IN := TURE I had to replace TRUE with NOT Timer_TOT_STINS.Q;

Thank you!

1 Like