LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add to new values to an existing 1D array in a while loop

Solved!
Go to solution
Highlighted

Sounds like an error wiring the connection.  A feedback node should not be involved here.

0 Kudos
Message 11 of 16
(558 Views)
Highlighted

The connection to the shift register?

0 Kudos
Message 12 of 16
(555 Views)
Highlighted

@sgtpppr685 wrote:

The connection to the shift register?


Your code needs a good amount of cleanup imo... and perhaps make some of it into nice looking subVIs.  Also you pretty much should NEVER have a wire running backwards (right to left).  I noticed at least one of them in there.  Always wire in this direction --->

 

Another future tip is to not use your sequence structures in this instance.  You should probably use a State Machine architecture or at least native dataflow.  Theres no reason to have nested sequence structures that make the code much harder to follow (in my, and most people's opinions).

 

But the Shift Register and Feedback Node work similarly -- i.e. you don't need both in your case.  Since you already have the Shift Register wired up, just remove the Feedback Node.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 13 of 16
(552 Views)
Highlighted

Thank you for the advice. Perhaps I will clean it up further once this problem is resolved. 

When I delete the feedback node all my wires break and I cannot reconnect them without the feedback node appearing. any thoughts on why that occurs?

0 Kudos
Message 14 of 16
(547 Views)
Highlighted

@sgtpppr685 wrote:

I am using Labview 2011

I have tried using shift registers and because I exit the loop, a feedback node appears and it seems to be nullifying the array instead of storing the data. Perhaps I just don't understand how to properlyy use a feedback node.

Thank you for all the help so far. I've really been pulling my hair out.


The reason it is automatically adding that Feedback Loop is a result of you wiring up incorrectly in terms of Dataflow. 

 

This is why I highly highly highly demand/recommend you wire exclusively from LEFT to RIGHT.

 

You are trying to use the value from the Array Size that happens inside the while loop to determine the size of the Initialize Array which happens BEFORE the while loop which determines the size.  Confusing... I know.  Do you see the circular logic here?  You are trying to initialize a size before executing your while loop.  But the while loop is a necessity to provide you the size you have wired to initalize the array... This is just flawed programming 😛  No wonder you are having issues with the output.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 15 of 16
(544 Views)
Highlighted
Solution
Accepted by topic author sgtpppr685

Yes, except I thought you wanted to recalculate the average each time through the loop.

The outer loop is the "big project" loop. User decides to perform the process N time.

The inner loop is the process where you collect 5, 10, 20, any number of values. In your outer loop you are using the "plus sign" version of the adder. Look at the thickness of the wire going into the adder (triangle with plus sign) It is a THICK array wire. So, you are not adding a single value to a single value, you are adding two complete arrays, element by element.

Look at the thickness of the wire coming out of the index control (square with "i" under 5 DAQ samples taken here)  That is a thin single value wire.

That thin wire will be zero, then 1, then 2, then 3, then 4 and because of auto indexing in the for loop, all of those values will be passed out, as a length 5 array, when the loop finishes, and given to the adder control. (Not what you want.)

Assuming that you actually want the values captured from the DAQ, 5 times in a row, you can either add up 5 single values, or use the "sigma" "sum array" operator, just one time, after you have the entire array.

GoodLoopSnippet.png

Message 16 of 16
(513 Views)