LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

keep programming running after for loop ends

Hey there,

 

I have attached the vi. file which is programmed inside a for loop so that it will stop after the designated time is reached. It gets info from a lvdt that is attached to the DAQ assistant and also has a xy graph which generates displacement against real time with y corresponding to the lvdt movement and x to real time (in minutes). I have wired a statistics vi express function to the wire going into the y of the xy axis graph for signal so that datas such as max, min, range etc can be extracted from the graph and shown on a number indicator.The datas that are retrieved from the statistics function are values required for a formula that requires other values to output the final answer. The other values cannot be worked out from the lvdt and so requires to be manually input to the system. Thus, the statistic datas are attached to arithmetic functions and number controls and hence the number indicators.

 

This is where I run into the problem. The program will end once the for loop time runs out. But I still need it running after the for loop ends so that the user can manually input numbers into the no. control, which will do its arithmetic stuff with the data from statistics function and output the final result. I have fiddled with the while loop in an attempt to get this to work but to no avail. When I run the program with the 'Highlight Execution' on, the while loop runs first and runs for an eternity until the 'STOP' button is hit. Once the while loop stops, the for loop starts executing. I need this to be the other way round.

 

I dont understand the precendence of while loop over the for loop. What am I doing wrong? Is the while loop even the way to go? Are there ways where part of the for loop can be run after time runs out so that arithmetic and user number inputs can be placed inside the for loop and stopped with a boolean like the while loop?

 

Any help is greatly appreciated.

 

Cheers,

Gurung

 

ps- I am fairly new to this software and navigating through labview is still difficult for me. The only reason I have managed to make this vi. file is by going over numbers of  various vi files posted by other forum users (Can't thank them enough). It would be easier to understand if you could attach a modified vi. file and/or image as its much easier to understand than words 🙂

0 Kudos
Message 1 of 6
(2,899 Views)

Because LabVIEW is a dataflow language, the while loop has to finish executing first before the FOR loop starts since you have an output tunnel from the while loop wired to the FOR loop.  You could add a second while loop with a shfit register so that the user could add values manually.  Even better, you might consider a state machine structure.  Also, try breaking up your code into sub-vis.  Ideally, your code should fit on one screen, without scrolling up/down and left/right. 

 

Edit: you don't really need the first while loop.  You just need a sub-vi with an event case to wait for the user to input the data.

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 2 of 6
(2,894 Views)

@Gurung wrote:

Hey there,

 

 

 

I dont understand the precendence of while loop over the for loop. What am I doing wrong? Is the while loop even the way to go? Are there ways where part of the for loop can be run after time runs out so that arithmetic and user number inputs can be placed inside the for loop and stopped with a boolean like the while loop?

 

 

To expand on your question a bit, I'm not sure what you mean by precedence?  The while loop has no presendence over a For loop, this is dictated by data flow.  It's evident one loop takes presendence over the other simply by the order in which it is wired in your code.  Since I can't view your code, it's difficult to visualize what's going on, but rarely should you need sequential loops.  If that's the case, consider a different archetecuture such as the state-machine or Producer/Consumer design patterns.

If you downcovert your VI (Files>>Save For Previous Version) to 8.2, I can take a look.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 3 of 6
(2,859 Views)

At vt92 mentioned, you really should be using an event structure instead of polling the data.  All you are doing is hammering your processor.  SubVIs would help organize your code more.

 

Just for MoReese, attached is a downconverted copy of the VI.  I went ahead and used diagram cleanup before saving.


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 4 of 6
(2,841 Views)

I have been playing with the case structure for hours and haven't had any success so far with the regards to my original question :mansad:.... An image or the a modified vi. file would be much appreciated please

 

Warm regards,

Gurung

0 Kudos
Message 5 of 6
(2,818 Views)

Just some quick changes, but this might give you some ideas.  Try to make your code more compact (like the attached).  Use Case structure for decision making.  I omitted your For loop.  You can use clusters to clean up your bd and to transfer data more compactly.   The true case will be executed until the time expires.  If this is not exactly what you want play around with it; however, even after the time expires, your while loop will continue to execute; therefore, any needed code you can place in the false case of the case structure.

 

Again, this is just to give you some ideas, it may even be a solution for you, but I do think an Event structure would be a better design for your application.  This will depend on other applications you are running on your PC.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Download All
0 Kudos
Message 6 of 6
(2,803 Views)