LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

waint until ms vs ms function

Unable to find the difference in both function.

can someone explain using sample code?

0 Kudos
Message 1 of 4
(2,127 Views)

Are you talking about the two functions "Wait (ms)" and "Wait Until Next ms Multiple"?

 

To understand these two functions, you need to understand (really understand) the Principle of Data Flow.  Let's consider a While Loop as an example.  Once the code inside a While Loop starts to execute, the loop will not finish until every function inside the loop has finished.  In addition, the order in which the functions execute is governed by their Inputs and Outputs -- data must be present on all wired Inputs for the function to begin, and data is not presented to any output until the function finishes.

 

Now consider the Wait (ms) function.  It has one input, the number of milliseconds.  Let's wire a constant, 1000, to it.  How long will this function take to finish?  1000 milliseconds = 1 second.  Suppose it is inside a While Loop?  How fast will the While loop run?

 

The correct answer is "No faster than once a second, but it could run much slower".  Do you understand why?  You know that, by itself, the Wait (ms) function will take a second to finish.  Suppose you are also doing a big calculation that takes 2.3 seconds inside the loop -- the Wait finishes, but the calculation has another 1.3 seconds left to run, so the loop doesn't finish for another 1.3 seconds.

 

A harder question -- suppose another operation takes 900 milliseconds -- can we now say that the loop will finish in 1 second?  The answer is that we cannot, since we don't know when the Wait function started to run (LabVIEW will try to run it in parallel with the other code in the loop, but nothing is guaranteed ...).  

 

So what can we say about the time taken by loops with a Wait (ms) function inside them?  We can specify the minimum time, but cannot say anything about the actual times.  In particular, it could be the case that the loop times are something like 1.0, 1.2, 1.0, 2.1, 3.5, 1.0, 1.0, 1.0 seconds, not very good if we want things to happen "regularly" (and are willing to "miss a point").

 

That's the purpose of "Wait Until Next ms Multiple" -- it can transform the preceding loop times into 1.0, 2.0, 1.0, 3.0, 4.0,1.0, 1.0, 1.0 seconds, so all measurement times are "quantized" in units of 1 second (or 1000 millisecond) intervals.  Because there is No Such Thing as a Free Lunch, there's a cost associated with this -- the first Interval will probably be "short" to get the Timer "in synch" (i.e. if the Timer is initially at 657 msec and we are waiting for multiples of 1000, the first Wait will be for 343 msec, and the remaining for 1000).  The fix for this, of course, is to put a Wait for Multiple function before the While Loop and be sure to wire its output wire to an input tunnel on the While Loop (you don't use it on the inside).  If you've been following this explanation, and understand Data Flow, you will be able to explain why you need this wire from the Wait Multiple into the While loop  ...

 

Bob Schor

Message 2 of 4
(2,117 Views)

In less words than Bob...

 

Wait Until Next ms Multiple is used for synchronization.

Wait ms is used for general waits.

 

Let's just say one of these functions gets called with a timer value of 90 and it is set to wait for 100ms.  The Wait Until Next ms Multiple will actually only wait 10ms since 100 is the next multiple of 100.  The Wait ms will actually wait for 100 ms, ending with a timer value of 190.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 4
(2,090 Views)

BS for verbosity, crossrulz for succinctity (is there such a word?).

 

BS

0 Kudos
Message 4 of 4
(2,077 Views)