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, or its frequency. If you wanted to acquire data in a loop, you would need a method to control the frequency of the data acquisition.
Timing a loop also allows the processor time 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. Timing a loop can drastically increase performance.
Untimed Loop Timed Loop Executing at 1000 Times a Second
You can control loop time in LabVIEW using Wait functions These functions control how long to wait before performing the next iteration of the loop. There are two basic wait functions in LabVIEW:
Wait (ms) and
Wait Until Next ms Multiple.
The Wait (ms) function forces the loop to wait for a user-specified amount of time, in milliseconds, before running the next iteration.
The Wait Until Next ms Multiple function watches the millisecond counter and waits for it to reach a multiple of the user-specified time, in milliseconds, before running the next iteration of the loop. You can use this VI to synchronize different activities. For example, you can configure multiple loops to execute at each multiple of 200 ms.
This tutorial explains how to implement timing structures in LabVIEW and helps you 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 is suited for LabVIEW beginners. If you are looking for more resources on LabVIEW basics, look into the
Introduction to LabVIEW getting started material.