Timer Control


Jeyjey

Recommended Posts

So I have 3 digital outputs set on DF linked to Labjack (Pump, Solenoid 1 and Solenoid 2)

Initially the pump is activated with a button on the DF page. If solenoid 1 and 2 are not active for a minute (just an example), I want to be able to turn off the pump with a timer (1 minute). If either of the solenoids turn on while the pump is off, I would like the pump to turn on again. Do you have a solution to this scenario?

Any assistance is appreciated.

See below the section of my rough script:

if ((Up[0] == 0) && (Down[0] == 0))     //if solenoid is OFF for more than a minute, turn off pump
         

         starttime = systime()
         
tim = systime() - starttime                                              

         if (tim >= 60)                             //1800 seconds = 30mins * 60sec

                                                            //60 seconds = 1min x 60sec
           
APump = 0                            //turn OFF pump command    
         
        endif

 
      else


         tim = 0
         
starttime = 0
         
APump = 1
         
      endif

endif

 

 

Link to comment
Share on other sites

There are a number of ways to do this depending on the details of your desired logic.  Probably the most reliable is to have a global variable that indicates the desired pump state (on/off), then have a sequence that monitors this and the solenoids and acts accordingly.  The button would change the global, not the pump directly.  Here's the code, assuming you have created and initialized a variable called "APumpHOA" and your digital channels are Up, Down and APump.  I'm going to make APumpHOA a Hand, Off, Auto switch.  You can just use the off and Auto for off and on if you don't want a Hand state (force on).  APumpHOA = 0 is off, 1 is hand (force on) and 2 is auto.  This sequence should always be running:

private autoOffStartTime = 0
while(1)
   switch
      case(APumpHOA == 0) // off
         APump = 0
      case (APumpHOA == 1) // hand (force on)
         APump = 1
      case (APumpHOA == 2) // auto
         if (autoOffStartTime == 0)  // not in "off" mode
            if ((sum(Up[systime(),systime()-60]) == 0) && (sum(Down[systime(),systime()-60]) == 0))  
               // both pumps off for the last minute
               autoOffStartTime = systime()
               aPump = 0
            else
               aPump = 1
            endif
         else
            if (Up[0] || Down[0]) // one of the solenoids came on, so reset
               autoOffStartTime = 0
               aPump = 1
            else
               aPump = (systime() - autoOffStartTime > 60)
            endif
         endif
   endcase
   delay(0.1)
endwhile
                  

That should be about it, though of course I can't test.  Note that after 60 seconds, the pump will start back up, and stay running even if both solenoids remain off.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.