LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time delay in ForFor Loop

Hi guys,

Appreciate you can look over here.

I have been doing the time delay between my 'For For loop', but I couldn't able to figure out what I want to achieve.

What I'd like to accomplish is making a time delay between each for loop,  let's say wait for 1s after the program reaches the minimum value in the inner For loop, and then the outside For loop starts to run again.

Here I attached the picture of the program since some experts in the forum can not open the LabVIEW 2019. Thanks for your time.

 

0 Kudos
Message 1 of 33
(3,374 Views)

If I understand you correctly, the wait function needs to go outside the inner for loop.  The wait value needs to stay inside the inner for loop.  That will create the necessary dataflow dependency for the wait to occur after the inner loop finishes execution. If you want to wait a full second, you need to use the Wait function, not the Wait until Next MS Multiple.  Depending on the current value of the ms counter when this function is called, you may only get a few ms of delay. 

 

Why are you using local variables for D and V when the control terminals are sitting there not being used at all? 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 33
(3,356 Views)

Hi AIEXINUK,

 

I couldn't able to figure out what I want to achieve.

You should know what you want to achieve… 🙂

 

making a time delay between each for loop, let's say wait for 1s after the program reaches the minimum value in the inner For loop

"Between each loop" is not easy, when the loops are inside of each other: there is no DATAFLOW "between" them…

How do you know the inner loop reaches the "minimum"?

Why do you use so many local variables? Use more wire! (Why are all those terminals unused???)

 

and then the outside For loop starts to run again.

Yes, it does.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 33
(3,350 Views)

Hi,

Thanks for your reply.

 

How do you know the inner loop reaches the "minimum"?

Why do you use so many local variables? Use more wire! (Why are all those terminals unused???)

Because this is only a simulation program for me to try and the 'D minimum, D maximum or V' are some settings of the instrument. So I just created some numeric control in the front panel to represent those settings. 

 

I found local variables are so useful, is there any reason for the users shouldn't use too many local variables?

0 Kudos
Message 4 of 33
(3,337 Views)

If I understand correctly you want to wait 1 s after the inner For loop has completed to go to the next iteration of the outer For loop. If so then the direction that @aputnam gave you should suffice.

 

Instead of posting a screenshot you could save your vi to a previous version and post it. It's much easier to provide help when a vi is available.

Message 5 of 33
(3,329 Views)

I found local variables are so useful, is there any reason for the users shouldn't use too many local variables?


Most definitely yes. Using local variables is a prime cause of race conditions. Local variables break dataflow. They also create a copy of the data for every local variable that you create. Always use a wire where possible.

Message 6 of 33
(3,313 Views)

Hi aputman,

Thanks for your reply.

I just tried your advice, it's interesting and I almost got the result I want!

What the program does now is that the program will wait for 1s after the inner loop finishes execution. But what I'd like to see is that after the first iteration of the inner loop which is the minimum value of D, the program waits for 1s.

0 Kudos
Message 7 of 33
(3,309 Views)

Hi johntrich1971,

Thanks for your reply, I can understand it now.

0 Kudos
Message 8 of 33
(3,307 Views)

@AlEXINUK wrote:

What the program does now is that the program will wait for 1s after the inner loop finishes execution. But what I'd like to see is that after the first iteration of the inner loop which is the minimum value of D, the program waits for 1s.


So the wait should only happen on the first iteration of the inner FOR loop?  I would probably use a simple Select function to choose how long to wait.  If "i" is 0, wait the 1second, otherwise wait 0seconds.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 33
(3,298 Views)

@crossrulz wrote:

@AlEXINUK wrote:

What the program does now is that the program will wait for 1s after the inner loop finishes execution. But what I'd like to see is that after the first iteration of the inner loop which is the minimum value of D, the program waits for 1s.


So the wait should only happen on the first iteration of the inner FOR loop?  I would probably use a simple Select function to choose how long to wait.  If "i" is 0, wait the 1second, otherwise wait 0seconds.


Also, if the 1 second wait must be after the loop runs then you need to use dataflow to force it to run after everything else has run - otherwise it will run in parallel (which may be OK depending on your application).

0 Kudos
Message 10 of 33
(3,293 Views)