Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
1
Indexable
Never
PROGRAM PLC_PRG
VAR
  ValveState: INT := 0;
  OpenValve: BOOL;
  CloseValve: BOOL;
  Open: BOOL;
  IsOpen: BOOL;
  IsClosed: BOOL;
  Close: BOOL;
  ErrorMode: BOOL;
  IdleMode: BOOL;
  Timer_Tp: TP;
  ElapsedTime: TIME;
  ErrorLightOutput: BOOL;

END_VAR



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
    IF NOT(IsClosed) THEN
    ValveState := 2;
    END_IF;

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

  3:
    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;
    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