FOR #index := 0 TO 9 DO
// Increase working time count if the pump is active
IF #PumpActiveSignal[#index] = true THEN
IF #M_Clockbit1s = true THEN // memory clock that switches on every second
IF #LoopOnce[#index] = false THEN // execute this on a positive edge of the memoryclockbit
#WorkingTimes[#index]."Time" := #WorkingTimes[#index]."Time" + 1; // increase the working time
#LoopOnce[#index] := true;
END_IF;
ELSE
#LoopOnce[#index] := false;
END_IF;
END_IF;
END_FOR;
// move working times to list that needs to be ordered
FOR #k := 0 TO 9 DO
#OrdenedList[#k] := #WorkingTimes[#k]."Time";
END_FOR;
// Order working times, lowest to highest
FOR #i := 0 TO 9 DO
FOR #j := #i + 1 TO 9 DO
IF #OrdenedList[#i] > #OrdenedList[#j] THEN
#temp1 := #OrdenedList[#i];
#OrdenedList[#i] := #OrdenedList[#j];
#OrdenedList[#j] := #temp1;
END_IF;
END_FOR;
END_FOR;
IF #CHNGOVER = 1 THEN
// assign priority number according to working times
FOR #l := 0 TO 9 DO
#WorkingTimes[#l].PriorityNo := -1;
END_FOR;
FOR #m := 0 TO 9 DO
FOR #l := 0 TO 9 DO
IF #OrdenedList[#m] = #WorkingTimes[#l]."Time" AND #WorkingTimes[#l].PriorityNo = -1 THEN
#WorkingTimes[#l].PriorityNo := #m;
EXIT;
END_IF;
END_FOR;
END_FOR;
END_IF;
///with this logic I tried to make the logic in tia portal for a project. Following are the requirement in the logic: ** Change over based on the less running hours. ** after a time cycle of 2 hrs. there will be a change over which will make the less run hour motor to start first. ** and also i want to add the trip status in the logic , so that due to above logic trip motor should not come into running logic.