11-10-2010 10:28 AM
Can someone please explain to me how the “Wait Until Next ms Multiple.vi” works ?
I am looking at an older code and the only different when I run smaller angle (less than .72) and bigger angle (larger than .72 ) is the “Wait Until Next ms Multiple.vi”.
And yes I have read the help file. I just need a little bit more elaboration on what exactly is does the “Wait Until Next ms Multiple.vi” does?
I am using a timed looped with 5ms time period.
11-10-2010 12:36 PM
That VI uses the built-in ms timer in the OS.
When executed it will put the thread it is running in, into a resource wait state waiting for an interupt to be made runable again. The interupt (trap?) is configured to fire when the systems ms timer reaches an even multiple of the value you specify.
So if;
MS_Time = 100 and you pass the value "100" then then it fires right away.
if
MS_Time = 90 and you pass 100 then it will wait 10 ms and then fire.
If that function live beside other code taht takes longer than 100 ms then the first multiple will get missed and you wait for the remaining time until the next multiple that comes up.
So it syncronizes your code with the next ms multiple.
I avoid using that function becuase (unless you use only prime numbers for wait values like the cicada) it winds up being a effective way of waking-up all of your loops at the same time and make them fight over who get the CPU first.
I use the plain vanilla version.
Ben
11-10-2010 03:59 PM
Ben,
Thank a lot. I love the example. But I still have another question. What would you recommend me using? Normal wait (ms) vi?
11-10-2010 08:17 PM
You said you are using a timed loop. Why the question about a wait?
11-11-2010 07:19 AM
Adding to Dennis' Socratic response...
Yes use the normal wait if you are NOT using the timed loop. Timed loops are quite impressive evn under a non-determinsitic OS.
Ben
11-11-2010 09:46 AM
Another use is instead starting from zero, the VI can be used to syncronize action at a specific clock multiple set by the "millisecond multiple" input.
Example, input 1000ms to the Wait and Wait Multiple in seperate loops. Let say Wait timer value is 175696182 well WaitMultiple will output 175696000 for its and continue on the 175697000, 175698000...
Useful if you want to process data by a particular clock value.... and not just the interval.
11-11-2010 10:03 AM
lol.Socratic...
well i am doing data acquation on a motor so sometime there may be a very small overshoot. When the motor stop moving, the code use the "wait until next multiple.vi"to determine the final distance..
so i was just concern with what exactly is happen on the finally loop..
11-11-2010 10:13 AM
Rich,
I am slow. Can you please elaborate on that some more? Sound interesting. Think that may be related to what happen to my code. When I measure smaller distance I have to use bigger numbers for the wait.
11-11-2010 11:35 AM
Hey, wait a millisecond, this was just posted in the Community to demonstrate differences between wait variants:
http://decibel.ni.com/content/docs/DOC-14149
-AK2DM
11-11-2010 01:09 PM
@sticyfinger wrote:
I am slow. Can you please elaborate on that some more? Sound interesting. Think that may be related to what happen to my code. When I measure smaller distance I have to use bigger numbers for the wait.
Please elaborate how you are measuring. A wait controls, and does not measure, timing. What happens in the code during the wait? How do you measure?
In a nutshell, here are some semi-true analogies:
Wait until next ms multiple
Do something every hour on the hour (60 minutes multiple), i.e. wait until the minute hand points straight up. If your task takes 30 minutes, you get a 30 minute break, if the task takes 50 minutes, you can only take a 10 minute break. If your task takes 61 minutes, you get a 59 minute break, but might lose your job because you missed an assignment. 😄
The first wait is random between 0 and 60 minutes and depends on the time you arrive at the job site.
If the wait is in a loop, the first iteration takes between 0 and x ms. All subsequent iterations are equally spaced unless your code cannot complete in the allocated time.
Wait(ms)
No matter what time it is, wait 60 minutes before continuing. This is often somewhat clouded by the parallel nature of LabVIEW. For example if a wait(ms) is in a loop, the iteration cannot complete until at least x ms have elapsed. However the timer starts in parallel with the other operation in the loop, so even if the operations take a significant amount of time, it won't artificially prolong the loop. However, if you would use a sequence such that the wait is in the last frame, the loop time will be the sum of the code time and the wait time. And so on....
All waits are the same, and independent in when you arrive at the job site.
If the wait is in a loop, all iterations will be approximately x ms unless your code cannot complete in the allocated time. Over time, there could be slight drift due to accumulations of small errors caused by the delay between the loop start and scheduling of the wait node.