showing a countdown for a delay


Recommended Posts

What I want to do is, I have a delay of lets say 30minutes. What I want is to have a coundown timer that shows how much time during that delay cycle is left.

So I have

While (1)

Pump1 on


Pump1 off



And I want to know where in that delay for 30 minutes i am at before the pump comes back on

Link to comment
Share on other sites

You just need to record the start time. Good programming practice would remove the magic number (30 minutes) as well:

global loopTime = 30
global startTime
startTime = systime()
pump = 1
delay(x) // ???
pump = 0
delay(loopTIme * 60)


Then to display how far into the loop, use a display value component with an expression of:

(systime() - starttime) / 60

and how much time is left:

looptime - (systime() - starttime) / 60

Link to comment
Share on other sites

So this is what I have my code written as.

global R5off = 1
global R5on = 1
global starttime
while(1) // this is a loop function
starttime = systime()
RAS_R5 = 1 // turns RAS pump for R5 off
delay(R5off*60) // this is the time interval that the pump will be off for. It is R5off times 60 because we work with minute frequencys and not seconds
RAS_R5 = 0 // command function to turn ras pump for R5 on
delay(R5on+2) // peroid of time the pump will be on for. Plus 2 is in there do to the 2 second delay from on to pump actually coming on
endwhile // ends the loop sequence and just repeats lines 2-6[/CODE]

I am able to have it come on and off at the set times which is perfect. However, when I try and write the expression R5off - (systime() - starttime)/60 in to a variable value component it doesn't work. What might I be missing.

Link to comment
Share on other sites

What doesn't work? Does it display the wrong value, or nothing at all? Also, remember all time in DF is seconds, so if you want R5On/Off in minutes, you have to remember to multiply by 60 in your second delay statement (you got right in the first one).

Link to comment
Share on other sites

Yeah nothing at all, when I am entering in the expression it is read background instead of the green background where the actual expression goes. When I put everything in as I have discribed, I hit enter and I get the red x that is pressent when the value expression is first created as a defualt

And yeah the delay time is in minutes and the pump time is in seconds so I should be good there.

Link to comment
Share on other sites

I saved the program closed DAQFactory and open it up new and it is working now. I my guess is I missed apply &compile somewhere in there but it is working great now. Thank you very much for your help.

Link to comment
Share on other sites

  • 5 years later...

To continue this discussion:


I require a cycle timer initiated by a button, with the delay set through (Timer1[0])

So, I have a sequence as follows:


global StartTime

while (1)
   startTime = systime()
   delay (1)

This works just fine, but...using a display device with expression:

(systime() - starttime)

The display starts counting from zero up when the timing sequence starts, but when the sequence stops because of the break, the display just keeps on counting. 

I need to figure out how to stop the display count when the sequence stops.

Link to comment
Share on other sites

First, you don't want:

channel.Timer_output[0] = 1

you can just do:

Timer_output = 1

The channel. prefix is only needed for channel list specific commands, or if you happen to name a global variable the same as a channel.  The [0] is assumed in assignment with a channel because you can only change the most recent data point on an actual output.

As for your question, the sequence you have won't count from zero up from the start of the sequence.  Instead it will count from 0 up for each iteration of the while loop.  To make it stop if the sequence stops, just replace the expression with:

iif(sequence.mySeq.running, systime() - starttime, "No running")

or something like that.  You can also use the visible expression of the component to just make it disappear when not running.  There are a lot of ways to do it.



Link to comment
Share on other sites


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