LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Resetting the shift register

Hi,

Is there any way to clear a shift register after running a VI, or just before running the VI? I have a VI that uses a shift register to produce an incrementing set of values for one part of a data array that I'm exporting, but unless I completely shut down the whole VI and reload it the shift register starts from its previous last value rather than starting from zero when I run it again.

Thanks for your help.

Dominic
0 Kudos
Message 1 of 8
(6,034 Views)
You can initialize the shift register to a value you want. If you zero is what you want, create a numeric constant, set it to the appropriate representation and wire it to the left shift register. Also check "shift registers: initializing" under LabVIEW help for additional information.
0 Kudos
Message 2 of 8
(6,034 Views)
"D_Brasted" wrote in message
news:5065000000080000000B800000-1042324653000@exchange.ni.com...
> Is there any way to clear a shift register after running a VI, or just
> before running the VI? I have a VI that uses a shift register to
> produce an incrementing set of values for one part of a data array
> that I'm exporting, but unless I completely shut down the whole VI and
> reload it the shift register starts from its previous last value
> rather than starting from zero when I run it again.

The solution you're looking for is probably to initialize the shift
register.

You probably want to wire a numeric constant 0 outside of the loop as input
to the shift register. It will be initialized to that value. As you see, an
uninitialized shift registe
r is unpredictable just like an uninitialized
variable in other languages. You'll get zero, null, or the value from a
previous run depending on the datatype and state of your program.

-joey
Message 3 of 8
(6,034 Views)
Thanks for the replies, but my for loop with the shift register is itself in a for loop, and if I wire the zero constant, the shift register reinitialises to zero on every iteration and so the counter I'm using it for doesn't work.

Please see the attached JPEG for a picture of my code without wiring the zero constant. This code works for the first run of the VI, but not if I run it again.

Dominic
0 Kudos
Message 4 of 8
(6,034 Views)
Create an initialized shift register on the outer loop and wire it to the shift register of the inner loop.


LabVIEW, C'est LabVIEW

0 Kudos
Message 5 of 8
(6,034 Views)
Two things about your code. First, the inner for loop doesn't have any real function because it will only execute 1 time. Remove the inner loop move the shift register to the outer loop, initialize it to 0 and you should be good to go.

Second, never pass reference numbers through a for loop the way you are doing. The problem is that a for loop can execute zero times (in this case if the array you are auto indexing on is empty). Because of this feature, the reference on the right side will be invalid because the loop hasn't executed and LV doesn't know what its value should be. The result will be errors arising in any VIs after the loop that depend on the reference. For this reason, always pass reference numbers through for loops using shift registers. The
n even if the loop executes zero times, the reference on the right side will always be valid

Mike...

PS: Oh yes, third, errors arising in this routine are not being sent anywhere or displayed.

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 6 of 8
(6,034 Views)
> Is there any way to clear a shift register after running a VI, or just

You already have several responses, but to be complete, there are two
places to write to a shift register -- the left outer terminal, and the
inner right terminal. If the loop is only entered once, then you can
clear it on the left outside each time the loop is run, since that will
be just once per run. If the loop is entered many times, then you
either need to have additional loops around the shift register such that
one of them gets entered only once. Or, if the inside of the loop is
written correctly, it can run through once and prime the right inner
shift register, then subsequent iterations run the loop with the normal
code, and a similar thing can happen with the las
t iteration.

Greg McKaskle
Message 7 of 8
(6,034 Views)
Great answer mike, I never thought about the outputs from a for loop being invalid. Thanks for the tip.
0 Kudos
Message 8 of 8
(6,034 Views)