LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

(Hopefully) Easy problem with time delay

Solved!
Go to solution

Hey Folks,

 

I am a labview neophyte, and have a program (see attached) that I am using to flash one of three signs on the screen after a pressure switch is released. There is a time delay feature between the pressure switch (run through a DAQ) and the flashing of the sign on the screen; however, when I use a value other than zero for the delay, the DAQ appears to trigger after a variable amount of time after the pressure switch is released, and THEN the time delay occurs. If I use no delay, the DAQ reliably triggers immediately after the pressure switch is released (and hence the sign flashes immediately as well).

 

I can't figure out why the DAQ does not trigger immediately in all cases regardless of the value of the time delay. The only thing I can think of that might be affecting this is that the computer I am running this through is dated (2Ghz P4 with 512MB RAM) but it is not like this is a complicated program... please help! Thanks!

 

 

0 Kudos
Message 1 of 7
(3,443 Views)

A few comments first. Don't use stacked sequence structures! Use flat ones if you must use on at all (you rarely need them). Use error in and outs to enforce your data flow. Trust me I made that same mistake years ago and when you need to go back to your code the stacked structures make it hard to understand.

 Avoid local variables. As soon as your code enters the second portion of your sequence structure the lower Trig Val local probably gets read before it is set by the DAQmx read. Probably?? Since there is no data flow who knows.

 

Finally look at the code located on the bottom of this page. If your DAQ supports change detection just change the DAQmx read to Digital>Single Channel>Single Sample>Boolean (1line). When the data goes true randomly change the tab. Use the error out of the DAQmx read to feed into the Wait.vi and its error out goes into the true/false case structure.

 

You could also use a counter in the same manner if you have one available.

 

Hope this helps.

 

 

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 2 of 7
(3,433 Views)
Thank you for a comprehensive answer, but as I mentioned, I am a complete Labview neophyte; I undertand enough to follow the gist of the code and make very minor changes, but I got nothing you just went through (I am borrowing the code which was used for an old project and the author is no long around). Is there a more direct, simple answer that I might use to resolve this?
0 Kudos
Message 3 of 7
(3,430 Views)

Ok which DAQ device do you have?

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 4 of 7
(3,423 Views)

oops got called away when I tried to edit.

Some pointers that help me:

Use the Ctrl H key combination to bring up the help window. When you code it really helps.

Don't use the run continous button. It's only for special circumstances. Use a while loop with a stop button instead to test code. Also use the the light bulb icon on the top bar. This helps you understand the data flow.

Use the example finder. Help>>find examples. There is usually an example you can use to start with.

The page I linked earlier is part of a series of tutorials which are a great resource. Here is a primer.

Look up the term "State Machine". Find the simplest example you can and run it with the light bulb on. It's a powerful technique. Eventually you'll need to learn about producer consumer design patterns. Really useful with DAQ to seperate acquisition from data display or calculations.

 

Let me know what DAQ device and LabVIEW version you have and I might get a chance to write something to get you a better start.

 

 

 

 

 

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 5 of 7
(3,418 Views)
Solution
Accepted by topic author dcherman

R-click the stacked sequence and "replace with flat sequence". R-click the flat sequence and "Remove sequence". 

You have a race condition between Trig val and the local of it. Wire it directly to the loop to make sure it's this runs trig val you're using and not the previous runs.

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 7
(3,402 Views)

I use Labview 2010 and the DAQ is an NI USB 6008... thanks!

0 Kudos
Message 7 of 7
(3,377 Views)