Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
Never
CASE ValveState OF
  0: // It's closed
    IF OpenValve THEN
      ValveState := 1; // Checks if the output opens when OpenValve is pressed, if it does then it is closed
    ELSE
      ValveState := 3;
    END_IF; 

  1:
    Open := TRUE; // OpenValve is started because case 0 was true
	Timer_Tp(IN:=TRUE,PT:=T#5S);
    IF NOT(IsClosed) THEN 
    ValveState := 2;
    END_IF;

  2:
    IF IsOpen THEN // opening
      ValveState := 3;
	END_IF;

  3:
  	Timer_Tp(IN:=FALSE,PT:=T#5S);
	ElapsedTime:=Timer_Tp.ET; 
    IF CloseValve THEN // If it's open then the valve should close
      ValveState := 4;
	  Timer_Tp(IN:=TRUE, PT:=T#5S);
    END_IF;

  4:
    Close := TRUE; // CloseValve is started because case 3 was true
	IF NOT(IsOpen) THEN
		 ValveState := 5;
	ElapsedTime := Timer_Tp.ET; 
    END_IF;

  5:
    IF IsClosed THEN
      ValveState := 0;
      Close := FALSE;
    END_IF;

   6: 	IF IdleMode:=TRUE THEN
   		OpenValve:=FALSE;
   		CloseValve:=FALSE;
		END_IF
	   IF ElapsedTime>T#5S THEN
	   IdleMode:=TRUE;
	   END_IF;
	7:
		 IF OpenValve AND CloseValve THEN 
			 ErrorMode:=TRUE;
			 ValveState:=8;
		 END_IF
	8:  ErrorMode:=TRUE;
		 ErrorLightOutput := NOT ErrorLightOutput;
		 
 
END_CASE