BH2114

Delayed evaluation in order to fire alarm

Recommended Posts

I have an oil pump that takes 3 seconds to develop pressure. I need to mask the oil pressure = 0 for 5 seconds after the oil pump is powered on, then evaluate. I have this in a function, which works, except that the 5 second delay hangs the display.

return=0 alarm normal

return=1 Fires Alarm

 

	private a = main_lubepumpmon[0] //  1 indicates that the pump is powered on.
private b = main_Oil_press[0] // 1  indicates that oil pressure is up.
   
if(b==1)
    
  private c = 2
	else
  private c = 0
  
endif   
  
 private d = c+a
 
 delay(5)
 
 switch
    
    case (d==1)
    return 1
  endcase
   
   switch
      case (d==3)
      return 0
   endcase  
    
    
    switch
       case (d==2)
       return 0
   endcase
      
   switch
       case (d==0)
       return 0
   endcase
	

Obviously, I'm doing something wrong here.

Share this post


Link to post
Share on other sites

Are you calling this function from an Alarm Fire expression?  If so, then yes, it will likely hang things.  Alarm expressions are typically evaluated as channel data comes in.  So, a delay in an alarm evaluation will cause a delay in channel processing, and a delay in channel processing can lead back to lags in the user interface.  And by channel processing I mean Channel Events, Alarms, and Logging sets (which would be pretty hard to delay as the actual logging is done in a separate thread).  

You could turn off the alarm processing that occurs with channel processing and instead trigger alarm processing from a sequence.  This is a good idea in general if you have a lot of alarms.  But, its not really going to achieve what you want.  It will just cause your alarm processing to slow by 5 seconds.    

These sort of things are much better dealt with using subsetting by time and time markers.  So, use an event on the pump that looks for the the transition from off to on and when that occurs, set a global flag with the time.  Something like:

if (pumpStat[0] && !pumpStat[1])
   pumpTurnOnTime = pumpStat.time[0]
endif

where pumpTurnOnTime is a global you declared elsewhere.

Then, when evaluating the alarm, you can just look and see if the pump is on, and if it is more than 5 seconds after the turn on time.  So, if you want to alarm if OilPressure == 0, but only if the pump is on and has been on for more than 5 seconds, the Alarm expression would just be:

(OilPressure[0] == 0) && (pumpStat[0]) && (systime() - pumpTurnOnTime > 5)

and the reset expression would be the inverse:

(OilPressure[0] == 1) || (!pumpStat[0]) || (systime() - pumpTurnOnTime <= 5)

Note of course I could just put !OilPressure[0] and OilPressure[0] if these are boolean, but I wasn't sure if it was a flag for oil pressure, or an actual pressure reading.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now