Shift Registers
State Retention in Graphical Programs
State retention in graphical programs lets a calculation use information from an earlier update. A running total, for example, needs both the latest increment and the total already accumulated. In LabVIEW, a shift register makes this memory explicit on a loop border. Understanding what it reads, what it writes, and how it starts helps you predict results across iterations and repeated executions.
Read the old state, write the new state
A state is information retained for use in a later calculation. A shift register is a paired set of loop-border terminals that carries a value from one iteration to the next. The left terminal supplies the stored value inside the loop; the right terminal receives the value to retain.
Use the following indexing convention: s0 is the initial state, and iteration k reads sk and writes sk+1. The governing update rule is
Here, xk is the current input and F is the calculation performed during that iteration. LabVIEW loop indices begin at zero, so the first iteration reads s0 and writes s1.
Writing a new value does not replace the old value already supplied by the left terminal during that iteration. The new value becomes available there on the next iteration. After the loop finishes, the right terminal provides the final stored value outside the loop.
For a cumulative mass total, the update is
If m0=1.20 kg and successive increments are 0.30 kg and 0.40 kg, the first iteration writes 1.50 kg. The second reads that value and writes 1.90 kg. Adding each increment to the original 1.20 kg would discard the accumulated history.
Choose the starting state deliberately
Initialize a shift register by wiring a starting value from outside the loop to its left terminal. That value is supplied when execution enters the loop. It is not reapplied at the start of every iteration.
An uninitialized shift register can retain its last value across executions while its VI remains loaded in memory. On first loading, it starts with the default for its data type, such as zero for a numeric value. This behavior is useful when persistence is intentional, but it makes independent runs depend on earlier execution history.
Configuration | Starting state when the loop executes again | Suitable intention |
|---|---|---|
Initialized from outside | The supplied starting value | Restart an independent calculation |
Uninitialized, same VI still loaded | The last retained value | Continue an existing calculation |
Uninitialized, first loading | The data type's default value | Accept the default as the starting state |
Trace and check retained values
A useful trace has four columns: iteration number, state read, current input, and state written. Carry each written value into the next row's state-read column. Keep units consistent throughout the update, and use a numeric representation that can store any required fractional values.
You can retain several quantities using separate shift registers. Each register needs a clear meaning and compatible data types at its paired terminals. When updates depend on several stored quantities, calculate every new value from the incoming states unless the update rule explicitly specifies otherwise.
A single scalar register retains one current scalar state; it does not automatically produce a history of all earlier values. Choose what to retain according to what the next iteration needs.
What to remember
- The left terminal reads the incoming state; the right terminal writes the next state.
- Initialization supplies the starting value when execution enters the loop.
- Uninitialized state can persist while the VI remains loaded.
- Trace incoming and outgoing values separately to avoid iteration-count errors.
Example: Retaining an Energy Total Between Updates
A LabVIEW program records the cumulative energy delivered during a bench test. A floating-point shift register is initialized to 15.0 J, representing energy already delivered before the recorded updates begin. Three iterations receive energy increments of 4.5 J, 6.0 J, and 3.5 J, in that order. Each iteration adds its increment to the left-terminal value and wires the result to the right terminal. Assume no other operation changes the stored total.
a) Find the values read and written during the first two iterations.
Let E0=15.0 J be the initialized state. Each iteration uses the cumulative update
The first iteration reads 15.0 J and writes
The second iteration reads the retained 19.5 J, rather than the original initialization, and writes
The value written in the first iteration becomes the value read in the second iteration. This handoff is what preserves the accumulated energy.
b) Find the value read during the third iteration and the final output after the loop finishes.
The third iteration reads the result written by the second iteration:
It then adds the third increment:
After the loop finishes, the right terminal returns this last written value. The third iteration therefore reads 25.5 J, and the final output is 29.0 J. As a check, the three increments total 14.0 J, which increases the initial 15.0 J to 29.0 J.
c) The program runs again with the same three increments. Find the final output with the initialization wire retained. Compare it with a separate uninitialized version whose register already contains 29.0 J and whose VI remains loaded in memory.
With the initialization wire retained, entering the loop supplies 15.0 J again. The second run therefore gives
For the specified uninitialized version, the starting state is the retained 29.0 J. Its successive written states are
The initialized version returns 29.0 J, while the specified uninitialized version returns 43.0 J. Both retain values between iterations; the difference is the starting state supplied when the loop executes again.
A LabVIEW loop uses an initialized shift register to retain a temperature estimate. Match each connection location to its role during one execution of the loop.
Supplies the starting estimate before the first iteration
Supplies the estimate retained from the preceding iteration, or the starting estimate on the first iteration
Accepts the estimate calculated during the current iteration for retention
Returns the last retained estimate after execution finishes
Left terminal connection inside the loop
Right terminal connection outside the loop
Right terminal connection inside the loop
Wire entering the left terminal from outside the loop
A LabVIEW program tracks the mass in a collection vessel using a floating-point shift register initialized to 0.75 kg. Three iterations add 0.18 kg, 0.24 kg, and 0.16 kg, respectively. Each iteration adds its increment to the value read from the left terminal and writes the result to the right terminal. What final mass leaves the right terminal after the loop finishes? Answer in kg, to two decimal places.