Reinitializing a Shift Register Without Stopping the VI

Updated Aug 22, 2023

Environment

Software

  • LabVIEW

There are instances in programming where you want to make changes to your coding inputs without stopping the program. There are many ways to go about this, one being to use a shift register. Shift registers pass values between iterations of code, continuously overwriting the previous value and bringing a new value into the next iteration. You can utilize this characteristic by programmatically overwriting the shift register value, resetting it to a default value while not stopping the code.

This tutorial is for beginner LabVIEW users. In these steps, you will set up a while loop with shift registers and use a case structure to take input from the user. The case structure will allow you to overwrite the shift register value to a default value when specified.

This can be done by adding a case structure within the while loop as follows, or by dragging the VI snippet to your block diagram if you are running LabVIEW 2013 or later:

  1. In order to select a while loop right click on the block diagram then navigate to Programming>>Structures>>While Loop and drag it onto the diagram.

  2. In order to select a case structure right click on the block diagram then navigate to Programming>>Structures>>Case Structure and drag a case structure into the while loop.

  3. Create a numeric constant outside of the while loop and wire it to the border of the loop.

  4. Right click on this tunnel and select Replace with Shift Register.

  5. Place a boolean control on the Front Panel. This is our reset button that will reset the shift register in the while loop. (The boolean can also be an indicator that shows if a case is true or false in your code).

  6. Wire the boolean control (or indicator) to the Case Selector of the case structure.

  7. In the True case, place a numeric constant of zero and wire to an output tunnel on the Case Structure.

  8. In the False case, wire the data through to the output terminal.

  9. Wire the output terminal of the case structure to the shift register on the right side of the while loop.

    Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

This code is applicable to arrays as well, you just have to replace the numeric constants with array constants.