From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Time delay in ForFor Loop

Sorry about the image. Here I attached VI which I drop the version to 2017 so maybe you can see the VI.

0 Kudos
Message 21 of 33
(834 Views)

By the way, because it doesn't change anything if I just put the logic delay to the loop, so it would be same if I just connect the 'wait' to the inner for loop, you can just ignore the sequence structure.  😄

0 Kudos
Message 22 of 33
(831 Views)

I'm trying to understand what you want to do. You want to delay the inner loop after the first iteration each time? If so then you need to put your delay in the inner loop. But you're already delaying (potentially) the inner loop with the Wait for next ms. Do you want an additional delay for the first iteration?

Message 23 of 33
(813 Views)

Yes, I'd like to have another delay in the inner loop but not only for the first iteration. As you can see what this program does now is that it will delay 1 more sec when the D indicator reaches 70, let's say 30,1sec,40,1sec,50,1sec,60,1sec,70,2sec until it goes to 30 in the next iteration. What I'd like to achieve is that delay 2sec in every iteration when it reaches 30 after the first iteration rather than 2sec when it's 70. So now it would be 30,1sec, 40,1sec, 50,1sec, 60,1sec, 70,1sec, 30,2sec, 40,1sec, 50,1sec, 60,1sec......

Sorry for the confusion and thanks a lot for your patience.

0 Kudos
Message 24 of 33
(799 Views)

Hi AIEXINUK,

 

So now it would be 30,1sec, 40,1sec, 50,1sec, 60,1sec, 70,1sec, 30,2sec, 40,1sec, 50,1sec, 60,1sec......

You really need to learn how to express simple logic dependencies!

 

You already learned about the Select function in previous posts.

So I guess a simple hint is enough for now:

IF i>0 AND x==30
   THEN wait(2s)
   ELSE wait(1s)
ENDIF

"i" is the iterator of the outer FOR loop…

Best regards,
GerdW


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

Additional hint - this logic has to be in the inner loop.

Message 26 of 33
(782 Views)

@aputman wrote:

Wouldn't it be better to use a case structure with no wait function rather than a 0ms wait?  You probably won't notice a difference but a wait of 0ms does force the thread to give up control of the CPU.  


That is a good thing and allows other parallel processes to do their thing. Almost any loop short of a "crunch these number the rest of the code be damned" should at least included a "0 ms Wait" to allow other threads to update.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 27 of 33
(766 Views)

Thanks for your answers. It works.

However, If I type the values in the front panel, sometimes it will have a 2sec delay when it reaches the minimum, sometimes it doesn't. And when I click highlight execution, it shows that it has 2sec delay every time.

0 Kudos
Message 28 of 33
(746 Views)

Hi AIEXINUK,

 

If I type the values in the front panel, sometimes it will have a 2sec delay when it reaches the minimum,

Please define "sometimes"…

 

The code runs fine for me (you should have learned about the Ramp function until now):

check.png

The longer wait occurs not in the first iteration of the outer loop…

Best regards,
GerdW


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

Change your logic just a bit. You really want x==Dmin. This only occurs when i=0 on the inner loop. Also, you should be using the Wait (ms) function, not the Wait until next ms Multiple function. Finally, change the datatype for your wait times to U32 to match what is expected by the Wait function.

 

Edited to add: Looks like GerdW beat me to the punch.

Message 30 of 33
(734 Views)