Loop Timing Configuration in LabVIEW

Updated Apr 26, 2021



  • LabVIEW

Normally when a loop, such as a while loop, finishes executing one iteration, it immediately begins running the next. However, it is often beneficial to control how often a loop executes as this will allow the processor to complete other tasks such as updating and responding to the user interface. In the following figures, the processor usage for a simple VI with a while loop running untimed and timed are shown. 
Untimed Loop                    Timed Loop Executing at 1000 Times a Second

In LabVIEW, it is possible to control the loop execution rate and synchronize multiple activities using functions Wait (ms) and Wait Until Next ms Multiple. For example, multiple loops can be configured to execute at each multiple of 200 ms. The difference between these two functions is addressed in this article.

This tutorial explains how to implement timing structures in LabVIEW and helps to visualize how loop time affects number of iterations of a loop. Before completing this tutorial, it may be helpful to review information on LabVIEW For Loops and While Loops. This is a tutorial suited for LabVIEW beginners. For more resources on LabVIEW basics, look into the Introduction to LabVIEW getting started material.

Configure Front Panel Objects

  1. Launch LabVIEW and open a new VI from File >> New VI.
  2. Place a knob numeric control on the front panel by right-clicking on the front panel and navigating to Controls»Modern»Numeric»Knob. This knob will be used to set the wait time of the while loop.
  3. Double-click the name of the knob and change its name to Wait Time (ms).
  4. Change the knob’s limits to 1 and 1000 by double-clicking on the knob’s current limits and entering the new values. It is also possible to adjust the limits of the numeric control by right-clicking on the knob >> select Properties >> Scale tab >> set the Scale Range Minimum and Maximum.
  5. Place a numeric indicator on the front panel by right-clicking on the front panel and navigating to Controls»Modern»Numeric»Numeric Indicator. This indicator will display the while loop iterations. 
  6. As this knob will be later connected to the Wait (ms) function, which expects an input of an unsigned long-integer, change the knob representation to U32 to avoid coercion. For that, right-click the knob icon and select Representation >> U32.
  7. Double-click the name of the numeric indicator and change its name to Iteration.
  8. Change the Representation of the numeric indicator to I-32 (long integer) by right-clicking on the indicator and selecting Representation >> I32.
  9. Place a Stop Boolean control on the front panel. You can find this at Controls»Modern»Boolean»Stop Button. This Stop button will be used to stop the while loop. When complete, the front panel will resemble the image below.

Configure the Block Diagram

  1. View the block diagram by selecting Window»Show Block Diagram or pressing <ctr+E>.
  2. Add a Wait (ms) function by right-clicking on the block diagram and navigating to Functions»Programming»Timing.
  3. Wire the knob control Wait Time (ms) to the input of the Wait (ms) function. The knob value specifies how long, in milliseconds, the loop waits before running the next iteration.
    block diagram 2.png
  4. On the block diagram, add a while loop around the front panel object icons. For that, 
    1. Right-click on the block diagram and navigate to Functions»Programming»Structures»While loop.
    2. After selecting the while loop, left-click and drag the loop around the icons. If one of the icons ends up not being included in the loop, it is possible to add it by clicking and dragging it into the loop.
      block diagram 2.png
  5. Wire the Stop control to the while loop’s stop conditional terminal. 
  6. Wire the numeric indicator to the while loop iteration terminal.
block diagram 3.png

Test Loop Timing

  1. View the block diagram by selecting Window»Show Front Panel or pressing <ctr+E>.
  2. Move the knob value to around 500 ms.
  3. Run the VI. Note that, because the wait time is set to ~500 ms, the iterations indicator updates every half-second.
  4. As the VI runs, change the knob value by clicking and dragging the knob. Note that as the speed of the loop increases, the iteration speed changes accordingly.
  1. Stop the VI using the Stop Boolean control.