05-09-2013 07:36 PM - edited 05-09-2013 07:41 PM
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
Solved! Go to Solution.
05-09-2013 07:51 PM
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
05-09-2013 08:25 PM
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!!!!!!!!!!!!!!!!!!!!!!
05-09-2013 08:43 PM
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
05-10-2013 12:44 AM
Personally, I prefer to use a single shift register and an array with two elements. Minimizes code clutter. 😄
05-10-2013 08:16 AM
Thanks. We always learn an even better way to do it when altenbach adds his improvements.
Lynn
05-10-2013 08:31 AM
It's the first time I see shift register can also accept data of array....
I feel I learn a lot today!!
Thank you altenbach and also Lynn
05-10-2013 01:57 PM - edited 05-10-2013 01:58 PM
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)