04-12-2012 04:55 PM
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!
Solved! Go to Solution.
04-12-2012 07:19 PM
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.
04-12-2012 08:07 PM
04-12-2012 08:45 PM
Ok which DAQ device do you have?
04-12-2012 09:26 PM
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.
04-13-2012 05:31 AM
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
04-15-2012 01:32 PM
I use Labview 2010 and the DAQ is an NI USB 6008... thanks!