LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with repeating while loop

Hi everyone, 

 

I'm busy with making a program with Labview in order to operate a water tank. what it does is this:

a waterreservoir can hold up to 16l of water.When it's empty it wil pump water into reservoir with a speed of 1l/sec( 1 litre per second) now when it reaches 8l the speed will change to 0,5l/sec. When then reservoir is filled with 15l of water, then the pump stops en the water goes away through a pipe with a speed of 1l/sec. When the reservoir has only 1l water, then the pump starts again and the cycle begins again.

I have made this program with labview using 3 while loops and 3 case structures. But the problem is that I can seem to start the whole cycle over again. when it reaches 1l it decrements to 0, -1, -2, etc instead of going to 15 litres again. Is there a way to to repeat the whole code in a while loop?

 

here's a screenshot of how my program works : 

Message Edited by Escatrax on 03-28-2009 06:11 PM
0 Kudos
Message 1 of 14
(3,675 Views)

You make some typical beginner mistakes due to the lack uf understanding of dataflow.

 

Your inner loops can never stop (unless stop is TRUE at program start), because the stop button is in the outer loop. The inner loops never read the updated stop value, just the stale value from the input tunnel. Your stop button must be in the innermost loop so the code reads it at every iteration. Any of your inner loops, once started, will go on forever, trapping the code.

 

If you attach your code we can give further advice. All you need is a single while loop and a single shift register of the tank value. Add a few small case structures to change mode depending on the state of the tank. Don't overcomplicate things. 😉

 

See how far you get.

Message 2 of 14
(3,669 Views)

Your first problem is that you have endless while loops.

 

 Assuming that the Stop button hasn't been pressed before you start your VI, it would be false.  The inner most while loop will run continuously because the stop terminal is false, and there is never a way for it to change because the stop button won't be read again unless the outer while loop iterates.  You have a catch 22.

 

In reality, if you want the innermost while loop to stop when you hit zero, that should be the condition you check and wire to the inner while loop stop terminal.  Likewise for the middle while loop.

 

What are you trying to do with all these while loops?  It looks like you want to programmatically make the tank level look like it is going up and down.  But because of the local variables, multiple shift registers, and the multiple while loops (3 layers of while loops and 2 case structures is just way too deep) you really don't have good control over that tank display.

 

What you are doing could probably be done with a single while loop, a couple shift registers, and perhaps a single case structure.  Look up the state machine archtictecture in LabVIEW help and other messages on the forum.

Message 3 of 14
(3,668 Views)

Can't I use 3 shift registers: one for adding 1l/sec, one for adding 0,5l/sec and one for decrementing with 1l/sec?

 

I don't quite understand how you can only use 1 shift register unless you can put the shift register in those case structures.

 

Sorry for asking noob question, I'm only using labView for a month now, but thanks for helping me out. 

Message Edited by Escatrax on 03-29-2009 03:50 AM
0 Kudos
Message 4 of 14
(3,644 Views)

Hello escatrax,

 

here an exemple of what could be done, based on state machine structure .

have a look on different existing structures it could save a lot of time an nrj 

 

http://zone.ni.com/devzone/cda/tut/p/id/3024

 

a description is missing in your statement : what is done when starting your systeme at V = 3L, 10L  ?     

 

 fill up to 15L  or emptiyng ?

 

Best regards

 

Tinnitus
CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
Download All
Message 5 of 14
(3,634 Views)

 


tinnitus wrote: 

Hello escatrax,

 

here an exemple of what could be done, based on state machine structure .

have a look on different existing structures it could save a lot of time an nrj 

 

http://zone.ni.com/devzone/cda/tut/p/id/3024

 

a description is missing in your statement : what is done when starting your systeme at V = 3L, 10L  ?     

 

 fill up to 15L  or emptiyng ?

 

Best regards

 

Tinnitus

 

 

 

It could be both. In this program I want to start at 0, so let's say the reservoir has no water in the beginning. So the pump starts to pump at a speed of 1l/sec and if it reaches for example 3l then it still pump water untill reservoir has 15 l of water. BUT when the water reservoir has 8l water, then it will pump water much slower( at a speed of 0,5l/sec) untill it becomes 15l. When it reaches 15l then the water goes way at a speed of 1l/sec . when the reservoir has only 1l of water left then it starts to pump water again at a speed of 1l/sec untill becomes 8l , etcetc. 

 

0l ==(+ 1l/sec)==> 1l(*) ==(+1l/sec)===>8l ==(+0,5l/sec)==>15l ==(-1l/sec)===>1l==>(*) 

(*) =loop 

So the problem that I'm having is to restart to whole cycle when the waterlevel reaches 1l. That's where I'm stuck.

0 Kudos
Message 6 of 14
(3,630 Views)

???

 

did you try vi i sent ?

 

 

 

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
Message 7 of 14
(3,628 Views)

oo, sorry I forgot

 

thanks, I'm going to check it out and I'm going to let you know if it worked.

 

thanks alot! 

0 Kudos
Message 8 of 14
(3,616 Views)

Hi, I've just tested it, and it works fine, thx alot!

 

I also want the stop button to empty the reservoir before stopping the whole program.

Is this also done with a case structure? And do I have to use a Enum constant to perform this?

 

 

Message Edited by Escatrax on 03-29-2009 07:44 AM
0 Kudos
Message 9 of 14
(3,599 Views)

Hello,

 

here is one way i see, i don't say that is the best choice, may be others could give advices

 

enum define the number of state you have in your system  , then with transitions you can order

them or give some conditions to pass from one to other, as i said have a look on tutorial and type state machine in

search function to find more examples. 

 

Regards

 

Tinnitus

 

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
Download All
0 Kudos
Message 10 of 14
(3,585 Views)