You are on page 1of 2

LabVIEW Shift Registers

The shift register feature in LabVIEW essentially provides a history mechanism for loop structures. Shift registers may be added to while and for loops by right-clicking on the loop border and choosing Add Shift Register. By doing this, you can wire an output of the loop to the right terminal and access that result in the next loop iteration via the left terminal. You can also wire an initial value to the input of the left terminal. 1. Create the following VI and save as Summation.vi. When you create the control n, the indicator summation, and the constant 0, change each of their representation to 32-bit integer.

2. Run this program for various values of n. Are there any values of n that this program does not work for? What result does this VI produce in such cases?

Shift registers in LabVIEW may also have more than just a single element of history. In the case of a 2element shift register, the previous two loop results would be stored in and available in the registers. Additional elements are added to a shift register by right-clicking either terminal icon and choosing Add Element. Consider the Fibonacci sequence wherein each number in the sequence is the sum of the previous two. Mathematically, we say:

This formula is defined for values of n greater than 1, so the first two values in the Fibonacci sequence are predefined as seed values of 0 and 1. 3. Create a new VI as save it as Fibonacci.vi. Place a while loop then add a numeric control n and a numeric indicator summation as shown. Also add a two-element shift register with initial constant values of 0 and 1 as shown.

4. Change the loop condition to Continue if true and complete the loop termination logic as shown.

5. To handle the special case when n<=0, we use a case structure to produce the zero answer otherwise we produce the sum of the previous two numbers. Add a zero-test on n and a true/false case structure with contents as show.

6. Run this VI for various values of n and verify using the list of the first 300 numbers in the sequence given at http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibtable.html Thus, the shift register mechanism in LabVIEW provides history of previous values for loop iterations. A good application of this in our robotic kit is to keep track of the previous distance sensor sweep angle for determining the next angle.

You might also like