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 Start | Punishment End | Punishment Duration |
2:30 | 3:00 | 30 min |
2:31 | 3:01 | 30 min |
2:45 | 3:15 | 30 min |
2:59 | 3:29 | 30 min |
3:00 | 3:30 | 30 min |
Second Case (Wait Until Next ms Multiple) |
Punishment Start | Punishment End | Punishment Duration |
2:30 | 3:00 | 30 min |
2:31 | 3:00 | 29 min |
2:45 | 3:00 | 15 min |
2:59 | 3:00 | 1 min |
3:00 | 3:30 | 30 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