LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to make while loop stop when i set while loop at a fixed time.

Solved!
Go to solution

i don't know how to make while loop stop at a fixed time. Usually. while loop stops when we enter stop button or mistakes have been made. now i wanna while loop stop at a fixed time, 20ms,40ms,and so on. how can i realise that. thank u!

0 Kudos
Message 1 of 5
(3,065 Views)
Solution
Accepted by topic author tangliang

Use the Tick Count function. Get the current tick count when you start the loop.  Add your time (20 ms) to the start value creating a "stop time." On each iteration read Tick Count again and compare the current value to the "stop time" value.  If greater, then stop, otherwise continue.

 

Note that on a desktop operating system you will see some jitter when trying to use loop times as small as 20 ms.  You may need to go to a real time system or something hardware timed to get any precision or stability at those time scales.

 

Lynn

0 Kudos
Message 2 of 5
(3,064 Views)

wire the stop with a true constant, this will execute the loop once and wire a cntrl to the wait (ms)

wait.png

maybe this is not what you want, not realizing you may want code to continuosly run for a certain time allocated...

0 Kudos
Message 3 of 5
(3,056 Views)

thank u so much!

0 Kudos
Message 4 of 5
(3,027 Views)

thank u!

0 Kudos
Message 5 of 5
(3,025 Views)