Laboratory Virtual Instrument Engineering Workbench (LabVIEW) is a system development environment developed by National Instruments. It is used to test, measure, and control software applications. Virtual instruments help developers in building flexible applications that meet customer needs. We can create virtual instruments with a combination of software and hardware through block diagrams. The shift registers play an integral part in the process of virtual instrument creation. In this post, you will understand the potential of shift registers in LabVIEW. You will get to know what shift registers are, how to initiate, and stack them, etc. Keep on reading to improve your LabVIEW knowledge.
When we use loops in LabVIEW, we often need to get data from the previous iteration. The data from the previous iteration of the loop should be retained for further processing. A shift register is used to store data in looping conditions like For loops and While loops. It lets you pass values from the previous iteration of the loop to the next. It can be termed as a local variable inside a loop.
The shift registers appear as terminals on vertical sides of the loop border. The terminal on the left side is a down arrow. On the other hand, the terminal on the right side is an up arrow. When the loop executes, the last value stored in the shift register will be returned by the terminal on the right side.
A shift register can transfer data of any type. It takes the data type of the first object wired to the shift register. Each shift register of a terminal should be of the same type. We can perform calculations based on the data stored in a shift register. Certain decisions can also be made with this data. We can add multiple shift registers to a loop. If we have multiple values to read from the previous iteration, we can add multiple shift registers to store each of the values.
We can implement a shift register in two methods.
Method 1: Create either a For or While loop on the block diagram. Add a shift register to the loop by right-clicking on the left or right border of the loop and selecting the ‘Add Shift Register’ option from the shortcut menu.
Method 2: Create either a For or While loop on the block diagram. Wire a node to the loop. Right-click on the node and select the ‘Replace with Shift Register’ option from the short-cut menu.
The shift register initialization resets the value when the VI is run. It then passes the new value to the first iteration of the loop. Wire a control or constant to the shift register terminal on the left side of the loop to initialize a shift register.
For example, take a loop that increments the value of the shift register by 1. When the VI is run, the shift register will get initiated and begins with the value 0. If the loop iterates 3 times, the final value that the shift register passes is 3. Now when the VI is run again,
If we want to access data from multiple previous iterations, we can use stacked shift registers. These stacked shift registers remember values from multiple previous iterations and carry them to the next iteration. We can use stacked shift registers only on the left side border of the loop. The terminal on the right side of the loop only transfers data generated from the current iteration to the next. Hence, we cannot use stacked shift registers on the right terminal.
To add a stacked shift register, right-click on the left terminal. Select the 'Add Element' option from the shortcut menu. The values from the last two iterations will pass to the next iteration. The most recent iteration value will get stored in the top shift register. The previous iteration value will get stored in the bottom shift register.
A tunnel is used to pass data to an ongoing loop in LabVIEW. The value and data type does not change before or after the loop structure. A tunnel can be replaced with a shift register when necessary. To do so, right-click on the tunnel and select the 'Replace with Shift Register' option from the shortcut menu. If there is no tunnel on the other side, LabVIEW will create a shift register on that side as well. If multiple tunnels exist on the loop, you will get an option to choose the tunnel that you want to change to a shift register.
If we want to reinitialize a shift register value to zero when an action is performed on the front panel, we can do so without having to stop the VI. All we need to do is add a case structure within the while loop. Right-click on the block diagram and choose the 'Programming' option from the shortcut menu. Then select the 'Structures', select the 'While Loop' option, and add it to the block diagram. Drag and drop a case structure into the while loop.
Create a numeric constant and wire it to the border of the while loop. Replace the tunnel with a shift register. Create a boolean control on the front panel. This will work as a reset button that will reset the shift register. Wire the boolean control to the case structure. Wire the output terminal of the case structure to the shift register on the right side of the while loop.
Here are a few pointers to keep in mind while working with the shift registers.
The shift registers are the best way to pass data between loop iterations in LabView. Now, that you know how to use the shift registers, create a block diagram, and experiment with the shift registers. If you are looking for some more information, check out our other posts on LabVIEW.
Batch starts on 30th Sep 2022, Fast Track batch
Batch starts on 4th Oct 2022, Weekday batch
Batch starts on 8th Oct 2022, Weekend batch