LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop completion issue

Hi there

 

I have specific test that I want the user to enter how much time it needs to run. This time gets converted to a number which then gets fed into a for loop which runs a certain amount of time (See attached jpeg).

I'm guessing my number conversion is funky because my time remaining indicator sometimes goes negative which keeps the VI from completing. When I test it with a small amount of time, for example FP_Time = 0.1, the VI ends just fine. I'm having this problem when the test is ran for 48h (The sample rate control is set to 5). How come? I noticed I don't have a number conversion wired to my "wait time" function? Could that be it? Please help me understand what is going on.

thank you!

Don't think twice.
0 Kudos
Message 1 of 5
(2,465 Views)

Instead of a lot of awkward math to try to drive a For Loop, use a regular while loop and the Elapsed Time Express VI to determine when to end the loop.

0 Kudos
Message 2 of 5
(2,463 Views)

yes I see your point. Thats probably what I will end up doing. But I also wanted to understand why this happens.

Don't think twice.
0 Kudos
Message 3 of 5
(2,428 Views)

sb_oxinst wrote:

I'm guessing my number conversion is funky because my time remaining indicator sometimes goes negative which keeps the VI from completing.


Well, that indicates that you check the completion with an equal comparison. Use a "less or equal zero" instead, for example.

 

You are running a fixed number of iterations, 5 seconds each and comparing the elapsed time at that rate. Depending on what else the computer is doing, some iterations might take 5001ms, and you will accumulate small errors over time that end up in a negative time difference at the end.

 

btw. why are you using a local variable? Simply wire the current time from outside the loop.

Message 4 of 5
(2,417 Views)

thanks for reply alten.

 

I believe you are right because the negative time is not always the same value . I must have a fairly large error accumulating in that 48h period because my counter goes negative for over 10h haha.

I realize that their are much better ways to do this.

thanks,

Don't think twice.
0 Kudos
Message 5 of 5
(2,411 Views)