LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed nested while loops

Hi,

 

I want to create a VI using nested while loops. What I want is the outer loop to run for 24hrs and during this run after every 30 minutes it should switch to the inner loop. The inner loop runs for 1 minute, this I am doing with the elapsed time subVI.

 

I tried to use a remainder to check whether the elapsed time for the outer loop is a multiple of 30 minutes, based on the condition being true the inner loop would be started. But since labview measures time in milliseconds the remainder was never zero and thus I was not able to accompolish the needed functionality. I am not very familiar with Labview and I am only just starting off so suggestions of anykind are more than welcome.

0 Kudos
Message 1 of 5
(3,492 Views)

Let me try to restate your description as I might do it --

     I have a task that runs for a minute (either because that's how long it takes, or because after a minute of running, I stop it).  I write this as a VI called "One Minute Task".  I want to run this task every 30 minutes for a total of 24 hours, so I want to run it exactly 48 times.  So my entire program is as follows:

     A For Loop, with a count of 48, inside of which is the One Minute Task sub-VI and a Wait (ms) with 1800000 (30 minutes * 60 seconds/minute * 1000 milliseconds/second) wired to it.  The For Loop will run one loop every 30 minutes, will run 48 times, executing the One Minute Task, as required.

 

Bob Schor

0 Kudos
Message 2 of 5
(3,477 Views)

It is very hard to offer advice on your programming unless you attach your code.  And by that, we mean the actual VI and not just a screenshot.

 

Do you really need two loops?  You can do it all in a single loop.  Inside the while loop you have a case structure that executes the stuff you want to do.  Let the Elapsed time timer determine when 30 minutes has passed and whether the 1 minute interval has passed.  Keep track of things with a shift register and you'll know whether you need to execute the code in the case structure or not.

 

The "Time has Elapsed" output of the 30 minute timer can be used to reset the timer for the 1 minute timer.

0 Kudos
Message 3 of 5
(3,476 Views)

Thanks for the reply. I think I should have given the purpose of the VI as well. I want the outer loop to control feed pump which keeps the feed liquid flowing continously for 24hrs or even longer if required and is stopped only when the inner loop is switched on. The inner loop controls backwash pump which is switched on after every 30 minutes for 1 minute. So using a for loop running 48 times won't provide me the continuous functionality. But I think I can use your idea with a controlled valve, the foor loop can close the valve every 30 minutes and the while loop can run the other pump. But that would not allow to me keep the feed pump running for 24hrs. 

I'll design a VI and then maybe update my post. In the meantime any further inputs are more than welcome.

0 Kudos
Message 4 of 5
(3,459 Views)

You just need to look at a state machine architecture.

 

Various states would be turn on and turn off large pump.  Turn on and turn off backwash pump.  Wait 30 minutes.  Wait 1 minute.  Probably the same state that will wait either 1 or 30 minutes, it just keeps going back to itself until the amount of time has passed.

0 Kudos
Message 5 of 5
(3,435 Views)