shift registers on For Loops and
While Loops to transfer values from one loop
iteration to the next. Shift registers are
similar to static variables in text-based programming
languages.
A shift register appears as a pair of terminals,
shown in 1, directly opposite each other on
the vertical sides of the loop border. The right terminal
contains an up arrow and stores data on the completion of an
iteration. LabVIEW transfers the data connected to the right
side of the register to the next iteration. Create a
shift register by right-clicking the left or
right border of a loop and selecting Add Shift
Register from the shortcut menu.
shift register transfers any data type and
automatically changes to the data type of the first object
wired to the shift register. The data you wire to the
terminals of each shift register must be the same type.
shift register, wire any value
from outside the loop to the left terminal. If you do not
initialize the shift register, the loop uses the
value written to the shift register when the loop
last executed or the default value for the data type if the
loop has never executed.
shift register
to run a VI repeatedly so that each time the VI runs, the
initial output of the shift register is the last
value from the previous execution. Use an uninitialized
shift register to preserve state information
between subsequent executions of a VI. After the loop
executes, the last value stored in the shift
register remains at the right terminal. If you wire the
right terminal outside the loop, the wire transfers the last
value stored in the shift register.
shift register to a
loop. If you have multiple operations within a loop, use
multiple shift registers to store the data values
from those different processes in the structure. The block
diagram in Figure 1 uses two initialized
shift registers.
![]() Figure 1 |
shift register, right-click
the left terminal and select Add Element from the
shortcut menu. Stacked shift registers let you
access data from previous loop iterations. Stacked shift
registers remember values from previous iterations and
carry those values to the next iterations.
shift registers, as shown in Figure 2, can only occur on the left side of the
loop because the right terminal only transfers the data
generated from the current iteration to the next iteration.
![]() Figure 2 |
shift register. The second terminal stores the
data passed to it from the previous iteration, and the bottom
terminal stores data from two iterations ago.
The Feedback Node, shown in 4,
appears automatically in a For Loop or
While Loop if you wire the output of a subVI,
function, or group of subVIs and functions to the input of
that same VI, function, or group. Like a shift
register, the Feedback Node stores data
when the loop completes an iteration, sends that value to the
next iteration of the loop, and transfers any data type. Use
the Feedback Node to avoid unnecessarily long
wires in loops. The Feedback Node arrow indicates
in which direction the data flows along the wire.
Feedback Node on the
Structures palette and place it inside a
For Loop or While Loop. If you place
the Feedback Node on the wire before you branch
the wire that connects the data to the tunnel, the
Feedback Node passes each value to the tunnel. If
you place the Feedback Node on the wire after you
branch the wire that connects data to the tunnel, the
Feedback Node passes each value back to the input
of the VI or function and then passes the last value to the
tunnel. The Accessing Previous Data
VI exercise contains an example of this behavior.
Comments, questions, feedback, criticisms?
"A full introductory course on programming with LabVIEW."