‎07-18-2019 09:44 AM
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.
‎07-18-2019 10:56 AM
@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.
‎07-18-2019 11:49 AM
@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.
‎07-22-2019 08:05 AM
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...
‎07-22-2019 08:13 AM
‎07-22-2019 08:15 AM
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)
‎07-22-2019 09:14 AM
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'.
‎07-22-2019 09:19 AM
You have to take that Wait until next ms out of the inner FOR loop.
‎07-22-2019 10:19 AM
If I do so, I won't be able to see the change of D.
‎07-22-2019 10:29 AM
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.