LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Timed Loop

Solved!
Go to solution

Hello all.  I am trying to write a program for a thermal chamber  Nothing crazy, just want to be able to set run time and hit start.  I want to be able to change the time while unit is running.  Also, after this time is up, I want it to go into a cool-down mode and then stop.

 

I created a for loop with a 1000ms Wait, and created a local variable for the Loop Count, and using a control, set it to 3600000 (1 hour).  When I run, I get into some sort of loop where the Control would change this value of the Loop Count.

 

I tried putting a flat sequence structure, first being Start Unit, second being the dynamic loop, and third cool-down.  Well, the unit would start, loop would start, and then I would just get locked up.  Is there a way to change this dynamically?

 

Thanks,

 

Mike

0 Kudos
Message 1 of 10
(3,667 Views)

Could you share a copy of what you have tried?

0 Kudos
Message 2 of 10
(3,645 Views)

If I understand you correctly, you've set a wait for 1hr in your loop.  That means you'll start the iteration, do all the things, and then sit there for an hour.  

 

Given it sounds like you're trying to read a value from user input, odds are it'll be read at that point... then the code will sit around for an hour.

 

 

0 Kudos
Message 3 of 10
(3,610 Views)

You talk about starting something, doing a bunch of things, sitting around waiting, then going into a cool down cycle.

 

That sounds a lot like a "state machine".  Search the forums and LabVIEW help for examples.

0 Kudos
Message 4 of 10
(3,599 Views)

@LV_Noob wrote:

Well, the unit would start, loop would start, and then I would just get locked up.  Is there a way to change this dynamically?


Sounds to me it does exactly what you programmed.

 

Try turning highlight execution on. You'll see what's happening.

 

When you tell a computer to wait for an hour it will wait for an hour... If you want the computer to wait until a certain time after a certain start time, you have to program that. You'd have to pull in a loop though, as the inputs of the compare might change.

 

0 Kudos
Message 5 of 10
(3,576 Views)

Thank you all for your replies.  I will try and get a copy of the vi uploaded, just need to get it off a remote computer.

 

@RavensFan, you are correct, it is a state machine. 

 

So, to better explain my desired results, I want the user to specify a run time, e.g. 1 hour, and hit Start.  At that point, the 1 hour loop (or however long the user chooses) will start.  But if the user should change their mind in the middle of the cycle, say to extend the cycle to 3 hours, then they will change the run time, and the loop will Automatically be updated to reflect that change without having to stop the current cycle.  I have a Wait within the For Loop set to 1000ms, and 3,600,000 linked to the loop count, 'n', to get the initial 1 hour of run time.  I want the 'n' value to be able to be updated dynamically while the unit is running, if the user changes the run time.

 

Hope this makes sense.  In the mean time, I will try and get that vi uploaded.

 

Thanks,

 

Mike

0 Kudos
Message 6 of 10
(3,551 Views)
Solution
Accepted by topic author LV_Noob

It sounds to me like you are using a for loop and wiring to the N (loop count) from outside the for loop - is that right? 

 

Rather than use a for loop, you need to use a while loop. Check what time it is right before the while loop starts, then check the time within the while loop, subtract them and check if it's greater than your desired run time. That way the run time can update in the middle of the loop. With for loops, you can't increase the loop count once its started.

 

Here, something like this:

loop time check.png

0 Kudos
Message 7 of 10
(3,542 Views)

First, you can't change the N in the middle of the loop, but you don't want to do it that way anyway. You really do need to implement this as a state machine - the program that you're describing will be hung up until your FOR loop completes. Just replacing the FOR loop with a WHILE loop will not get rid of this problem.

0 Kudos
Message 8 of 10
(3,540 Views)

Instead of a state machine, you could go OO and use a state pattern or make a sequencer. Both aren't that hard with OO, if you know the basics. I know what I'd do, but I know the basics Smiley Very Happy.

0 Kudos
Message 9 of 10
(3,510 Views)

@prettypwnie, thank you so much for this.  This is exactly what I ended up doing.  Now time to tackle the other challenges.  🙂

 

Thanks again,

 

Mike

0 Kudos
Message 10 of 10
(3,460 Views)