07-18-2019 08:39 AM
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.
07-18-2019 08:53 AM - edited 07-18-2019 08:56 AM
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?
07-18-2019 08:56 AM
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.
07-18-2019 09:10 AM
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?
07-18-2019 09:16 AM
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.
07-18-2019 09:21 AM
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.
07-18-2019 09:24 AM
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.
07-18-2019 09:26 AM
Hi johntrich1971,
Thanks for your reply, I can understand it now.
07-18-2019 09:36 AM
@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.
07-18-2019 09:39 AM
@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).