LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

timed loop bug

I  have a timed loop in this VI which responds quite strangely.  I ran it under LabVIEW 7.1 and Windows XP.  It is supposed to vary the period according to the slider.  It seems to run as quickly as the GUI permits, and does not vary when the slider is moved.  The left and right data nodes seem a bit odd. 

I could fix this by replacing the timed loop with a while loop and then replacing the while loop with a timed loop again.  It was necessary to reconfigure the data nodes, and to rewire all wires broken on the first replace.
Download All
0 Kudos
Message 1 of 7
(3,026 Views)
In your bug_example.vi, you had the timeout set to 2ms.  The loop was timing out on every iteration because the period is being set to a much greater value.  Change the timeout to 1500ms and it will work fine.
In your second vi, the timeout is set to -1.  This is why it works.

Message Edited by tbob on 11-03-2005 09:54 AM

- tbob

Inventor of the WORM Global
Message 2 of 7
(3,005 Views)
Thanks.  Do you know what the timeout is normally used for?  How does it interact with discarding late iterations vs. running them as fast as poswsible to catch up?  Since you mentioned the timeout, I recall having set it, but while trying to debug the loop I did not see it.
0 Kudos
Message 3 of 7
(2,994 Views)
As far as I know, the timeout value is only seen when double clicking on the properties box at the top left.  Can't see it during debug.  Timeout is usually used as a check to see if something is wrong.  If your code is supposed to execute in a certain amount of time, you can set the timeout to stop an iteration and perform the actions you set, like discard missed periods and maintain orginal phase.  What happens at timeout is that the present loop iteration stops running and a new loop iteration starts running.  When you had the timeout set for 2ms and the period set for 150ms, the loop would stop executing after 2ms and start the next loop iteration since both Discard and Maintain were checked.  So it looked like your LED was being set and reset every 2ms, and your period control was having no effect.  Setting the timeout to -1 means that there is no timeout check and the loop iteration takes as long as it needs.  Timeouts are useful for catching hangups, and for synchronizing when some code took too long to perform.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 7
(2,990 Views)
Many thanks.  Do you have any idea why the bug_example VI has left and right data nodes with extra empty space (I couldn't make it go away) and the other has none?

0 Kudos
Message 5 of 7
(2,977 Views)

Hello!

Great advice from other LabVIEW users on the operation of timed loops.  As far as the extra space on those nodes, this is something that I personally have never encountered, and does not appear in LabVIEW 8.  It doesn’t seem to affect execution at all, just some sort of inconsistency between the way LabVIEW rendered the graphics of the nodes and what the compiler says is available.

On another note, I would recommend that you add a condition to end the loop.  Right now you have nothing wired to the stop condition of your loop -- which forces the user to use the "Abort Execution" button.  Though tempting, good LabVIEW programming dictates that use of the Abort button be avoided whenever possible!

Hope this helps,  please let us know if you have any other questions.

Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 6 of 7
(2,959 Views)
I agree about the stop condition, but the problem arose on a project in very early development.  When I pared down the example to remove irrelevant details, I didn't think to add anything.

0 Kudos
Message 7 of 7
(2,935 Views)