LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with shift register

Solved!
Go to solution

for simplicity purpose, I eliminate non-problematic code

description:
1. my state machines, for some reason, has lots of cases.
2. the order of each case cannot change.
3. the main prupose is to get the difference as shown in the front panel
4. before I get difference, I first take measurement in case 2 and TRY to use shift register to pass data, ideally to case 5
5. however, the 'previous value' is updated too early, the 'get difference' is always ZERO.

e.g
you can see the left side shift register has two elements, ideally, the 'get difference' should display 2-0 = 2.
however, since the second element of the shift register updates too early, my goal cannot achieve and end up with 0 ALWAYS

I believe it is my wrong use of the shift register for multi-case state machine.

I stuck this problem for 4 hours........ kind of stupid but could not figure out

in a mulit-case state machine, how to properly pass data to the DESIRED case (case 5 in this sample code) so that I can get correct calculation

 

OR: since I only care about current value and previous value, is there other ways to get this problem done?

 

thank you

0 Kudos
Message 1 of 8
(2,922 Views)
Solution
Accepted by topic author ivy037

This is a case where Execution Highlighting may be of value. Turn on Execution Highlighting by clicking on the lightbulb on the block diagram toolbar. Then run the VI.  You will see the left side of the shift register change as the state machine goes through states 3 and 4.  By the time it gets to 5 all the data in the shift register is identical.

 

One fix might be to use two shift registers, one for the current value and one for the previous value.

 

Lynn

0 Kudos
Message 2 of 8
(2,914 Views)

This is the most magic line ever, ever ever, ever,ever ever,ever!!!!!!!!!!

 

How many repay do I own you now?!!

 

Thank you very much!!!!!!!!!!!!!!!!!!!!!!

 

Capture.PNG

0 Kudos
Message 3 of 8
(2,905 Views)

Glad to help.

 

While you are feeling good about having something that works, take a few moments to run your VI and mine with the Execution Highlighting turned on. It is a tool that can be useful for debugging and for understanding how things work.  This is a good chance for you to add that to your capabilities.

 

Lynn

0 Kudos
Message 4 of 8
(2,889 Views)

Personally, I prefer to use a single shift register and an array with two elements. Minimizes code clutter. 😄

 

 

0 Kudos
Message 5 of 8
(2,867 Views)

Thanks.  We always learn an even better way to do it when altenbach adds his improvements.

 

Lynn

0 Kudos
Message 6 of 8
(2,857 Views)

It's the first time I see shift register can also accept data of array....

I feel I learn a lot today!!

 

Thank you and also Lynn

0 Kudos
Message 7 of 8
(2,852 Views)

The real advantage of using arrays is scalability. Maybe next month you need to keep the last 20 history elements. In my code, very little needs to be changed but if you use a new shift register for each scalar, things get quicky unmanageable. 😄 What ig you need to keep the last 10000 history elements?

 

(A minor recommended change: You would use "rotate array" instead of "reverse array". Now it works for any size, not just two)

0 Kudos
Message 8 of 8
(2,830 Views)