Example Code

Delay Loop with a Divisor using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview
This example allows the user to run code at different rate inside of one while loop.  


Description
When the user turns the switch off it will delay for two seconds and then turn it back on. There is also a flashing LED running that turns on and off every 100 milliseconds to demonstrate that the delays are ultimately different. The principle behind this that every time the Wait function is triggered, a shift register adds one to itself. Once the shift register accumulates to 20, it triggers the inner-most case structure and then resets; this is why it is called a "divisor". This is a good way to keep to tasks in synchronization with each other while running at different rates.


Requirements

  • LabVIEW Base Development System 2012 (or compatible)


Steps to Implement or Execute Code

  1. Run the VI.
  2. Turn the switch off.
  3. Wait two second, the switch turns it back on

 

Additional Information or References

VI Front Panel

Front Panel.png
VI Block Diagram

Block Diagram.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Tannerite
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Alex.T
Active Participant
Active Participant
on

Since there's a small amount of code within this loop, it may be beneficial to use a Wait(ms) function rather than a Wait Until Millisecond Multiple.

In the switch case, to demonstrate behaviour it may be handy to reset the Shift Register back to zero once it has succeeded the correction constant, rather than writing to the 'Switch' value (I don't have LabVIEW 2012 so I'm hazarding a guess at that's what is happening). This makes these two tasks susceptible to losing their sequential synchronisation by allowing the user to change the value of the boolean.


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)