LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop running continuously as well as with number of iterations.

Hi Everyone,

I want to run while loop with number of iteration its working fine in attached vi. now i want to modify the vi such as if iterations 1 or more iterations are give then it should run with given number of iterations  and number of iteration is zero then it should run continuously.. how can i modify it??

 

 

thank you in advance

0 Kudos
Message 1 of 10
(1,299 Views)

Hi new,

 


@newmemeber123 wrote:

if iterations 1 or more iterations are give then it should run with given number of iterations  and number of iteration is zero then it should run continuously.. how can i modify it??


Why is desired iterations an orange DBL?

 

You seem to have problems to transcript your requirements into (pseudo)code:

STOP := (i >= desired_iteration) AND NOT (desired_iteration == 0)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(1,292 Views)

Here is a code that does what you want, but the specification is weird because there should never be an infinite loop waiting for a user input with no delay, it saturates the processor.

I added a 10ms delay in case we are in an infinite loop. Here when the input is 0, the "equal" function always returns false, so the only way of stopping the loop is through the stop button.

While Loop.png

Message 3 of 10
(1,267 Views)

How about this?

 

loops1.png

========================
=== Engineer Ambiguously ===
========================
Message 4 of 10
(1,261 Views)

(Yes, as has been said, your loops needs a wait, your desired iteration needs to be an integer, and never hide the label of terminals)

 

You need much tighter specifications:

 

  • Are the desired iterations always in the valid range of I32? What if the users wants 5000000000 iterations??? (You would need your own counter, because the iteration terminal no longer increments after around 2^21 iterations.
  • What should happen if the user enters a negative number?
  • What should happen if the user changes the number of desired iteration during the run, e.g. set it to 20 when 30 iterations already happened?
  • What is the purpose of all this? What happens after the loop stops?

 

0 Kudos
Message 5 of 10
(1,203 Views)

1, User will not give more than 500 iterations

2, No negative number  will be given 

3, it should work while running... i added pause and play code in it now.. if i pause running loop and give the iteration it should work only for given iterations it should not run continuously or for previous iteration.

3, im measuring voltage from sensors so it should measure continuously or the code should  stop or for given iterations.

 

im attaching the modified vi as per yours suggestions.. its working for continuously or given number of iterations but its not working if i pause running loop and give iterations and rerun it again.

 

ow can i modify the code?

 

thank you for the inputs 

0 Kudos
Message 6 of 10
(1,168 Views)
  • Never ever attach a new VI with the same name as you posted earlier. Never ever!!!!
  • Your code is misguided. a toplevel while loop should never end unless you are done measuring for the day. Edit mode is for editing, not to simulate an idle state. All you probably need is a simple state machine. If the measurement should stop, all you need is go to back to an idle state.
  • You can keep the desired iteration in a shift register and do whatever you want with it, e.g. reset to zero under some conditions.
0 Kudos
Message 7 of 10
(1,127 Views)

See if this can give you some ideas ....

 

First, try to understand every bit of it, then modify as needed.

Might need a few tweaks, nothing a +1 or -1 in the right place cannot fix. 😄

 

altenbach_0-1664986155640.png

 

0 Kudos
Message 8 of 10
(1,114 Views)

thanks, altenbach,

Thank you for such and great example. this is working fine but initially it's on pause pause state(case)

.. i need it initially at play state (running state) the after pressing button it should be pause satate.. i tried to change a code such as making condition false and changing it i or making decrement but im not getting idea how can do it?

 

thank you

0 Kudos
Message 9 of 10
(1,068 Views)

You can switch the control to true, select it, and do a menu...edit...make selected values default. Now it will be true when you open the VI.

However, In a more typical program designed for the end users, it makes more sense for a VI to open in the idle state. One it is a built application, it will run when opened anyway, so FALSE is a better default, giving you time to set up the instrument.

0 Kudos
Message 10 of 10
(1,046 Views)