Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
73 ratings:
 3.27 out of 5   

The Difference Between the Wait (ms) Function and the Wait Until Next ms Multiple Function



Primary Software: LabVIEW Development Systems>>LabVIEW Base Development System
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Development Systems>>LabVIEW Full Development System, LabVIEW Development Systems>>LabVIEW Professional Development System

Problem:

I have heard of the Wait (ms) and the Wait Until Next Millisecond Multiple functions, but it seems that they both accomplish the same thing. What is the difference between the Wait (ms) and Wait Until Next ms Multiple functions in LabVIEW?


Solution:

Both functions are used to block execution for a specified period of time, usually in order to control the rate at which a loop will execute. The difference is that the Wait (ms) function simply blocks until the time specified at milliseconds to wait elapses, but the Wait Until Next ms Multiple function blocks until the current value of the system millisecond clock is evenly divisible by the value specified at millisecond multiple.

The figure below illustrates when execution would be unblocked if both VIs had 100 as their respective inputs and started running at 50ms. The horizontal axis is the value of the system millisecond clock.



You can also observe the difference in execution using the following code examples.

Wait (ms):
The Wait (ms) function will block execution until the time specified at milliseconds to wait has elapsed.

  • Example 1: Consider a loop with code that takes 5 ms to execute. The loop also includes a Wait (ms) function with 10 ms wired to its milliseconds to wait input. The While Loop takes 10 ms total to execute because the code finishes after 5 ms and then the Wait (ms) function finishes 5 ms later. In this case, the Wait (ms) function executes in parallel with the code.



    In this example the loop timing is set by the outer Wait (ms) function.

  • Example 2: The loop is the same as in the previous example, but the code now takes 15 ms to execute. The outer Wait (ms) function still has 10 ms wired to its milliseconds to wait input. Because the time wired to the Wait (ms) function is less than the time it takes the code to execute, there is no delay after the code finishes, and the loop moves to the next iteration immediately after 15 ms elapses.



    In this example the loop timing is not set by the Wait (ms) function. It is set by the overall execution time of the code within the loop.
Wait Until Next ms Multiple:
You can use the Wait Until Next ms Multiple function to synchronize separate loops to your system's millisecond clock. As the name suggests, it will wait until the next multiple of the number of milliseconds specified at the milliseconds multiple input before becoming unblocking.

  • Example 3: There is a loop with code that takes 100 ms to execute and a Wait Until Next ms Multiple function running in parallel with the code. The Wait Until Next ms Multiple function has 200 ms wired to its millisecond multiple input. The loop executes at every 200 ms multiple of the system's millisecond clock. There is second loop in the same VI that has a Wait Until Next ms Multiple function with 200 ms wired to its millisecond multiple input. The code in the second loop takes 150 ms to execute running in parallel. The two loops will be synchronized to move to their next iterations every time a multiple of 200 ms on the system clock elapses. Using this method, it will be insured that each loop begins subsequent iterations at the same time.


Note that when using the Wait Until Next ms Multiple function in a loop, the first iteration delay will not be the same as the time that is specified for the millisecond multiple input. This is because the Wait Until Next ms Multiple function waits until the current value of the system's millisecond clock is evenly divisible by the value you specify at millisecond multiple input. Therefore, the very first time it runs, the time it waits is dependent on the absolute time of the system millisecond clock. Every subsequent iteration will be aligned with this time and wait the appropriate amount of time that you specified at millisecond multiple.

Keep in mind that like the Wait (ms) function, the Wait Until Next ms Multiple function will have no effect on loop speed if there is code executing in parallel that takes longer than the time specified at millisecond multiple. In this instance, the next loop will start after the code has finished running

Refer to the LabVIEW Help (linked below) for more information about the differences between the Wait (ms) function and the Wait Until Next ms Multiple function.


Related Links:
White Paper: Software Timed Loops using Wait (ms) and Wait Until Next ms Multiple
NI Community: Wait (ms) and Wait Until Next ms Multiple Explained
LabVIEW 2015 Help: Wait (ms) Function
LabVIEW 2015 Help: Wait Until Next ms Multiple Function

Attachments:





Report Date: 10/16/1995
Last Updated: 09/07/2016
Document ID: 0EF854SG

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit