Adjusting the Execution Speed of a Loop

By default, LabVIEW executes each loop iteration as quickly as possible based on the code inside the loop. However, you might want to control the rate at which a loop executes in order to specify a fixed time interval for each iteration, reduce the speed at which an indicator changes value, or conserve processing resources.

What to Use

What to Do

Place the code you want to repeat on the subdiagram of a While Loop or For Loop.

To specify the amount of time to wait between loop iterations, wire the desired time duration to the milliseconds to wait input of the Wait node. The Wait node waits until the value of the millisecond counter of the operating system increases by an amount equal to the input you specify.

The total running time of the loop is equal to the greater of the time it takes to run the code inside the loop and the wait time you specify.

Pressing the stop button does not interrupt the Wait node. For example, if the user presses the stop button in the middle of a loop iteration, the While Loop stops only after the specified wait period has elapsed and the code inside the loop has finished executing.

Troubleshooting

If a loop does not execute at the desired rate, verify that you have specified milliseconds to wait correctly. Consider the following common mistakes:

If you are converting to milliseconds from another unit of time, verify that your conversion calculation is correct.

If your code takes longer than expected to execute, note that the total running time of the loop is equal to the greater of the time it takes to run the code inside the loop and the wait time you specify.