LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loops running simultaneously with data feed

Hey, 

 

 

This is probably a noob problem, but I'm trying to run a while loop with a case structure in it.  The condition for the case file is either a clock runs down (in another while loop) OR a button is pressed.  However, I can only get the clock while loop to run, followed by the case structure while loop, when I want them to run simultaneously.  Also, the idea for the countdown while loop itself I got from another poster and slightly modified.  I've attached a copy of my practice vi. 

0 Kudos
Message 1 of 6
(2,927 Views)

You said it yourself:

 "The condition for the case file is either a clock runs down (in another while loop) OR a button is pressed."


LabVIEW is a dataflow paradigm. Data on the wires determines what happens next. Your second while loop won't run until the first one is finished and feeds the two values (boolean and double) to the second while loop.


What do you want the second loop to do while you're waiting for either the count down or the button press?

 

And you can get rid of the sequence structure. It's not needed. You can drive the last bit of DAQ writes with the error out of your second while loop.

Message 2 of 6
(2,915 Views)

In the real vi, that second while loop is for taking in data from a bunch of sensors and run a centrifuge.  Every so often, the centrifuge needs to be "flushed," and so it needs a loop that's set on a timer that can also be triggered manually should the operators have the urge to flush the centrifuge. 

 

Also, that "error out" bit was a nice tip.  I think I did it in this updated version.

0 Kudos
Message 3 of 6
(2,908 Views)

Ok, now you want to have both loops running in parallel. Take a look at the Notifier operations. You can use them to "notify" your sensor/centrifuge loop when the count down or button press occurs. (Use a small timeout value for the Wait for Notifier so your loop isn't slowed down too much).

 

Also, I would recommend a user event structure to handle the button press/count down (surround it with a while loop). Example:

 

Countdown_BD.png

 

Hopefully that will get you started. (Don't forget error handling that I omitted for brevity)

Message 4 of 6
(2,902 Views)

Thanks a bunch!  Here's my updated version.  The "end blink" notifier uses the "timed out?" to control the loop, while the "end timer" uses the normal "notification" to control that loop.  I've also noticed that with 2 notifier operations, it runs a tiny bit slower than before and that I have trouble placing Release Notifiers, so I didn't include any.

 

 

0 Kudos
Message 5 of 6
(2,853 Views)

Better!

Some other observations after a quick look:

  1. Why do you have two separate DAQ tasks (two lines) that are being programmed identically? Just create a single task using the two lines. And you don't need to keep creating the same DAQ task over and over. Define it once before your loops start and then clear it when the loops end.
  2. Put the DAQ task setup into its own subVI.
  3. You have more complicated code than necessary for your hours, mins, secs calculations and displays. There are much simpler ways to do that.
  4. In the top loop, you don't need the sequence structure. Use the Timed Delay (as you did in the middle loop) except wire the error in/out for dataflow.
  5. You can put the Release Notifier after all your loops exit. What problem are you having with that?
0 Kudos
Message 6 of 6
(2,847 Views)