LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stuck in a loop

Hi all,

 

I have a VI that will be used to collect data on sump pump life cycle testing. It needs to be able to handle ten cycle tests at a time. Thus far I have been able to set it up to handle one cycle test at a time. So im just trying to expand on that to handle ten at a time.

 

The uploaded file ReadData_new is my attempt at setting up two of these at once. However I think im getting stuck in a loop. When I run my VI I only see first data point and program seems to be stuck (in loop)

 

I have tried a few variations of stop/continue if true but have yet to get the functionality I want. 

 

Thanks in advance for any help and ideas,

 

Andrew

0 Kudos
Message 1 of 6
(3,099 Views)

I suspect that the problem is not so much that it gets stuck, but rather that you only read the voltage from the analog input once. Look at the flow of your code. Inside the main while loop, but outside the inner loops, you read the analog voltage. Then the two inner loops start running. Since the voltage never changes, the cycles never increment and it keeps writing the same values to the file.

 

It would be better to do this properly with arrays, so you can expand to more channels without copying and pasting code multiple times. Then when you want to make changes, you'll only need to make them in one place.

0 Kudos
Message 2 of 6
(3,066 Views)

So basically set my inner loop as  its own VI. Then impliment them as sub VI to a main program?

 

I had thought of this but steered away from the idea because I'm unsure how my sub vi will aquire data from the main vi. (apparently with arrays) 

 

Ill see if I can try it this way.

 

Thanks for the responce.

0 Kudos
Message 3 of 6
(3,061 Views)

Again, the fundamental problem is that your existing code only reads from the analog input once per iteration of the outer loops, and never gets read inside the inner loops. Simply moving the inner loop into a subVI doesn't solve this problem.

0 Kudos
Message 4 of 6
(3,053 Views)

Ture, I see that now. 

 

So then on your last comment you suggested I use arrays. Can you expand on that?

 

I have a 1D array being used to handel my incoming analog channels. Can I somehow then pass that entire array through my program and have it give me a 2D array with my cycles times and counts for each controller?

 

I understand copy and pasting that same innerloop isnt the best / correct way to do it. Im just having a hard time visualizing how your suggesting I do it.  

 

0 Kudos
Message 5 of 6
(3,046 Views)

There are several ways you could approach this. The simplest is to continue with the copy-paste approach but don't use nested loops. Move all the shift registers from the inner loops to the outer loop. Obviously I don't recommend stopping there.

 

The next step is to move all the logic for an individual channel into a subVI. Make that subVI reentrant with pre-allocated clones, because inside it you're using Express VIs that won't work properly otherwise. Then, instead of copying and pasting all the logic to add a new channel, you just add another copy of the subVI and a few more shift registers. This would be reasonable way to go.

 

For further flexibility in the number of channels, you could combine all the matching shift registers into arrays, so that there's an array instead of a value in each shift register. You could then put a single instance of the logic subVI into a for loop, but you would first need to replace the Elapsed Time function with your own code so that the channels would have independent timing.

0 Kudos
Message 6 of 6
(3,020 Views)