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: s0s_0 is the initial state, and iteration kk reads sks_k and writes sk+1s_{k+1}. The governing update rule is


sk+1=F(sk,xk)s_{k+1}=F(s_k,x_k)


Here, xkx_k is the current input and FF is the calculation performed during that iteration. LabVIEW loop indices begin at zero, so the first iteration reads s0s_0 and writes s1s_1.


A stored state enters an update operation and its result becomes the state for the next iteration.


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


mk+1=mk+Δmkm_{k+1}=m_k+\Delta m_k


If m0=1.20 kgm_0=1.20\ \text{kg} and successive increments are 0.30 kg0.30\ \text{kg} and 0.40 kg0.40\ \text{kg}, the first iteration writes 1.50 kg1.50\ \text{kg}. The second reads that value and writes 1.90 kg1.90\ \text{kg}. Adding each increment to the original 1.20 kg1.20\ \text{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 J15.0\ \text{J}, representing energy already delivered before the recorded updates begin. Three iterations receive energy increments of 4.5 J4.5\ \text{J}, 6.0 J6.0\ \text{J}, and 3.5 J3.5\ \text{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 shift-register update passes the stored total through an addition and retains the result for the next iteration.


a) Find the values read and written during the first two iterations.


Let E0=15.0 JE_0=15.0\ \text{J} be the initialized state. Each iteration uses the cumulative update


Ek+1=Ek+ΔEk.E_{k+1}=E_k+\Delta E_k.


The first iteration reads 15.0 J15.0\ \text{J} and writes


E1=15.0 J+4.5 J=19.5 J.E_1=15.0\ \text{J}+4.5\ \text{J}=19.5\ \text{J}.


The second iteration reads the retained 19.5 J19.5\ \text{J}, rather than the original initialization, and writes


E2=19.5 J+6.0 J=25.5 J.E_2=19.5\ \text{J}+6.0\ \text{J}=25.5\ \text{J}.


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:


E2=25.5 J.E_2=25.5\ \text{J}.


It then adds the third increment:


E3=25.5 J+3.5 J=29.0 J.E_3=25.5\ \text{J}+3.5\ \text{J}=29.0\ \text{J}.


After the loop finishes, the right terminal returns this last written value. The third iteration therefore reads 25.5 J25.5\ \text{J}, and the final output is 29.0 J29.0\ \text{J}. As a check, the three increments total 14.0 J14.0\ \text{J}, which increases the initial 15.0 J15.0\ \text{J} to 29.0 J29.0\ \text{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 J29.0\ \text{J} and whose VI remains loaded in memory.


With the initialization wire retained, entering the loop supplies 15.0 J15.0\ \text{J} again. The second run therefore gives


Efinal, initialized=15.0+4.5+6.0+3.5=29.0 J.E_{\text{final, initialized}}=15.0+4.5+6.0+3.5=29.0\ \text{J}.


For the specified uninitialized version, the starting state is the retained 29.0 J29.0\ \text{J}. Its successive written states are


E1=29.0+4.5=33.5 J,E2=33.5+6.0=39.5 J,E3=39.5+3.5=43.0 J.\begin{aligned} E_1&=29.0+4.5=33.5\ \text{J},\\ E_2&=33.5+6.0=39.5\ \text{J},\\ E_3&=39.5+3.5=43.0\ \text{J}. \end{aligned}


The initialized version returns 29.0 J29.0\ \text{J}, while the specified uninitialized version returns 43.0 J43.0\ \text{J}. Both retain values between iterations; the difference is the starting state supplied when the loop executes again.

A LabVIEW loop has a numeric shift register initialized to 8.0 J8.0\ \text{J}. Every iteration adds 2.5 J2.5\ \text{J} to the value read from the left terminal and wires the sum to the right terminal. What value does the left terminal supply during the second iteration?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

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.

Match each term
A.

Supplies the starting estimate before the first iteration

B.

Supplies the estimate retained from the preceding iteration, or the starting estimate on the first iteration

C.

Accepts the estimate calculated during the current iteration for retention

D.

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

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A LabVIEW program tracks the mass in a collection vessel using a floating-point shift register initialized to 0.75 kg0.75\ \text{kg}. Three iterations add 0.18 kg0.18\ \text{kg}, 0.24 kg0.24\ \text{kg}, and 0.16 kg0.16\ \text{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.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice