LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a shift register to detect input...

Hi guys,
I'm creating a LabVIEW VI that needs to be able to detect when a user changes an input. I read a previous post that suggested using clusters and shift registers to compare previous data.
My question is how do I use shift registers? I've created a shift register on a for loop, but I'm not sure when to compare the "previous" data to the "new" data. Do I need to add an element to the left side and compare it there? Is the right side the output? I'm just not sure how it works. An uploaded example would be nice. Thanks.

-Mike
0 Kudos
Message 1 of 8
(4,391 Views)
Mike,
This is probably the simplest approach.
The SR (shift register) on the left is the
"input" and the one on the right is the "output". Adding an element on the left will allow you to see a "history" of the values.
The "previous" data is available on the left SR as soon as the loop iteration starts. So you can compare at anytime until the loop finishes that iteration. What ever you wire to the right SR will go out when the loop finishes that iteration and that will be the "previous" for the next iteration. I attached a VI (I hope) that shows you how this is done using a while loop.
Kevin
0 Kudos
Message 2 of 8
(4,391 Views)
Shift registers are very powerful but difficult to use for the first time.

The shift register you just created has two "arrows", one on either side of the structure. The arrow to the left is the value from the previous (i:th) iteration and the arrow to the right you have to feed with the (i+1)th value.

Now, if you want to compare values and look for a change you can compare your old value (the one coming out from the left) with the new value in your for loop. The feed your new value to the right arrow so that it becomes the old value for the next iteration.

If you have many parameters to compare, clusters are very useful since they make things very compact. If you are comparing clusters, do not forget to change the setting on the comparison to compare aggregates (r
ight click on it and select that option).

Also, in most cases you need to set the initial (start) value for your shift register. This is done by feeding the left arrow with the default value from the outside of your loop.

I attached a simple example, CompareSettings.vi, that shows how it works. Hope this helps. /Mikael"
0 Kudos
Message 3 of 8
(4,391 Views)
While-loop
________________________________
| |
| Input----\-------------------| |
| = ----------- | |
|SR------------/ | |---SR|
| | |
| [ Stop ] |
| [ i ] |
|_______________________________|

Hope this helps. You should insert a delay of 50ms to keep cpu-load low.
Philipp
0 Kudos
Message 4 of 8
(4,391 Views)
I've read all the answers to your question, and they all have merit. I have a subvi that I use. It compares a value to it's previous values, and outputs a true when it has changed.

The inputs can be a boolean array, a numeric array, or a string array, and will report if any item in the array has changed. If you just have a single numeric, boolean, or string, wire that into a create array VI, then the output to the subvi input. Only one input can be used per call.

The subVI is reentrant. Therefore, since it is stored in a different memory location for each call, the shift registers which hold the last values are unique to each subVI; therefore, you can use it many times in a single VI with different inputs.

Finally, there is an iteration input. Upon t
he first iteration, a True is output. (This can be changed from within the VI).

Check it out.

Mark
0 Kudos
Message 5 of 8
(4,391 Views)
With LabVIEW 6 you can use the Variant datatype for this VI. It will adapt
to whatever datatype you wire at the input.

Jean-Pierre Drolet
Scientech R&D

"markwysong" a écrit dans le message news:
50650000000500000056360000-993342863000@exchange.ni.com...
> I've read all the answers to your question, and they all have merit.
> I have a subvi that I use. It compares a value to it's previous
> values, and outputs a true when it has changed.
>
> The inputs can be a boolean array, a numeric array, or a string array,
> and will report if any item in the array has changed. If you just
> have a single numeric, boolean, or string, wire that into a create
> array VI, then the output to the subvi input. Only one input can be
> used per call.
>
> T
he subVI is reentrant. Therefore, since it is stored in a different
> memory location for each call, the shift registers which hold the last
> values are unique to each subVI; therefore, you can use it many times
> in a single VI with different inputs.
>
> Finally, there is an iteration input. Upon the first iteration, a
> True is output. (This can be changed from within the VI).
>
> Check it out.
>
> Mark


LabVIEW, C'est LabVIEW

0 Kudos
Message 6 of 8
(4,391 Views)
This is true. This VI was developed in LV5.0, so I just left it as is so anyone could view it.

Mark
0 Kudos
Message 7 of 8
(4,390 Views)
I realize you can do this. I developed this VI in LV5.0, so I left it as 5.0 so everyone could view it.

Mark
0 Kudos
Message 8 of 8
(4,390 Views)