Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
59 ratings:
 3.22 out of 5     Rate this Document

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 function 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:

Wait (ms)
The Wait (ms) function is typically used as a programmatic delay between code segments. The Wait (ms) function will block execution until the time specified at milliseconds to wait has elapsed.

  • Example 1: There is 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.

  • Example 2: The loop is the same as in the previous example, but the code takes 15 ms to execute and the Wait (ms) function has 5 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.

Refer to the attached VI and following VI snippet for an example of how the Wait (ms) function works in parallel with the executing code.


 

Wait Until Next ms Multiple
The Wait Until Next ms Multiple function is typically used for the purpose of synchronizing separate loops to the 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: There is a loop with code that takes 100 ms to execute and a Wait Until Next ms Multiple function in parallel with it. 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 another loop in the same VI that has a Wait Until Next ms Multiple function with 200 ms wired to its millisecond multiple input. In parallel with this function is some code that takes 150 ms to execute. 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 exactly 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, with respect to the system millisecond clock, that the loop began to execute. 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 the Wait Until Next ms Multiple function should have no effect on loop speed if there is code executing in parallel with it that takes longer than the time specified at millisecond multiple.

Refer to the attached VI and the following VI snippet for an example of how the Wait Until Next ms Multiple function can be used to synchronize two loops to multiples of the system clock.


The key point to take away is that the Wait (ms) function simply blocks until the time specified at milliseconds to wait elapses, and 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.

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:
KnowledgeBase 2G27ANEW: Wait Until Next ms Multiple.vi Does Not Wait Properly on First Loop Iteration
LabVIEW 2013 Help: Wait (ms) Function
LabVIEW 2013 Help: Wait Until Next ms Multiple Function
NI Community: Wait (ms) and Wait Until Next ms Multiple Explained

Attachments:

Wait_ms_example (LabVIEW 7.1).vi
Wait_ms_example (LabVIEW 2010).vi




Report Date: 10/16/1995
Last Updated: 05/27/2014
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