LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the Wait function in while loops?

Hi,
I have a rather complicated top level VI with about 20 subVIs and the main VI has on big while loop around it and another smaller one inside, basically it runs rather slow and I have no idea how to set the wait function. I mean what factors should I consider..what would be the difference between setting it to 10 and 100 (besides the obvious 10ms vs 100ms)? I just want to increase the performance of the executable, so it is not that slow. Can you offer some hints as to what I need to take into consideration when determining my delay? And also, are while loops the only place that I should use the delay or are there other instances too?
0 Kudos
Message 1 of 8
(5,919 Views)
The idea of setting a delay in a loop is to keep that loop from needlessly executing as fast as it can. This is particulary true in loops that monitor user interaction on the front panel. Setting a delay of 250ms will not be noticable to the user, but will save some processor time if that loop had been previously running at like every 1ms. Basically if you don't need the loop to execute as fast as it can then add a small delay, like a 100ms or so.

Good luck!

Brian
Message 2 of 8
(5,919 Views)
Thanks,
So when you say loop you mean only while loops right? Or do for loops also take timers?
0 Kudos
Message 3 of 8
(5,919 Views)
The wait function does just that, it waits a set number of milliseconds. It does this any time that it is run. Be that in a while loop, a for loop, or just in the main program. Put the wait VI anywhere that you need a delay.

Rob
0 Kudos
Message 4 of 8
(5,919 Views)
I guess since I'm more used to text based programming I don't really have a feel for when the Wait will get executed since LabVIEW does not have clear flow of events (at least in my mind). So If a sequence of about 10 frames I'd be better off to put some kind ofa wait in each one, so would that improve my performance?
0 Kudos
Message 5 of 8
(5,919 Views)
The main reason for puttings waits inside of loops is to improve the response of a user interface. The wait allows the OS to process mouse clicks, etc. Putting waits inside of sequences will only add a delay between the execution of each sequence. It sounds to me like you want the whole application to run faster. You can use the Profile VIs option under the Tools>Advanced menu to see what VIs are taking all of the time and work from there.

p.s. If you want to better visualize LabVIEW flow of events, make use of error in/error out connections to enforce dataflow and I'd recomend getting rid of the sequence structures.
0 Kudos
Message 6 of 8
(5,919 Views)
Yes you are exactly right! I want the whoel application to run faster, and the reason I say it goes slow is because it does not respond to mouse clicks. I have run the profiler so it shows me the subVIs that take the most time so where should I put a wait, in the subVI or right outside it?
0 Kudos
Message 7 of 8
(5,919 Views)
Adding waits is not a fix-all for slow running applications. Its just one thing that can be done to improve things. If you determine that a sub-vi is causing your problems then you need to find out exactly what that vi is doing to slow you down. If its because there is a loop inside it that is running constantly as fast as it can, then a delay in that loop may help. If that is not your problem then you need to look at other ways to boost performance. It sounds like you have alot of locals variables, each instance of a local variable makes a copy of the data that's in the control. If the controls/indicators that you have local variables of contain large amounts of data then you may be filling up memor
y with copies of it.

I suggest that you study the "Performance and Memory Management" chapter of the LabVIEW manual. This can found in the printed manual of the older versions, in the online manuals that install with 6i, or on NI's web site here: http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/732cec772aa4fbe586256a37005541d3?OpenDocument , which is Application Note 168. This should give you some good ideas of what to look for to improve your performance.

Hope this helps.

Brian
0 Kudos
Message 8 of 8
(5,919 Views)