Presentation is loading. Please wait.

Presentation is loading. Please wait.

EET 2259 Unit 6 Shift Registers

Similar presentations


Presentation on theme: "EET 2259 Unit 6 Shift Registers"— Presentation transcript:

1 EET 2259 Unit 6 Shift Registers
Read Bishop, Section 5.3. Exam #1 this week. Lab #6 and Homework #6 due next week. -This week’s big idea is an extension of the loop idea from last week. -Example: Notification.vi from two weeks ago contains a loop with shift regs.

2 Recalling Data From Previous Loop Iterations
When programming with loops, you may need to recall data from previous iterations of the loop. Example: This program generates and displays a new random number each time through the loop. But the program “forgets” each earlier number every time it generates a new one. What if we need to remember the earlier values?

3 Recalling Data From Previous Loop Iterations (Cont’d.)
LabVIEW provides two ways to “give your loops memory” and let them access data from previous iterations of a loop: Shift registers Feedback nodes I recommend not using feedback nodes; use shift registers instead. And definitely don’t use shift registers and feedback nodes in the same program—this gets very confusing. -Sometimes it’s a matter of personal preference whether you use a shift reg or a feedback node. But shift regs are more flexible and powerful.

4 Iteration Counter Provides One Form of “Memory” Within a Loop
Before looking at shift registers, note that the iteration terminal automatically remembers one piece of information, namely, how many times you’ve executed the loop so far. In some cases this is all you need to remember, so you don’t need a shift register. Build and demo program shown.

5 Shift Registers Shift registers transfer values from one iteration of a For Loop or While Loop to the next iteration. To create a shift register, right-click on the left or right border of a loop and select Add Shift Register. (Bishop, p. 227)

6 Shift Registers (Continued)
A shift register appears as a set of arrows on the borders of the loop: an up arrow on the right border, and one or more down arrows on the left border. These arrows are terminals that can be wired to other items inside or outside the loop. (Bishop, p. 228) Shift register

7 Using a Shift Register The terminal on the right border receives and stores a data value as each iteration of the loop finishes. This value then becomes available from the terminal on the left-hand border during the next iteration. (Bishop, p. 228) -Demo by using WHILE loop to generate random #’s, displaying current and previous random #’s. Show how to drag down the left-hand terminal to display more than one previous number.

8 Using a Shift Register (Continued)
The shift register’s initial value is set by wiring the left terminal to a constant or a control or another element outside of the loop. For consistent results, always initialize your shift registers. The shift register’s final value can be used by wiring the right terminal to an element outside of the loop. (Bishop, pp ) -Note how previous example, in which we didn’t initialize shift regs, gives misleading results. Fix this. -Have them save this example as shiftReg.vi.

9 Example Program Write a program that finds the sum of all integers from 0 to 9. (Can easily extend this to find the sum of all integers from 0 to any positive integer). The key is to use a shift register to keep track of the running total as we add each new integer. -For loop with N=10, shift reg + i back into shift reg. -Have them save as runningTotal.vi for future use. -Mention lab exercise that decides whether a voltage is increasing, decreasing, or staying constant; also mention warm-cold guessing game, which we’ll do in a future week.

10 Feedback Nodes Feedback Nodes offer another way to transfer values from one iteration of a loop to the next iteration. Shift registers are more powerful because they can remember as many of the previous values as you want, while feedback nodes can only remember the last previous value. (Bishop, p. 233)

11 Feedback Nodes (Continued)
A Feedback Node appears as an arrow inside a rectangle, along with an associated Initializer Terminal on the loop’s left border. (Bishop, p. 234) Feedback node

12 Converting Between Shift Registers & Feedback Nodes
A Feedback Node can be converted to a shift register (or vice versa) by right-clicking and selecting “Replace with Shift Register” (or “Replace with Feedback Node”). (Bishop, p. 234) Demo by changing shift reg in previous example to a feedback node.

13 Creating Feedback Node by Wiring Output to Input
A Feedback Node will appear automatically if you wire the output of an element or group or elements to the input of that same element or group. Don’t use feedback nodes and shift registers in the same loop.


Download ppt "EET 2259 Unit 6 Shift Registers"

Similar presentations


Ads by Google