I am trying to set up Chart(s)/Devices that rely on an ‘enable’ to be present to run. In this case, as long as the compressor is enabled by the user or a safety circuit is happy.
I found this on the forums, but am not sure if it relates to me:
I want to check if the compressor is enabled and run until the temp is <= AirTemp_Lower. Stop compressor is enable is dropped.
Currently I have this is my code in an OptoScript Block,
while (IsVariableTrue (Compressor_Enabled))
while (ReturnAir_Temp > AirTemp_Lower)
//refrigerate
TurnOff(Green_LED);
TurnOn(Blue_LED);
DelayMsec(DelayMedium);
wend
wend
TurnOff(Blue_LED);
TurnOn(Green_LED);
It seems to work when I set the value of the variable (Compressor_Enable) before entering the Debug, but not when I change it in Debug from -1 to 0
Am I going about this all wrong? Thanks for any help/pointers in advance
When you set Compressor_Enable to false but the air temperature is still above the lower threshold, the runtime never leaves the inner loop. Both conditions need to be false for the code to end. You could try using “and” between both conditions in just one while loop so that it stops running when either condition becomes false?
And just a little tip, when you share code you can highlight everything and hit the </> button to add triple ticks ``` at the start and end to format it like this:
while (IsVariableTrue (Compressor_Enabled))
while (ReturnAir_Temp > AirTemp_Lower)
//refrigerate
TurnOff(Green_LED);
TurnOn(Blue_LED);
DelayMsec(DelayMedium);
wend
wend
TurnOff(Blue_LED);
TurnOn(Green_LED);
If this logic is going to be used in production some day, then consider that ReturnAir_Temp will be a noisy analog signal that may cause your condition statement to alternate between true and false rapidly. Since compressors tend to make a fuss about starting against high head pressure, appropriate cycling delays should be provided.
Philip, I plan to add an anti-recycle timer in there for that reason, as well as time to let the motor windings cool if not on a VFD. I also have air temp setpoint differentials in place to allow some more off cycle. That is where the ‘lower’ comes into play for off cycling the compressor.
AirTemp_Setpoint minus AirTemp_Differential equals AirTemp_Lower
As always, your help and suggestions are much appreciated.