LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested loop using outer loop iteration as counter

Solved!
Go to solution

Hi everyone.  I have a while loop where I perform calculations at every iteration and display them on the front panel.  Then, at a random loop iteration (here designated as i=9 for testing) it triggers an event where which performs new calculations on x number of iterations (iterations of the outer while loop) of the result of the outer calculations, while simultaneously performing and displaying the outer while loop calculations.  That is the two math algorithms are in sync in iterations.  After x iterations the program then returns to only calculating and displaying the while loop calculations using the updated value from the shift register, until another event is triggered (I did not show another event trigger in the sample code)  I just cannot figure out a way to trigger an event and simultaneously do both calculations with the same loop iterations.  Any suggestions?  

0 Kudos
Message 1 of 9
(5,846 Views)

So you want the code in the true case to execute on i=9 through i=9+10? The way you have it the code will only execute on i=9. You need to check if i is in the range you want using in range and coerce or some other code. But I think I don't understand your question.

=====================
LabVIEW 2012


0 Kudos
Message 2 of 9
(5,838 Views)

Something along these lines?  You are confusing me a little by talking about events.

My numbers are not correct, but I'm sure you can figure it out.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(5,836 Views)

Sorry for the confusion.  Once triggered, inside the case structure I need to perform say 10 calculations in sync with the calculations running in the while loop, (triggering will be random, will only be true for one iteration then return false).  Then after 10 calculations inside the case structure, turn to false, and continue to calculate and display the while loop.  So say the case structure gets triggered at i=9, then from i=10 to i = 19, calculations are being performed and displayed both inside the while loop and inside the case strcture.  Then at i = 20 return to just calculating and displaying the while loop calculations. 

0 Kudos
Message 4 of 9
(5,827 Views)

I think I understand.  How about this then.  Basically, I have a counter being held in the shift register.  Once the trigger is activated, the counter is reset.  When performing the extra calculations, increment the counter.  Once the counter reaches 10, you will no longer perform the extra calculation.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 9
(5,823 Views)

Thank you this is a good idea, I think it will work.  My code is going to look something like the attached.  My last question is what would be the best way to take in x consecutive data points into the case structure and perform calculations on all of them once they were received?  Could I store each one in an array inside a flat sequence, then once the array is filled somehow transfer to another frame for processing?    

0 Kudos
Message 6 of 9
(5,805 Views)

I would wire the count directly into a case structure.  You can have "0..9" (0 through 9) for one case where you build up the array, "10" for the second case where you perform your measurement, and "Default" which will just pass your previous calculation through.  You will want a shift register for the array and another one to hold your previous measurement.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 9
(5,786 Views)

Hi, I am a little confused how this is going to work.  If I wire the count to the case structure, the frame of the case will change at each iteration, so how can I store each data point in a shift register like this?  I don't see how it can work, can someone clarify?  Thank you. 

0 Kudos
Message 8 of 9
(5,741 Views)
Solution
Accepted by topic author baseball07

The sample VI in crossrulz's previous post should provide the functionality that you are looking for. The while loop acts to iterate through the ten operations that you want to perform and the shift registers will allow it to save those values, as you understand. I believe that crossrulz is referring to shift registers on the while loop surrounding the case structure as shift registers cannot be used on a case structure, as you pointed out.

Ben R.
Aerospace & Defense Test
Solutions Marketer
National Instruments
0 Kudos
Message 9 of 9
(5,704 Views)