Sei sulla pagina 1di 5

Shift Registers

Use shift registers when you want to pass values from previous iterations through the loop to the next
iteration. A shift register appears as a pair of terminals, shown as follows, directly opposite each other on
the vertical sides of the loop border.

The terminal on the right side of the loop contains an up arrow and stores data on the completion of an
iteration. LabVIEW transfers the data stored in the right terminal of the shift register to the left terminal.
The loop then uses the data from the left terminal as the initial values for the next iteration. This process
continues until all iterations of the loop execute. After the loop executes, the terminal on the right side of
the loop returns the last value stored in the shift register.
Create a shift register by right-clicking the left or right border of a loop and selecting Add Shift Register
from the shortcut menu.
A 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.
You can add more than one shift register to a loop. If you have multiple operations that use previous
iteration values within a loop, use multiple shift registers to store the data values from those different
processes in the structure, as shown in the following block diagram.

In the previous block diagram, the upper right shift register terminal transfers 2, the sum of 0 and 2 in the
first iteration, to the upper left terminal as the initial value for the second iteration of the addition operation.
The lower right terminal transfers 2, the product of 1 and 2 in the first iteration, to the lower left terminal

2 and 2
4, to the upper left terminal for the third iteration. The second iteration also
multiplies 2 and 4 and transfers the outcome, 8, to the lower left terminal for the third iteration. After ten
as the initial value for the second iteration of the multiplication operation. The second iteration adds
and transfers the outcome,

iterations, the upper right terminal transfers the final outcome of the addition operation to the upper
indicator and the lower right terminal transfers the final outcome of the multiplication operation to the lower
indicator.
Initializing Shift Registers
Initializing a shift register resets the value the shift register passes to the first iteration of the loop when the
VI runs. Initialize a shift register by wiring a control or constant to the shift register terminal on the left side
of the loop, as shown in the following block diagram.

In the previous block diagram, the For Loop executes five times, incrementing the value the shift register
carries by one each time. After five iterations of the For Loop, the shift register passes the final value, 5, to
the indicator and the VI quits. Each time you run the VI, the shift register begins with a value of

0.

If you do not initialize the shift register, the loop uses the value written to the shift register when the loop
last executed or, if the loop has never executed, the default value for the data type.
Use an uninitialized shift register to preserve state information between subsequent executions of a VI. The
following block diagram shows an uninitialized shift register.

In the previous block diagram, the For Loop executes five times, incrementing the value the shift register
carries by one each time. The first time you run the VI, the shift register begins with a value of 0, which is
the default value for a 32-bit integer. After five iterations of the For Loop, the shift register passes the final
value, 5, to the indicator, and the VI quits. The next time you run the VI, the shift register begins with a

5, which was the last value from the previous execution. After five iterations of the For Loop, the
10, to the indicator. If you run the VI again, the shift register begins
with a value of 10, and so on. Uninitialized shift registers retain the value of the previous iteration until you
value of

shift register passes the final value,


close the VI.
Stacked Shift Registers

Stacked shift registers let you access data from previous loop iterations. Stacked shift registers remember
values from multiple previous iterations and carry those values to the next iterations. To create a stacked
shift register, right-click the left terminal and select Add Element from the shortcut menu.
Stacked shift registers can occur only on the left side of the loop because the right terminal transfers the
data generated from only the current iteration to the next iteration, as shown in the following block diagram.

If you add another element to the left terminal in the previous block diagram, values from the last two
iterations carry over to the next iteration, with the most recent iteration value stored in the top shift register.
The bottom terminal stores the data passed to it from the previous iteration.
Replacing Shift Registers with Tunnels
Replace shift registers with tunnels by right-clicking the shift register and selecting Replace with Tunnels
from the shortcut menu when you no longer need to transfer values from one loop iteration to the next.
If you replace an output shift register terminal with a tunnel on a For Loop, the wire to any node outside the
loop breaks because the For Loop enables indexing by default. Right-click the tunnel and select Disable
Indexing at Source from the shortcut menu to disable indexing and automatically correct the broken wire.

If you want indexing enabled, delete the broken wire and the indicator terminal, right-click the tunnel, and
select Create Indicator from the shortcut menu.
Replacing Tunnels with Shift Registers
Replace tunnels with shift registers by right-clicking the tunnel and selecting Replace with Shift Register
from the shortcut menu when you want to transfer values from one loop iteration to the next. If no tunnel
exists on the loop border opposite of the tunnel you right-clicked, LabVIEW automatically creates a pair of
shift register terminals. If a tunnel exists on the loop border opposite of the tunnel you right-clicked,
LabVIEW replaces the tunnel you right-clicked with a shift register terminal, and the cursor becomes a shift
register icon, shown as follows.

Click a tunnel on the opposite side of the loop to replace the tunnel with a shift register or click the block
diagram to place the shift register on the loop border directly across from the other shift register terminal. If
the shift register terminal appears behind a tunnel, the shift register is not wired.
If you convert a tunnel with indexing enabled to a shift register on a While Loop, the wire to any node
outside the loop breaks because shift registers cannot auto index. Delete the broken wire, wire the output
wire located to the right of the shift register to another tunnel, right-click the tunnel, select Enable
Indexing from the shortcut menu, and wire the tunnel to the node.

Feedback Node
The Feedback Node, shown as follows, operates similarly to shift registers in loops.

Like a shift register, the Feedback Node stores data when the loop completes an iteration and then sends the
stored data to the next loop iteration. The next iteration reads the data, writes a new value to the data, and
sends it through the loop again. This process continues until the loop execution completes.
By default, the Feedback Node stores data from only the previous iteration. However, you can use the
Configuration page of the Properties dialog box to configure the Feedback Node to store samples of data
from multiple subsequent executions or iterations by increasing the number of executions or iterations to
delay the output of the Feedback Node. If you increase Delay to more than one execution or iteration, the
Feedback outputs only the initializer value at each execution or iteration until the delay you specify is
complete. Then on each subsequent execution or iteration, the Feedback Node outputs the values it stored
one at a time and in subsequent order.
Initializing the Feedback Node on Loop Execution
By default, the Feedback Node globally initializes when the VI compiles or loads. If you wire a value to the
initializer terminal, the Feedback Node initializes to that value on the first call of the VI in an execution or
each time a loop executes, depending on whether you leave the initializer terminal on the node or move the
terminal to the left edge of a loop. The following image shows the appearance of the initializer terminal
when you move it to the left edge of a loop.

To initialize a Feedback Node when a loop executes, right-click the initializer terminal and select Move
Initializer One Loop Out or Move Initializer One Loop In from the shortcut menu to move the initializer
terminal. The initializer terminal changes icons, as shown on the loop in the following figure, and the
Feedback Node initializes before the first iteration of each execution of the loop. You must wire an initial
value to the initializer terminal if you move it to the left edge of a loop. If the initializer terminal is on the
edge of the outermost or innermost loop, as in the following block diagram, LabVIEW dims the
corresponding option to Move Initializer One Loop Out or Move Initializer One Loop In in the shortcut
menu.

In the previous block diagram, although the Feedback Node is in the For Loop, the initializer terminal is on
the edge of the outermost While Loop. Thus, the Feedback Node initializes to the input value 2 every time
the While Loop executes, whereas the outcome of the Increment function builds on previous values for each
For Loop execution. Separating the Feedback Node and initializer is useful in nested Case structures when
you want the Feedback Node to execute only in certain cases.
Globally Initializing the Feedback Node
If you do not move the initializer terminal to the left edge of a loop, the Feedback Node globally initializes.
You can use a Feedback Node that globally initializes anywhere on the block diagram. If a Feedback Node
globally initializes and you set an initial value, by default the Feedback Node initializes to that value on the
first call of the VI in an execution. However, you also can set a Feedback Node that globally initializes to
initialize when the VI it belongs to compiles or loads. If you do not wire an input value to the initializer
terminal, the initial input of the Feedback Node for the first execution is the default value for the data type.
Each time the VI runs after the first execution, the initial value is the last value from the previous execution.
The following block diagrams show the differences in value from execution to execution for a Feedback Node
with a wired initializer terminal and a Feedback Node with an unwired initializer terminal.

First Execution

Second Execution

Iteration

End Value

Iteration

End Value

Since the Feedback Node in the previous block diagram reinitializes after the first execution, the values for
each loop iteration from one execution to another do not change. The Feedback Node behaves differently if
you do not wire an initial value to the initializer terminal, shown as follows.

First Execution

Second Execution

Iteration

End Value

Iteration

End Value

In the previous block diagram, the initializer terminal uses 0, the default value for the data type, as the
initial value in the first execution and does not reinitialize the Feedback Node in any subsequent executions.
Although you can separate the node and initializer terminal in loops and nested loops, you cannot move the
initializer terminal outside the set of nested structures that contains the node. You also cannot separate the
node from the initializer terminal when you create a subVI. If you attempt to create a subVI from a section
of the block diagram that contains either the node or the initializer terminal, but not both, LabVIEW returns
an error.
Note You can use the Appearance page of the Properties dialog box to change the appearance of a
Feedback Node to z-transform view, which looks like that of a z -1 block in feedback control theory
and signal processing. Changing the node to z-transform view changes only the cosmetic
appearance of the Feedback Node and does not change the functionality of the node.
Replacing Shift Registers with a Feedback Node
Replace a shift register with a Feedback Node by right-clicking the shift register and selecting Replace with
Feedback Node from the shortcut menu. Replace a Feedback Node with shift registers by right-clicking the
Feedback Node and selecting Replace with Shift Register from the shortcut menu.

Potrebbero piacerti anche