LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to immediately stop a timed loop in between period/loops

Hi,

 

need some help!

 

How do i stop the timed loop?

Ex: when the period is 10 seconds and program is running and when the stop is pressed it is waiting until the next iteration occurs which is 10 secs here

how do i stop the loop immediately when pressed stop

I am using this  as a sub-vi in a larger program and this timed loop vi has data writing out to DAQ hardware which i dont want to happen when stop is pressed.

any ideas? this is probably simpler than im guessing

 

Thanks

0 Kudos
Message 1 of 7
(8,395 Views)

You can't.  All code in a loop must finish.

 

The best thing to do would would be make the loop run faster such as once per second but only execute the loop on every 10th iteration.

 

There is one other possibility.  You can use the Stop Timed Structure function in the Timed Structures palette.  If you monitor the Stop button in a separate while loop and feed the name of your first while loop to this function, you can immediately stop the timed loop.

Message 2 of 7
(8,393 Views)

hi freemason,

 

I dont have labview 8.6. Can u post vi which is saved in 8.5? or post image.

If i have understood your problem, then ur using this vi as timer in your larger program as a subvi. What you can always do is instead of having 10 seconds delay, you can have 1 seconds delay and counter as 10. After each second check Stop buttons status and increment counter. You can even use state machine for this.

 

I hope this will help you.See example i have attached for reference.

 

Best of luck

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 3 of 7
(8,380 Views)

Plz see attached for the problem LV 8.0 version

i used stop timed loop structure.vi it works fine within the program. when i use it as subvi in a state machine and want to stop in that state. it doesnot stop. plz let me know of any modifications you suggest. 

 

Actually I need a subVI to calculate values every 10 seconds for a duration of 1 hr and put all the values out in this present state during this
entire period so that i can send them to next state for some calculations on the obtained data.

plz help if there is an alternate way to using timed loop or any other way around....

Thanks

Download All
0 Kudos
Message 4 of 7
(8,347 Views)

You have a problem of data flow.

 

First.  The Abort button is read in the Main VI and is False.  The sub VI starts.  Even though you may change the Abort button in the main VI, it does not get read again until the subVI ends allowing the loop iteration in the main VI to end.

 

Second,  I'm not sure why you started using the Wakeup Reason Node.  I didn't use that at all in my example.

 

Third,  as I said in my earlier post, it is better to run loop the more often.  I said the Abort Timed Loop was another possibility.  I did NOT say it was the better possibility.  As a result, trying to restart the subVI with the time loop even after you aborted it is causing an error -804.

 

As I said in that earlier post, the better way to do it is to run the loop more often and read the "Abort" button.  Now that you have buried that into a subVI whose front panel is not opened when run, your Main VI button is not read until the subVI is finished.  You need a way to have the subVI read the button even before it is finished, you can use a control reference to do that.

 

Try the following VI's.

Download All
Message 5 of 7
(8,333 Views)

Thanks for the reply ravens fans,

all points noted.

however the  end of loop is not being read in the main loop. so i used the same logic of bool refnum to variant conversion to get value from subVI, now it works, thanks.

 

but still the abort button in main VI is read at the period specified, so when no. of seconds increased to 1000 it is waiting for 1000 seconds to stop the main VI. I understand that it has to be read more frequently as you said. but i am using the period of the timed loop to get values from DAQ at that specified interval (like get values every 30 min etc), so essentially I cannot change it. only way to stop it seems to me the use of stop timed structure but that -804 will occur again i guess.

 

any work around?? like using a normal while-loop case structure /functional global or anything. i just need to take 20 values (loop iteration i= 0-19) every 2 min (dt=3200) that makes the total duration of expt 40 min. the only issue is i have to be able to stop with a button click/ end of data collection whichever occurs first.

 

*can you post in 8.6 version, i have 2009 trial expiring soon

 

Thanks,

0 Kudos
Message 6 of 7
(8,325 Views)

Solved,

 

I figured out. attached is the working solution.

 

Thanks for the help.

Download All
0 Kudos
Message 7 of 7
(8,313 Views)