LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem while using shift registers

Solved!
Go to solution

Hello,

 

I have been having a head scracher while using shift registers. When it is like shown in red on the picture (without any constant "0") it works as intended but the size of the output array just adds up every run and I do not want that. But when any constant are given to the shift register input, the outputs are just empty arrays and i do not understand why. I have changed and played around the part shown in green and when constants are given to "N" numbers of the loops the output are not empty but the loops dose not work as intended anymore. If anyone is instrested the way it should work:

Outer Loop: j=1;j++;j=Kal.

Inner Loop: i=j+1,i++,i=Kal.

Inside Inner Loop: Kj-Ki

 

Due to the input array having multiple colums that need to be read during loops the counters are slightly different. I have attached LV2016 version and not older because they were breaking while saving if so. I hope my question is somewhate clear, if not please let me know and Ill try my best to explain.

Screenshot 2023-07-21 163750.png

Looking forward for some answers, cheers,

Diural

0 Kudos
Message 1 of 13
(2,754 Views)

Fun fact about For Loops and Shift Registers:

 

If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype.   That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution. 

 

Just like you just proved for yourself with your example!

 

 

What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015)  Then AUTO index the nested For Loops over the array.  Don't wire anything to the N terminals and you will solve your issues


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 13
(2,746 Views)

So it can be solved by never iterating the loop"0" times and stoping when it gets to 1 ?

0 Kudos
Message 3 of 13
(2,739 Views)

@Diural wrote:

So it can be solved by never iterating the loop"0" times and stoping when it gets to 1 ?


I just edited my reply above with suggestions after inspection of you code.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 13
(2,724 Views)

@JÞB wrote:

Fun fact about For Loops and Shift Registers:

 

If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype.   That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution. 

 

Just like you just proved for yourself with your example!

 

 

What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015)  Then AUTO index the nested For Loops over the array.  Don't wire anything to the N terminals and you will solve your issues


I believe you misspoke.  I'm pretty sure that the behavior is exactly the opposite of what you mentioned.  I believe that if you don't have a shift register - and just a tunnel - what you decribed above happens.  I believe that the way to mitigate what you described above is to use a shift register.  That way, whatever is at the input of the shift register appears at the other side of the FOR loop in case of zero iterations.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 13
(2,673 Views)

@billko wrote:

@JÞB wrote:

Fun fact about For Loops and Shift Registers:

 

If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype.   That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution. 

 

Just like you just proved for yourself with your example!

 

 

What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015)  Then AUTO index the nested For Loops over the array.  Don't wire anything to the N terminals and you will solve your issues


I believe you misspoke.  I'm pretty sure that the behavior is exactly the opposite of what you mentioned.  I believe that if you don't have a shift register - and just a tunnel - what you decribed above happens.  I believe that the way to mitigate what you described above is to use a shift register.  That way, whatever is at the input of the shift register appears at the other side of the FOR loop in case of zero iterations.


That is correct.  If a loop iterates 0 times, outputs of shift registers will be whatever is at the input; outputs of tunnels will be the default for the data type.

0 Kudos
Message 6 of 13
(2,656 Views)

@paul_a_cardinale wrote:

@billko wrote:

@JÞB wrote:

Fun fact about For Loops and Shift Registers:

 

If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype.   That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution. 

 

Just like you just proved for yourself with your example!

 

 

What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015)  Then AUTO index the nested For Loops over the array.  Don't wire anything to the N terminals and you will solve your issues


I believe you misspoke.  I'm pretty sure that the behavior is exactly the opposite of what you mentioned.  I believe that if you don't have a shift register - and just a tunnel - what you decribed above happens.  I believe that the way to mitigate what you described above is to use a shift register.  That way, whatever is at the input of the shift register appears at the other side of the FOR loop in case of zero iterations.


That is correct.  If a loop iterates 0 times, outputs of shift registers will be whatever is at the input; outputs of tunnels will be the default for the data type.


I believe this to be a "brain fart".  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 13
(2,629 Views)

Screenshot 2023-07-22 120744.png

Screenshot 2023-07-22 120657.png

  

Hi eeryone,

 

After quite a bit of forum surfing and labview clicking I have come up with a solution. As stated by your answers having "0" go into the loop's iteration "N"umber it did not work at all so I have changed the algorithm to: (changing the green part of the block diagram)

L1 j=1;j++;N=Kal-1

L2 i=j;i++,N=Kal-j

K(j)-K(i+1)

 

I still did not get what I wanted after I made the block diagram easier (red part) so I found out that even though the inner loop was working as intended thanks to the shift register, it was in repeat due to the outer loop, thus creating another shift register in the outer loop took care of that. As a result I got the "outer loop 2d array", but again this was not want i wanted (blue part). Finally I have cleaned the "empty" parts of the array (yellow part) and as a result I got "cleaned 1d array" part.

 

Cheers,

Diural

0 Kudos
Message 8 of 13
(2,620 Views)
Solution
Accepted by topic author Diural

Your code is incredibly convoluted and you don't need any shift registers at all.

 

  • Kal.# needs to be an integer!
  • Use a concatenating tunnel and don't even create the padded 2D array
  • replacing at -1 is a Noop, so get rid of the while loop and case structure. (Since your elements to remove has a default value of "xxx" instead of an empty string, I wasn't really sure what the purpose was!)

 

see if the attached can give you some ideas.

 

altenbach_0-1690019764255.png

 

Since we no longer create padding, the parts after the loop are probably not even needed. It could be useful if you want to eliminate exactly one element, e.g. "K1 - K4".

 

altenbach_0-1690020153380.png

 

 

Message 9 of 13
(2,613 Views)

@altenbach wrote:

Your code is incredibly convoluted and you don't need any shift registers at all.

 


Compared to what some of my former cow-orkers were able to do, I would peg Diural's code as only moderately convoluted.

0 Kudos
Message 10 of 13
(2,603 Views)