LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make a while loop wait 10 seconds before iterations?

I am using labview to for an osmosis system that measures the amout of water lost from the reading on a scale.  

I currently have the program displaying the data from 3 scales every second.

I also need to calculate the flux through the membrane over time.

I do this with a function that takes a change in the scale reading over time (with a shift register) followed by a series of mathematical conversions.

The readings from the scale display OK every second, but I need to have at least 10 seconds between flux calculations.

So my question is, how do I make a the shift register take one value from the scale, then wait 10 seconds before taking the second value?  That way I have the mass of water lost over a 10 msecond period.  

Below is my current while loop for Flux using shift registers from data from 3 scales.  

Any helkp would be great!

Also, I'm new at LabVIEW...

Flux Diagram.png

0 Kudos
Message 1 of 12
(5,886 Views)

I can't see the rest of your program but I am guessing you want the inner loop to run once every 10 seconds and your outter loop is now running once per second?

 

If that is so the the eaisy way would be to do something like this 

 

loop.png

 

The inner loop only runs once every ten seconds.

========================
=== Engineer Ambiguously ===
========================
Message 2 of 12
(5,869 Views)

Why do you need the inner loop? Just as a scaffold for the shift registers? Seems wasteful.

 

You can easily place the shift registers in the outer loop or use feedback nodes instead. And yes, just place the occasional parts in a case structure to bypass it when not required.

 

Also why do you have all these duplicate operations? Why do you need all these duplicate diagram constants? One each is probably enough! You can branch the wire. What if you later need to chage the calibration? You would need to make identical changes in three different locations, tripling the chance of mistakes.

 

Building the three values into an array would make the code 3x simpler. That's what I would do.

Message 3 of 12
(5,852 Views)

Do you understand how Dataflow (a key idea behind LabVIEW) works?  If you put a Wait (ms) function (on the Timing Palette) with 10000 (10,000 milliseconds = 10 seconds) inside your While Loop, the principles of Data Flow will require all of the functions inside the While (specifically the Wait function) to finish their execution before the loop can run again.  As everything else in the loop takes approximately 0 seconds, this will make your loop run once every 10 seconds.

 

Bob Schor

0 Kudos
Message 4 of 12
(5,812 Views)

@Bob_Schor wrote:

Do you understand how Dataflow (a key idea behind LabVIEW) works?  If you put a Wait (ms) function (on the Timing Palette) with 10000 (10,000 milliseconds = 10 seconds) inside your While Loop, the principles of Data Flow will require all of the functions inside the While (specifically the Wait function) to finish their execution before the loop can run again.  As everything else in the loop takes approximately 0 seconds, this will make your loop run once every 10 seconds.

 

Bob Schor


I do not think that is a good idea. 

 

The inner loop should be in sync with the outer loop, not run independent on it's own timer.

 

If the inner loop is running independently you run the risk of using stale data.

 

Actually  altenbach is right the inner loop does not need to be a for loop at all, but rather just a case like my suggestion (without the for loop) and the shift registers should be out on the main loop.

 

My suggestion was a quick solution going by what little bit of the block diagram I could see, but if the entire code was posted I am sure we would see where more improvements could be made and possibly even a better solution.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 12
(5,794 Views)

Why would you use the AND?  He'd likely want to readt te value at the start as well.  What benefit are you seeing with the wait?

 

We can offer all sorts of solutions.  But, we would be more useful if we knew what you were trying to do beyonf the little piece you've shown us. That way we can help you choose an architecture

0 Kudos
Message 6 of 12
(5,749 Views)
Thank you all for the comments. I will try RTSLVUs suggestion. Natasftw, I am trying to take one value from the scale, wait 10 seconds, then subtract the new value from the one taken 10 seconds ago. The main outer loop runs at 1 second intervals. I'll revisit this problem next week.
0 Kudos
Message 7 of 12
(5,733 Views)

@natasftw wrote:

Why would you use the AND?  He'd likely want to readt te value at the start as well.  What benefit are you seeing with the wait?

 

We can offer all sorts of solutions.  But, we would be more useful if we knew what you were trying to do beyonf the little piece you've shown us. That way we can help you choose an architecture


Just in case he did not want the first iteration. 

 

Having done similar things myself sometimes I would want the first iteration and sometimes I would not, so I thought I would show the complete idea.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 12
(5,696 Views)

Thank you RTSLVU.  This was exactly what I wanted to do.  I know my code is ugly, but this is my first LabVIEW attempt, so making it work comes before making it elegant.  Thanks again!

0 Kudos
Message 9 of 12
(5,630 Views)

@cmorrow8 wrote:

so making it work comes before making it elegant.


This is a dangerous statement.  Bad habits are much harder to break than good habits are to make.  What "works" likely will break in one of many unexpected ways if put together poorly.  Elegant is often a luxury.  There's a range between that and "it works."  You probably want to spend time in the middle rather than settling for the lowest form of success.

 

Do you have any other programming experience?  If so, would you recommend using while loops inside while loops inside while loops in those languages?  If not, you're not looking at the difference between "just works" and elegant.

0 Kudos
Message 10 of 12
(5,626 Views)