LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a button to stop and run a for loop?

How to make a button to stop and run a for loop?  and if it is stopped it shall start from where i t stopped.
0 Kudos
Message 1 of 9
(3,856 Views)
You could insert a While Loop that waits if Stop is true.
To not waste too much CPU resources, you should also add a Wait to the While loop. The wait should only execute, if Stop is true.
I have never met a good scenerio that required a for loop with this feature?
What scenario do you have in mind?
If it is meant for debugging, I would use conditional probes and/or the Highlight Execution button.
Guenter
0 Kudos
Message 2 of 9
(3,828 Views)

Which version of LabVIEW are you using??

LabVIEW 8.5 has this particular feature for 'For' Loops

http://zone.ni.com/reference/en-XX/help/371361D-01/glang/for_loop/

0 Kudos
Message 3 of 9
(3,803 Views)
You cannot really stop a FOR loop. It is set to run for a predetermined number of iterations. Once you finish it prematurely with the conditional terminal (LabVIEW 8.5 only), you cannot continue the loop where you left of. You would need to use shift registers in an outer while loop to retain the history and restart the loop with the end values of the last run.
 
Of course you could pause it, but also this does not seem very useful. One possibility would be to place an event structure inside the FOR loop and toggle the timeout value (via shift register) between -1 (for pause) and 0 (for looping).
 
SInce all this does not make a lot of sense, could you explain what you have in mind? Maybe there is a better way. 🙂
0 Kudos
Message 4 of 9
(3,800 Views)
hi,
 
THX 4 your replies
 
in the attached file i tried to stop the for loop but only the input "X" stopped and the iterations continued. So, can you help me to stop them both and start them from the number they stopped at.
 
Thx...
0 Kudos
Message 5 of 9
(3,786 Views)

Your VI has some very fundamental flaws.

  1. The start/stop button is outside the FOR loop, thus it will NOT get read during execution of the FOR loop, but only before the FOR loop starts. Think dataflow!
  2. Thus the terminal of the start/stop button belongs inside the FOR loop.
  3. Your FOR loop iterates 20x, which probably takes about a nanosecond. You will NOT be fast enough to reliably press the start/stop button during a specific iteration of the FOR loop.
  4. Your code does not "stop and run" a FOR loop (sic). The loop always spins, but executes an empty case when "Stopped". I guess that's what you actually want?
  5. Once you solve (2), the x indicator will contain a random value whenever you "stop".
  6. As soon as the 20 iterations complete, the outer while loop spin an things start over, another nanosecond later.
  7. Place e.g. a 500ms wait inside the FOR loop to solve this.
  8. Don't place terminals of indicators on top of formula nodes.
  9. Your formula does not produce any output, so really has no purpose.
  10. Use a real "stop" button to terminate the while loop (mechanical action: latch when released). Right now you are using a plain switch, which does not reset to false before the next run. This means that you need to manually reset it before running the program again.

It is oftern useful to operate the VI in execution highlighting mode. You will immediately see that your button does not get read during execution of the FOR loop. Try it!

0 Kudos
Message 6 of 9
(3,714 Views)

Here's a possible solution to pause (not stop!) a loop. See if this helps, maybe... 🙂

Maybe you can go one step back and explain what you are actually trying to achieve. What kind of functionality do you need from an operator point of view?

0 Kudos
Message 7 of 9
(3,708 Views)

THX 4 your help

but i have a question in the file you attached, how to make the iterations to be 20 only in a while loop. Actually i used the for loop because it can determine the n- value (i mean from 0 to N). 

 

Thx...

0 Kudos
Message 8 of 9
(3,691 Views)
Hi,
 
I wasnt able to open the earlier posted example, so I dont know if this is what you want, but if all you want to do is limit the number of iterations in a while loop, use the boolean operators. See the attached JPEG for an example (to only have 20 iterations, you may need to change the constant to 19 since i starts at 0, but that is not difficult to check, the main part is the boolean operators. Hopefully this helps.
Jeff


Using Labview 7 Express
Message 9 of 9
(3,681 Views)