LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my calculation in a while loop repeat only once?

Solved!
Go to solution

I have a series of simple calculations (multiply, divide, add, subtract) occuring in a while loop based on data input on the front panel by the user. The results are then connected to local variables which change the settings of a signal generator in a seperate while loop.

 

The while loop containing the calculations only repeats one iteration unless I turn on the 'Highlight Execution' button on in which case it repeats until the loop is stopped as I would expect. With the 'Highlight Execution' button off and using a probe to check instead the loop does not repeat.

 

The other while loop with the signal generator does repeat, but only uses the values that were entered before the VI started running.

 

I need the VI to recalculate every time a value on the front panel is changed and change the output from the signal generator accordingly.

 

What am I missing?

 

 

0 Kudos
Message 1 of 9
(3,661 Views)

It is easier to troubleshoot if you post the VI giving you trouble.

 

Several possibilities.

1.  You are using local variables in ways you shouldn't and are getting race conditions.

2.  You don't understand the way data flows and have some interdependency between your loops.  Also, where you are reading your controls only happens outside of your while loops and only get read once the program starts.

3.  If you want to to something where you act when a user changes a front panel control, you should probably be using an event structure.

Message 2 of 9
(3,655 Views)
0 Kudos
Message 3 of 9
(3,649 Views)
You need a "wait" or "wait until next ms" in the other 2 while loops
Rodrigo Cuenca
www.cidesi.com

0 Kudos
Message 4 of 9
(3,627 Views)
Tried that, still no change.
0 Kudos
Message 5 of 9
(3,614 Views)
I found that replacing the local variables (they were acting to combine the stop command between all three loops) with stop buttons allowed the loops to continuously run, but i would still like to combine the stop commands between all three loops. How do i accomplish that without causing the problem i was experiencing before?
0 Kudos
Message 6 of 9
(3,608 Views)
How you know that is running only once? create an indicator and check the number of iterations. In my PC runs fine.
Rodrigo Cuenca
www.cidesi.com

0 Kudos
Message 7 of 9
(3,603 Views)
Solution
Accepted by MetzT16

Because the local variables are attached to the LEDs that are in the on position after ending the VI it runs correctly the first time and only runs one iteration before stopping the while loops containing the  calculations if you run the VI more than once. As long as the LEDs are in the off position when the VI is started then everything works fine.

 

Thanks for the hints everybody.

0 Kudos
Message 8 of 9
(3,592 Views)

Why do you have three separate loops running in parallel with local variables used to pass values to the bottom loop?  Just put everything in one loop and eliminate the local variables.  See attached vi.  works great.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 9
(3,579 Views)