LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time delay in ForFor Loop

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.  

aputman
Message 11 of 33
(1,339 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.  


Depends on exactly what you are doing.  I just find the Select easier to read since I can see everything.  If I go into "tweak every possible microsecond out of this code" mode, then I will likely switch over to the case structure.  But there are likely a lot bigger fish to get first.


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
Message 12 of 33
(1,324 Views)

@crossrulz wrote:

@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.  


Depends on exactly what you are doing.  I just find the Select easier to read since I can see everything.  If I go into "tweak every possible microsecond out of this code" mode, then I will likely switch over to the case structure.  But there are likely a lot bigger fish to get first.


My first inclination was the case structure, but I think that the Select is cleaner. I had also considered holding the wait time in a shift register and initializing the shift register to 1000 ms then setting it to 0 inside the loop. Still has the overhead of calling the wait function, but eliminates the overhead of the select or case structure.

Message 13 of 33
(1,311 Views)

Hi guys,

Sorry for the misleading information, I have tried to finish what I talked about last week but still couldn't able to do it..

I will repeat the problem again: my problem is that how could I able to add a delay after the first value of each iteration except for the first iteration? Basically, the delays start from the second iteration of the FOR loop. 

Really sorry for the misleading information on the forum, it's a mess...

0 Kudos
Message 14 of 33
(1,284 Views)

Hi AIEXINUK,

 

no wait in the first iteration, but later on?

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 15 of 33
(1,274 Views)

Did you try the suggestions about using a Select function or Case structure?

 

"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."

 

If i = 0

  wait (0)

else

  wait (1000)

aputman
Message 16 of 33
(1,283 Views)

Thanks for your reply.

This is a good idea that @aputman discussed this last week.

But this will delay every value later on. While I'd like to delay only the first value in each iteration which is tricky and hard to me(except the first iteration) 

Like the graph I attached below, if I set D maximum to 50, D minimum to 30, step size to 10, while V max to 1, V min to 0.5, so the delay only happens when the D minimum is 30 (1 sec) except in the first iteration. For now, the delay is only triggered by the 'wait until next multiple'.

delay.PNG

0 Kudos
Message 17 of 33
(1,267 Views)

You have to take that Wait until next ms out of the inner FOR loop.

Message 18 of 33
(1,261 Views)

If I do so, I won't be able to see the change of D.

0 Kudos
Message 19 of 33
(1,245 Views)

OK, it's hard to see in your image but I think that you've got your logic backwards. You want to have your wait time if i=0 and otherwise have it 0.

Message 20 of 33
(1,238 Views)