This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Using Shift Registers in LabVIEW

Updated May 23, 2024

Environment

Software

  • LabVIEW

When programming with loops, sometimes you need to call data from previous iterations of the loop. In LabVIEW, you can use shift registers, which are similar to static variables in text-based programming languages, to pass values from one loop iteration to the next.
After the loop code executes, data enters the right shift register and is passed to the left shift register on the next iteration of the loop.

This tutorial explains how to add and configure shift registers in LabVIEW. 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.
 

  1. Launch LabVIEW and open a new VI by navigating to File » New VI.
  2. Place a numeric control on the front panel (Controls >> Modern >> Numeric >> Numeric Control) and change its value to 2.
  3. Double-click on the control’s name and change it to Initial.
     
  4. Place a numeric indicator on the front panel (Controls >> Modern >> Numeric >> Numeric Indicator) and name it Result.
  5. View the block diagram by selecting Window»Show Block Diagram or pressing <ctr-E>.
  6. Place a for loop on the block diagram (Functions»Programming»Structures»For Loop) between the numeric control and indicator.
  7. Right-click on the input of the count terminal of the for loop and select Create Constant. Change the value of this constant to 2.
  8. Wire the output of the Initial control to the right edge of the for loop to create a tunnel.
  9. Right-click on the tunnel that you just created and select Replace with Shift Register.
  10. Wire the output of the right shift register to the Result indicator.
  11. Place a multiply function in the for loop (Functions >> Programming >> Numeric >> Multiply).
  12. Place a numeric constant in the for loop (Functions >> Programming >> Numeric >> DBL Numeric Constant), assign it a value of 3, and connect it to one of the input terminals of the multiply function.
  13. Wire the left shift register to the remaining input of the multiply function, and wire the output of the function to the right shift register.
  14. View the block diagram by selecting Window»Show Front Panel or pressing <ctr-E>.
  15. Run the VI. The VI changes the value of the Result indicator to 18.

Shift registers are integral to this VI. To understand how the VI works, you can step through the code:
  1. Because the for loop’s counter terminal is wired to a constant of 2, it runs twice.
  2. On the first iteration of the for loop, the value of Initial, 2, is multiplied by 3. The result is 6, and this value is passed to the right shift register.
  3. On the second iteration of the for loop, the left shift register receives the value that was sent to the right shift register on the previous iteration, 6. The value of 6 is multiplied by 3, for a result of 18.
  4. Because the for loop completed all of its iterations, it stops running and the value of 18 is sent to the Result indicator on the front panel.
The mathematical formula for this simple VI looks like this:
Result = ( ( Initial * 3 ) * 3 )
If you changed the value of the for loop’s count terminal to 4, the mathematical formula looks like this:
Result = ( ( ( ( Initial * 3 ) * 3 ) * 3 ) * 3 )