LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I stop a while loop with a wait ms timer before it is finished its cycle?

I am using Labview 6.0.2 to make a VI to control a programmable generator. I want to write initial values of Output Voltage/Frequency to the generator (eg 90V/60 Hz), then wait for 4 to 5 hours, then write new values (eg 254 V/50 Hz.) I also want to be able to interupt the wait sequence if changes need to be made or I just want to shut down the output voltage and stop the test. I an using a while loop with a wait ms timer for the timing, but I cant stop it in the middle of the cycle unless I want to wait double the set time! Any suggestions? I read some responses to similiar problems, but the example vi's supplied were in Labview 6.1 which I couldnt open in 6i. Thanks.
0 Kudos
Message 1 of 9
(5,203 Views)
The solution is not use the wait function. Instead, get the start time with either the tcik count or current time in seconds. Then inside the while loop, put the same time function to get the current time. Subtract the start time from the current time to get elapsed and compare that to the time you want to run your test. Terminate the while loop if the elapsed time is greater. To terminate early, or in a stop button with the elapsed time/test time and wire that to the while loop terminator.
Message 2 of 9
(5,202 Views)
you can make two while loops with a smaller timer in inner loop and count
up. Just after inner loop exit check if you want to finish or not.

"Dennis Knutson" wrote in message
news:506500000005000000B1E50000-1042324653000@exchange.ni.com...
> The solution is not use the wait function. Instead, get the start time
> with either the tcik count or current time in seconds. Then inside the
> while loop, put the same time function to get the current time.
> Subtract the start time from the current time to get elapsed and
> compare that to the time you want to run your test. Terminate the
> while loop if the elapsed time is greater. To terminate early, or in a
> stop button with the elapsed time/test time and wire that to the while
> loop terminator.
0 Kudos
Message 3 of 9
(5,202 Views)
Thanks D.K., works much nicer! I attached the basic design, the read write functions will be in the outer loop, timing in the inner loop. One more question, if I put a stop button on each while loop, it works, but then you have one too many buttons! If wire the stop funtions to one stop switch it doesnt work anymore, so I used a local variable on the inner loop associated with the outer loop stop button. Seems to work ok,can you see any problems I might run into with this configuration? Any easier ways to accomplish the same thing? Thanks!

Doug M.
0 Kudos
Message 4 of 9
(5,201 Views)
If you have an outer while loop that you want to stop as well, you can put the stop button inside the loop and besides wiring it to the OR, wire it through the inner while loop to the outer's termination terminal as well.
0 Kudos
Message 5 of 9
(5,202 Views)
Ok, thats much better, no more timing problems! Thanks again...

Doug M.
0 Kudos
Message 6 of 9
(5,202 Views)
My english is bad so i dont explain. I attach one file and I think that is the objective you want.
IF not sorry.
Saw Naing Aye(Maymaythar@yahoo.com)
My VI is written on 6.1 so i do not know you can open it or not but I convert the block diagram to jpg so think you can see.
Download All
0 Kudos
Message 7 of 9
(5,202 Views)
I read your objective and I modified the VI but the idea is still the same.
Download All
0 Kudos
Message 8 of 9
(5,202 Views)
Hi,
This two nested while loop was great to stop the application without waiting till the end. But another problem occured in my application when I ompleted your solution:

I am using an DAQ card to acquire a waveform data using AI Scan function. When I use a wait ms function my AI scan works fine but when I use the substraction of times and their comparison, the AI scan get too slow and give me one data point each 4 second!

Does anybody have a solution?

thnks
0 Kudos
Message 9 of 9
(4,992 Views)