Sequence/relay Problem


Recommended Posts

Hi there, I'm using the following code in one sequence to control a two way relay (humidifier/dihumidifier)

while(1)   
      if((RH[0] >=(RH_sp+RH_tol)))
         while ( RH[0] >=(RH_sp))
         dehumidifier=1
         delay(1)
         endwhile
  
// Else turn off dehumidifier    
      else 
      dehumidifier=0
      endif
 
// If RH becomes too low turn on humidifier until RH returns to desired value
      if((RH[0] <=(RH_sp-RH_tol)))
         while ( RH[0] <=(RH_sp))
         humidifier=1
         delay(1)
         endwhile
      
// Else trun off humidifier
      else 
      humidifier=0
      endif
endwhile
 
And I'm required to control this sequence on main page. So I created a button to turn this sequence on/off. My question is how can I change the value of humidifier/dihumidfier to 0 when I stop this sequence(by clicking the button)? I can add another button to toggle the value but I would prefer a automatic way for either another sequence or adding a few lines of code.
Thanks for the help in advance. Ryan 
Link to comment
Share on other sites

First, why the internal while() loops?  You should be able to create this logic with only a single outside while loop.

 

As for your inquiry, use a Quick Sequence action instead of the Start/Stop sequence action.  Assuming your sequence is named "mySequence":

 

if (sequence.mysequence.running)

   endseq(mysequence)

   delay(0.5) // give sequence time to stop

   humidifier = 0

   dehumidifier = 0

else

   beginseq(mysequence)

endif

Link to comment
Share on other sites

Agree on the while loops.  I'd also precalculate the error for easy reading and use an average on the RH reading.

while(1)
     private RH_Error = mean(RH[0,9]) – RH_sp
     if (RH_Error > RH_tol)
       dehumidifier = 1
     endif
     if (RH_Error > 0)
       humidifier = 0
     endif
     if (RH_Error < 0)
       dehumidifier = 0
     endif
     if (RH_Error < (-1 * RH_tol))
       humidifier = 1
     endif
     delay(10)
endwhile
Link to comment
Share on other sites

First, why the internal while() loops?  You should be able to create this logic with only a single outside while loop.

 

As for your inquiry, use a Quick Sequence action instead of the Start/Stop sequence action.  Assuming your sequence is named "mySequence":

 

if (sequence.mysequence.running)

   endseq(mysequence)

   delay(0.5) // give sequence time to stop

   humidifier = 0

   dehumidifier = 0

else

   beginseq(mysequence)

endif

This code is coming from a co-worker and I haven't think about the logic yet. And I'm agree on the while.

And thanks for the answer.

Link to comment
Share on other sites

 

Agree on the while loops.  I'd also precalculate the error for easy reading and use an average on the RH reading.

while(1)
     private RH_Error = mean(RH[0,9]) – RH_sp
     if (RH_Error > RH_tol)
       dehumidifier = 1
     endif
     if (RH_Error > 0)
       humidifier = 0
     endif
     if (RH_Error < 0)
       dehumidifier = 0
     endif
     if (RH_Error < (-1 * RH_tol))
       humidifier = 1
     endif
     delay(10)
endwhile

Thanks for the comment. It was trying to control rh in the certain range so instant rh reading might be more useful...

Link to comment
Share on other sites

Depends on whether noise or actual RH change is the more likely cause of an abrupt change in the reading.  You can still safely filter your PV (process value) reading so long as your rolling average can change as fast as the physical value can.  And, if you have a truly volatile measurement, you can still take advantage of filtering by measuring even more rapidly.  Say it's possible for a significant change to occur in one second.  Then I'd still average 5 or 10 readings, but just take 5 or 10 a second.  That way you know you're not responding to measurement noise (unless your instrument output is already filtered to take care of that).

 

Another factor, if your readings are for some reason sporadic, is that you can subset the channel array by time rather than by the last X readings.

Link to comment
Share on other sites

Depends on whether noise or actual RH change is the more likely cause of an abrupt change in the reading.  You can still safely filter your PV (process value) reading so long as your rolling average can change as fast as the physical value can.  And, if you have a truly volatile measurement, you can still take advantage of filtering by measuring even more rapidly.  Say it's possible for a significant change to occur in one second.  Then I'd still average 5 or 10 readings, but just take 5 or 10 a second.  That way you know you're not responding to measurement noise (unless your instrument output is already filtered to take care of that).

 

Another factor, if your readings are for some reason sporadic, is that you can subset the channel array by time rather than by the last X readings.

Hi I tried your code and it triggers the sequence when the instant RH=36.1% which saying the sensor feed is not noisy. But I think your idea is better since it could prevent the sequence turning on by a spike or sth. Thanks a lot.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.