LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Start and stop parallel while loop

Solved!
Go to solution
Highlighted

I have 2 while loops running. When the Boolean <Optimum Vacuum> goes true, the while loop below starts counting up a soak time.

There are conditions where <Optimum Vacuum> in the top while loop goes false. At that point, I want the lower while loop to go false and stop adding up the soak time.

 

The <Optimum Vacuum> variable in the bottom while loop never changes state from true to false, as it changes state in the top while loop.

How can I make that variable change state as needed?

 

Thank you

 

parallel while loop.jpg

0 Kudos
Message 1 of 11
(247 Views)

Because you are stuck in that inner while loop down below until the time finishes.  (PS, it makes more sense to use >= 420 and get rid of the NOT instead of <420 and have to use the NOT)

 

You have difficult code here where local variables are being abused and you are locked into program logic you can't get out of.  First, does this need to be two loops?

 

Your code should be a large state machine where you have start and stop states, and idle and check timer states to determine when to turn stuff on or off.  Google NI.com for "state machine".

Message 2 of 11
(226 Views)

I originally had it in a single loop, but once the seconds started counting, the original value stayed at the trigger point of 27.5.  The vacuum was still increasing but all I could see is the soak time increasing.

As far as the state machine, I'm not too familiar with it.

Would you be able to show me with some sample code for either situations?

 

Thank you.

0 Kudos
Message 3 of 11
(202 Views)

Then attach that VI so we can look at it and see where the issues are.

 

I can't show some sample code.  I'm getting paid to create code needed for my own company's needs.  I'm not getting paid to program other people's code.

0 Kudos
Message 4 of 11
(192 Views)

I’m not asking you to write all my software. Just asking for a small amount of assistance. But since you are so busy, maybe you should concentrate more on writing your company’s code than trying to help out beginners here in the support forums. 

Because you aren’t any help. 

Thanks. 

0 Kudos
Message 5 of 11
(186 Views)

Then spend time more time reading and googling and don't bother asking questions on the forum because with an attitude like that you won't get any help.

0 Kudos
Message 6 of 11
(185 Views)

When you attach code (rather than a picture), we can (a) see what version of LabVIEW you are using (so we can comment appropriately) and (b) can more easily see what you have done and provide "hints" (so you can learn by fixing your own code).

 

Absent that, do the following:

  1. Start LabVIEW.
  2. Click "Create Project".
  3. In the right-hand pane, click "Simple State Machine" (and "Next").
  4. Study the example.  Read the Documentation.  Learn.

I don't know how this "maps" into your issue, as I don't have your code to examine.

 

Bob Schor

 

 

Message 7 of 11
(182 Views)

Thank you for your help Bob. I didn’t realize how to properly post so that I can get the best help possible. I’ll remember that for the next time I need assistance. Again thank you very much. 

0 Kudos
Message 8 of 11
(178 Views)

@Big_Guy wrote:

Thank you for your help Bob. I didn’t realize how to properly post so that I can get the best help possible. I’ll remember that for the next time I need assistance. Again thank you very much. 


If you really want to blend in, you also press that kudo button to say thanks!

 

Only on Bob's post I assume, although the others did honestly try to help.

 

Accepting a solution (if you do feel it's solved) helps keep the forum tight. Then you won't get guys like myself opening this thread to find it's actually finished (and then writing OT advice). RavensFan did mention that solution in the first post, but it's OK if you'd mark Bob's reply (or both).

Message 9 of 11
(155 Views)
Solution
Accepted by topic author Big_Guy
04-17-2019 12:59 PM

@Big_Guy wrote:

 

How can I make that variable change state as needed?


It is not the variable change, but giving the code a chance to read the new value, which is currently deadlocked. It seems your problem is solved, so here are a few more tips:

 

  • Try to make the code less ambiguous and label the button either "Start" or "Stop". Naming it "Start Stop" and having some loops "stop if true" and some "continue if true" can raise a lot of confusion. If you want it as "Start Stop" on the front panel, use the caption (or boolean text) instead.
  • Your innermost loop spins millions of times per second, consuming 100% of a CPU core, draining your battery, heating your office, and starving all other processes running on the computer. I am sure there is a reasonable upper speed limit, so place a small wait. Hard to tell more about the other loops, because most of the code is hidden in other cases or truncated.
  • Not sure why there is a toplevel case structure. That's typically an architectural issue (Are you using "run continously"?). A typical well written state machine has a while loop as toplevel structure.
  • If you would use "high resolution relative seconds" instead of "tick count", you would not need to divide by 1000 and there is no need for blue wires.
  • etc.

LabVIEW Champion Do more with less code and in less time
Message 10 of 11
(140 Views)