Shift registers in labview examples : tutorial 10



In this tutorial, you will study the working principals and benefits of using a shift register with loops. You are provided with an explanatory introduction at the start, explaining the working and uses of shift registers. After that a program explain the usage of shift registers in detail is written, using a while loop. In the VI I have also explained how to expand a shift register and how to use it. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.



Introduction to shift registers in labview

When you want to pass values from previous iterations through a loop to the next iteration, what you need is shift registers. Below is shown the shift registers, which is basically a pair of terminals, directly opposite each other on the vertical sides of the loop border.

How to get shift registers in labview

On the right side of the loop a terminal is present which contains an up arrow, and this terminal stores data on the completion of iteration. Data stored in the right terminal of the shift register is transferred to the left terminal in LabVIEW. The data from the left terminal is then used by the loop as the initial values for the next iteration. Until all the iterations of the loop executes this process continues. The terminal on the right side of the loop returns the last value stored in the shift register, after every execution of loop.

Any data type can be transferred using shift register and they automatically changes to the data type of the first object wired to the shift register. Data type of the data wired to the each of the terminal of the shift register should be of same.



Multiple shift registers can be added to one loop. Use multiple shift register to store the data values from different processes within the loop, if you have multiple operations that uses the values from previous iterations within the loop.

A shift register must always be initialized in case of ‘for’ loop. When the shift register is not initialized ‘while’ Loops whereas produce default data. We must have to wire the shift register to 0 if we want a ‘For’ Loops to produce default data. If you wire an empty array to the ‘For’ Loop as an input with auto-indexing enabled, it will still produce default data. Shift registers are used to transfer values through a loop whether or not the loop executes.

Labview program to use shift registers

  • Let’s move to the LabView and try to understand the work king of shift registers in depth. Create a blank VI as discussed in tutorial 1 and save it as we have done in all previous tutorials.
  • From the function palette select structures and then select while loop and place it on the block diagram. We have been using for loop in our all previous tutorials, let’s work with while loop in this one. You must have done the exercise I gave you to do yourself in previous tutorials and you must be familiar with the working principal of a while loop, refer to the figure below.while loop

Figure 1: for loop

  • Right click on the iterative index a dropdown will appear select create indicator, this will create a numeric indicator, see the figure below,iteration indicator shift registers in labview

Figure 2: Indicator placement

  • Right click on the front panel, from the control palette select Boolean and then select stop button as show in the figure below,stop button labview

Figure 3: stop button

  • On the block diagram the respective block of the stop button will appear, connect this block to the loop condition of the while loop (a red dot at the bottom right corner), the resulting block diagram will look like the one shown below,While block

Figure 4: While block

  • Now, what is not present in the block?? A wait watch to control the time of each iterations, let’s add a wait watch, and set its time to 0.5sec.
  • Do yourself: Place the wait watch as we have done in previous tutorials.
  • After the placement of wait watch the complete block diagram will look like as shown in the figure below.Complete while operation

Figure 5: Complete while operation

  • Right click on the boundary of the while loop a dropdown will appear as shown in the figure below, and select shift register from the menu,shift register placement labview

Figure 6: Shift register placement

  • This will place a pair of shift registers on each side of the loop, one pointing up and the other pointing down. Now place an addition block inside the for loop and connect the left shift register to one of its input, and at the other input connect a constant with a value of 10 in it,, as shown below,Add block connections

Figure 7: Add block connections

  • The wire connected to the shift register is broken because the register does not have any value stored in it yet, it is void. Connect the output of the add block to the right shift register. This will provide an input to the previous value of the shift register and this value will move to the left shift register in the next iteration. In each iteration, the previous value is added with 10 placed in the next register and then move forward to the shift register in the next iterations. Every next number will be 10 more than the previous, see the figure below,Shifting values labview

Figure 8: Shifting values

  • Now, who will tell the registers where to start??. The shift register should always be initialized. Right click in the shift register and create a constant and place a zero in it. This is where the register will start processing.Initializing shift register

Figure 9: Initializing shift register

  • Now, if you want to see the value stored in the register at iteration, place an indicator at the output of the addition block as shown below,Addition indicator

Figure 10: Addition indicator

  • This gives the value of the sum after iteration. Run the program and see the results the sum of the blocks will update by 10 every half a second see the figure below,Results of shift registers in labview

Figure 11: Results

  • Starting from 0 at 5th iteration the number of addition is 60 (adding 10 at each iteration), If you want to stop the execution press the stop button.
  • There is another important feature of the shift register and that is that you can expand down the left side shift register, what this allows us to do that we can not only access the value from the previous iteration but also the one before that, see the figure belowAccessing last 2 values shift register labview

Figure 12: Accessing last two values

But, when you use more than one shift register, you must initialize all of them, in order to make them start together. Place indicator with both of them and see the values of both the register at iterations.

Exercise:

  • See the results of the expanded shift register and try to understand them.
  • Try to work with shift registers using for loop

<<Previous tutorial                                                 Next tutorial>>



Add Comment