From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to make a loop run for specific period of time ?

Solved!
Go to solution

hello !

i'm new to labview and could'nt found how to make a loop run for 2 sec for example, and then to exit.

0 Kudos
Message 1 of 11
(11,144 Views)

You can use a for loop, wire the N terminal (number of iteration) and add a timing function into the loop (wait until next (ms) multiple)

Rodéric L
Certified LabVIEW Architect
Message 2 of 11
(11,142 Views)
Solution
Accepted by topic author hookso

Hi Hookso,

 

You can do it using the different loops like While loop and For Loop. Roderic has already stated how to do it using a for loop. I have illustrated in the attached vi how to do it using a while loop and Elapsed Time function. Take a look.


Regards,

Nitzz

(Give kudos to good Answers and Mark it as a Solution if your problem is Solved;)) 

Message 3 of 11
(11,129 Views)

Assuming that you want to put other code in the loop, you could use the elapsed time VI and wire the loop termination to the timer, or open it and look at how it works then base your own code on it

 

elapsed time.png

 

Or you could look at timed structures (sub palette in structures). It depends on how you intend to use the delay. Any more info?

_____________________________
- Cheers, Ed
Message 4 of 11
(11,126 Views)

The right answer here is it depends on what you are going to do. I think I would use something like this:

 

Example_VI_BD.png

 

In this example you never get caught in the loop. It checks every time it executes to see if the time limit has been met. If you use the other methods suggested above you will get hung in the code. When the for loop executes there is no way to get out until it is done. You would have the same problem with the elapsed time vi. In the example that I am showing you could add a stop button and you could hit it and exit from the code at any time.

Tim
GHSP
Message 5 of 11
(11,110 Views)

This is an old way.

 

 

0 Kudos
Message 6 of 11
(11,096 Views)

Does anybody know what VIs he is using in this example? I can't seem to find them in the quick drop list. This does exactly what I need mine to do but not sure which functions he used.

0 Kudos
Message 7 of 11
(3,728 Views)

Look in the timing palette.

Tim
GHSP
0 Kudos
Message 8 of 11
(3,722 Views)

@aeastet wrote:

The right answer here is it depends on what you are going to do. I think I would use something like this:

 

Example_VI_BD.png

 

In this example you never get caught in the loop. It checks every time it executes to see if the time limit has been met. If you use the other methods suggested above you will get hung in the code. When the for loop executes there is no way to get out until it is done. You would have the same problem with the elapsed time vi. In the example that I am showing you could add a stop button and you could hit it and exit from the code at any time.


Why would using the Elapsed Time vi be any different than what you have written? You check for elapsed time every time through the loop. If time has not elapsed then you go through the loop again. While I suspect the FOR loop option is not what the OP is looking for you could also add a conditional terminal to it so that you could get out of the loop if necessary.

 

Edited to add: OOPS, just noticed that this was a 9 year old thread that had been resurrected.

0 Kudos
Message 9 of 11
(3,700 Views)

@johntrich1971 wrote:
Edited to add: OOPS, just noticed that this was a 9 year old thread that had been resurrected.

Yup!

 


@johntrich1971 wrote:
Why would using the Elapsed Time vi be any different than what you have written?

 

I probably would use "tick count" or "high resolution relative seconds". The "elapsed time" express VI is, first of all, an "express VI". It has five inputs and eight (!!) outputs and logic to auto-reset, etc. Seems like overkill for that. 😉

0 Kudos
Message 10 of 11
(3,672 Views)