LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does a while loop run faster than it's specified Wait Until Next ms Multiple?

Greetings-
Can someone explain how a while loop can run faster than the millisecond value wired to the Wait Until Next ms Multiple function inside the while loop?
I'm using the Tick Count function along with a shift register to determine the time that it takes for each loop iteration. Usually, the time it takes for the loop to iterate is in agreement with value fed into the Wait Until Next ms Multiple function, but occasionally it is significantly shorter. On the order of 10 to 20 milliseconds. How can this be?

Without getting into great detail, the while loop processes reads from a daq board and from a motion control board.
I'm also using:
LabVIEW 7.1
Windows 2000

Thanks.
0 Kudos
Message 1 of 4
(4,612 Views)
A few point to ponder:

Setup like this, the first iteration can be quite variable, because it depends on the start time of the loop with respect to the ms multiple. Do you also see variations in the later iterations?

I would highly recommend to use the timed loop (LabVIEW 7.1), it will make things much more predictable.
Message 2 of 4
(4,580 Views)
I wasn't a bad kid when I was young, but I occasionally got into trouble. My mom's form of punishment would be to send me to my room for a certain amount of time. "Robert, go to your room for 30 min!" she would say. Now she wouldn't have done this, but let's suppose she said to me, "Robert, go to your room until the next 30 min multiple!" The first case is comparable to the "wait" function and the second to the "wait until next ms multiple". Now let's compare the two cases:





First Case (Wait)
Punishment StartPunishment EndPunishment Duration
2:303:0030 min
2:313:0130 min
2:453:1530 min
2:593:2930 min
3:003:3030 min






Second Case (Wait Until Next ms Multiple)
Punishment StartPunishment EndPunishment Duration
2:303:0030 min
2:313:0029 min
2:453:0015 min
2:593:001 min
3:003:3030 min


If I'm sent to my room anytime between 2:30 and 2:59, the next 30 minute multiple is still 3:00, so I'm actually in my room anywhere from 30 minutes to 1 minute (lucky for me). Similarly, your while loop can run anywhere from 2 ms (see this thread) to the value you specify.

Your loop will generally only run faster than specified on the first iteration (see KB 2G27ANEW "Wait Until Next ms Multiple" Function Does Not Wait Properly on First Loop Iteration") and then align to whatever multiple you have specified. This would be analogous to my being sent to my room at, say, 2:45, getting out at 3:00 and being sent right back in until 3:30, then out and back in until 4:00, and so on.

The alignment can be thrown off if your code takes longer than the multiple to execute. If, for some reason, I decided to stay in my room past 4:00, say until 4:05 and then came out and was sent back in, my next "iteration" would only last 25 minutes instead of 30. Because of this misalignment, later loops can also run faster.

If you want every iteration to run for at least the specified time, I would recommend using the "wait" function, or the new "timed loop" (LabVIEW 7.1 and later).
Robert Mortensen
Software Engineer
National Instruments
Message 3 of 4
(4,563 Views)
Great response, Robert, and a touching story.
I hope these stars can help you recover from your childhood punishments.

___________________
Try to take over the world!
Message 4 of 4
(4,554 Views)