04-09-2019 01:26 PM - edited 04-09-2019 01:42 PM
In this simple program, I would like to subtract two double constants 45 and 8.9. Case structures 1 and 2 is used to define the variables, case struct 3 is used to subtract them. The values are passes using a shift register and I expect them to follow the order as per indexing (as shown in Array indicator). However, they seem to have swapped positions resulting in negative answer.
I am trying to pull in the numbers generated in case struct 1 and 2 in case struct #3. By using Add Element to shift registers I assume I am indexing 0th and 1st element in the shift register line pointing to the variables 45 and 8.9.
Why does this happen? What is the logic behind this?
Solved! Go to Solution.
04-09-2019 01:41 PM
You use an expanded shift register and a is i-1 and b is i-2. Looks correct.
04-09-2019 01:44 PM
On the left set of shift register terminals, the upper terminal outputs the previous value. The lower terminal outputs the value before that.
04-09-2019 01:46 PM
The most typical use of shift registers (SR) is to have a single SR on the left side of the loop which will be vertically aligned with the SR on the right side. Whatever you write to the right side on iteration i will come out of the aligned left-side SR on iteration i+1. It is the *most* recent value.
When you expand the left-side SR, it grows in a downward direction. The top SR retains its meaning as the most recently written value. The ones below are values from prior iterations. Basically, this is a visual metaphor for a fixed-size lossy "stack", with the added bonus that you're allowed simultaneous read access to anything in the stack.
So yes, the vertical ordering of the data is opposite to what you'd get from Array indexing, but it's intentional, not an "oops".
-Kevin P
04-09-2019 01:55 PM - edited 04-09-2019 02:04 PM
Some notes:
04-09-2019 02:17 PM
04-09-2019 02:23 PM
My first example was flawed because you don't get the correct array unless you branch inside the case structure. (I would use the array example anyway). Not sure if you need that array.
04-09-2019 02:41 PM
@altenbach wrote:
... (I would use the array example anyway). Not sure if you need that array.
Agreed.
They scale well on the fly.
It has been years since I used a resized SR. When I see one in code they "feel dirty" and I find myself wondering why the developer went that route.
Ben