FUNCTION_BLOCK FB1
VAR_TEMP
// Temporary Variables
END_VAR
VAR
Starts:ARRAY[1..3] OF INT;
iNumberOfStarts:INT:=3; //Size of the array above
iTimePeriodsecs:INT:=3600;
bStartEdgeStore:BOOL;
bStart:BOOL;
bStartNotAllowed:BOOL;
bStartSeen:BOOL;
bOneSecondPulse:BOOL;
iIndex:INT;
iCount:INT;
END_VAR
bOneSecondPulse:=M0.0;
iTimePeriodsecs:=30; //use 30 secs for testing
//rising edge for each start
bStart:= Q0.0 AND NOT bstartEdgeStore;
bStartEdgeStore:=Q0.0;
//loop for all starts finding
IF bstart THEN
bStartSeen:=False;
FOR iIndex:=1 TO iNumberOfStarts DO
IF NOT bStartSeen AND Starts[iIndex]=0 THEN
Starts[iIndex]:=iTimePeriodsecs;
bStartseen:=True;
END_IF;
END_FOR;
END_IF;
//update array of start timers every second decrementing to zero
IF bOneSecondPulse THEN
FOR iIndex:=1 TO iNumberOfStarts DO
IF Starts[iIndex]<>0 THEN
Starts[iIndex]:=Starts[iIndex]-1;
END_IF;
END_FOR;
bOneSecondPulse:=False;
END_IF;
M0.0:=bOnesecondPulse;
//search array of timers for non-zero
//If all starts are non-zero then another start is not allowed
iCount:=0;
bStartNotAllowed:=False;
FOR iIndex:=1 TO iNumberOfStarts DO
IF Starts[iIndex]<>0 THEN
iCount:=iCount+1;
END_IF;
END_FOR;
IF iCount = iNumberOfStarts THEN bStartNotAllowed:=True; END_IF;
//monitor for plcsim
q0.1:=NOT bStartNotAllowed;
//watch code
iIndex:=starts[1];
iIndex:=starts[2];
iIndex:=starts[3];
END_FUNCTION_BLOCK