LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Do Events while timer runs. Possible?

I am logging an analog voltage every 10 seconds - the ADC is read, the voltage is written to the screen, and the data is logged to a file with a timestamp.
Now let's say a user wants to open a valve during that 10 second period, while the timer, Wait (ms), is burning up the 10 seconds, the user's button input is ignored. After the 10 seconds is up, the button is seen, the digital output fires, valve opens, and the timer goes back to burning another 10 seconds. Forgive my longwinded explanation - but how do I get the interface to work while the timer is running??
I have 7.1, but have been using 6.02 for a few years and I'm not familiar with some things in 7.1 that may help.
Any help?
Richard






0 Kudos
Message 1 of 12
(3,709 Views)
You have to pay attention to both things in your loop.
Try this: ("Now" = the Millisecond timer function)
Use a shoft reg. for the TARGET value.

Interval = 10000 ( mSec)
Target = Now + Interval (Set the target time)
repeat (while loop)
if Now >= target
Read ADC
Display
Write to file
Target = Target + Interval
end if
If VALVE Button Clicked
Do button stuff
end if
Wait 100 mSec (or something to avoid hogging the CPU)
until Done Button

In other words, you are polling the timer, just as you would poll a button.

You can initialize the TARGET shift reg with NOW (if you want a sample immediately), or NOW + INTERVAL if you want to delay the first sample).
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 12
(3,711 Views)
You could use the event structure. Wire a numerical 10 into the timer icon on the Timeout event. Inside this event, put your code to read the analog signal and process it. Every 10 seconds, this event will run the code inside of it. Then create a new event for mouse click on the Valve button. This event will be executed whenever the button is clicked (mouse up or mouse down, whichever you choose), even though the timer is still in the middle of the 10 second count. However, if the timer event is in the middle of its execution, the button event will not execute until the timer event is complete. Also, if the button was clicked just before the end of the 10 second interval, the timer event will not execute until the button event is complete. Look up
event structure examples. I prefer using the event structure in cases like this because they are so much easier to code and maintain once you get familiar with the idea.
- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 12
(3,710 Views)
You need to do the two operations in separate parallel while loops.
One while loop contains the event structure and reacts to user input. The other while loop does the background operations.
0 Kudos
Message 4 of 12
(3,710 Views)
Hmmm. The number "10" in the TIMEOUT input means 10 mSec, not 10 Sec.

Even if you use 10000 mSec, you have a problem - the 10 seconds STARTS OVER when the VALVE button is clicked.

Suppose the structure starts at T = 0.
At T = 5, the VALVE button is clicked.
The structure does the valve stuff, then loops.
You start a NEW 10-second period at that time.

The next ADC won't happen until T = 15.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 12
(3,710 Views)
My mistake on the timer value. It is in milliseconds. I was not aware that the timer started over again when other events were executed. Good thing to know for the future. Thanx.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 12
(3,710 Views)
You might try reducing the Wait time to whatever the minimum
resolution you desire (say 100 msec). Then when that delay finishes,
kep count of how many of them have finished and only execute your adc
code if the total delay time is 10 sec. You can also check the valve
button upon each 100 msec end-of-delay.

In my experience, event structures finish their code before executing
other events that may have been fired from within that event even
though they do detect that a button etc has been pressed within the
running event. This is in contrast to say Delphi where events can be
interrupted and another event executed.
0 Kudos
Message 7 of 12
(3,710 Views)
In my experience, event structures finish their code before executing
other events that may have been fired from within that event even
though they do detect that a button etc has been pressed within the
running event. "

Of course they do - they have to. Otherwise, some variable passing OUT of the event structure would not know which value to pass - the value from the first event case, or the value from the interrupting event?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 8 of 12
(3,710 Views)
Thanks Steve, and all who have responded. Your solution is the way I'd do it in firmware, and sounds like the logical solution here. I've found you just can NOT interrupt the clock. Parallel loops was promising (thanks for the idea) but the ADC acts flaky, even after making all the sub-vi's reentrant.
Other than Steve's idea, the only other way I think will work is to use two dedicated boards on two serial ports.
Richard






0 Kudos
Message 9 of 12
(3,710 Views)
Parallel loops is actually more robust, if you get to extreme cases, where the VALVE operation takes a significant amount of time (more than your 100 mSec resolution), and where ADC timing accuracy is important (where a 100-mec uncertainty would be detrimental).

If that's not the case, the original scheme I presented should do the trick - I've used it for similar things for years.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 12
(3,710 Views)