PROGRAM Permissives
(* Surface Pressure Transducer *)
IF Pressure_Transducer_Enabled AND 
	Contactor_Status AND 
	Run_Time > Pressure_Alarm_Startup_Delay THEN

	IF Pressure_In >= Pressure_Hi_SP THEN
		Pressure_Hi := TRUE;
		Pressure_Lo := FALSE;
	ELSIF Pressure_in <= Pressure_Lo_SP THEN
		Pressure_Hi := FALSE;
		Pressure_Lo := TRUE;
	ELSE
		Pressure_Hi := FALSE;
		Pressure_Lo := FALSE;
	END_IF;
	
	IF NOT Pressure_Hi AND NOT Pressure_Lo THEN
		sts_TubingPressureOK := TRUE;
		Pressure_OOT_Scans := 0;
		Pressure_OOT_Seconds := 0;
	ELSE
		Pressure_OOT_Scans := Pressure_OOT_Scans + 1;
		Pressure_OOT_Seconds := Pressure_OOT_Scans * ANY_TO_UDINT(__SYSVA_TCYCURRENT) / 1000;
	END_IF;
	
	IF Pressure_OOT_Seconds > Pressure_Alarm_Delay THEN
		sts_TubingPressureOK := FALSE;
	END_IF;
ELSE 
	sts_TubingPressureOK := TRUE;
END_IF;



(* Start Permissive Status *)
SP_Pressure := (NOT Pressure_Startup_Enabled) OR (DH_IntakePressure > Pressure_Startup);
SP_Temperature := (NOT Temp_Startup_Enabled) OR (DH_IntakeTemperature < Temp_Startup);
SP_Mode := Hand_Mode OR Auto_Mode OR Test_Mode;
SP_Trip := NOT TripStatus;
SP_Voltage := VoltageOK;

(* Pressure should be above the startup pressure setpoint and temperature should be below the startup temp setpoint to begin*)
Start_Permissive := (SP_Pressure AND SP_Temperature AND SP_Mode AND SP_Trip AND SP_Voltage);



(* Run Permissive Status *)
RP_Pressure := (NOT Pressure_Shutdown_Enabled) OR (DH_IntakePressure > Pressure_Shutdown);
RP_Temperature := (NOT Temp_Shutdown_Enabled) OR (DH_IntakeTemperature < Temp_Shutdown);
RP_Mode := Hand_Mode OR Auto_Mode OR Test_Mode;
RP_Trip := NOT TripStatus;
RP_TubingPressure := sts_TubingPressureOK;

(* Pressure should be be above the shutdown pressure and temperature should be below shutdown temp setpoint to continue to run *)
Run_Permissive := (RP_Pressure AND RP_Temperature AND RP_Mode AND RP_Trip AND RP_TubingPressure);
END_PROGRAM