How can I introduce a delay between 2 operation. I mean something like that: instruction/operation/line code 1;delay some time, for example 100ms; instruction/operation/line code 2
Thank you
The ADL Timer Tick is 18.5ms - that should be fine for a 100ms delay.
Read the Timers section in the ADL User Guide
I think now in the 4.10 you have acces to the HW timer of the platform so maybe you could try it also then it should give 1ms granualrity!!
it is said all over WM slideware!!!
Anyone ever tried?
Hi,
Please find below the code, which can be used to provide a delay as small as 1 millisecond between the execution of two statements:
s32 GetTime(void) {
adl_rtcTime_t time;
s32 milliseconds;
adl_rtcGetTime(&time);
milliseconds = (s32)1000*time.SecondFracPart/32768;
milliseconds += (s32)1000*time.Second;
milliseconds += (s32)(60*1000)*time.Minute;
milliseconds += (s32)(60*60*1000)*time.Hour;
milliseconds += (s32)(24*60*60*1000)*time.Day;
return milliseconds;
}
void OATSleep (u16 msec) {
s32 initial_time;
u16 diff = 0;
initial_time = GetTime();
while (diff<msec)
{
diff = GetTime() - initial_time;
}
}
You can call this function by using OATSleep(1) to provide a delay of 1 millisecond.
Please beware of not providing a long delay (of the range of seconds) as it might kick off the watchdog and the Wireless CPU might reset. For providing big delays use timer APIs.
It must be noted that the above mentioned code would not work in Open AT versions where the adl_rtcGetTime () API is not available.
The above code can be used to get the delay between execution of two statements. You can verify this by creating an Open AT application and then try to call adl_atSendResponse () API two or three times having OATSleep(700) in it. You will see that a delay will be there between the reception of two responses. If you don’t use the OATSleep () API there would not be any delay.
Also, note that this code provides only a delay between the execution of two statements of Open AT Task. Hence, don’t use this function, if you want another task (for e.g. flash task) to be invoked by providing a delay between two statements. To make the Open AT task actually sleep( and facilitate task switch) use the timer API.
Best Regards,
Open AT Fan.
Thank you, this sleep example is helpful for me.
Thank you, OpenAT_Fan! I used your code on a Q24 Classic (Q24CL001) Wireless CPU with Basic OpenAT. It is working perfectly for delays 10ms and 100ms.
Unfortunately, I found that it is not reliable for small delays. I am switching an output port 3x or 10x (in last example) on and off and while doing so, I measure the delays on a scope.
When I use 1ms delays, a lot of times, I will see that the first 1-2 delays are distorted and then the rest looks OK.
[attachment=1]PRINT_03_1ms_bad_start.jpg[/attachment]
[attachment=2]PRINT_04_1ms_starts_short.jpg[/attachment]
But sometimes I can also see distorted delays in other places. I’ve marked those places in the example below.
[attachment=0]PRINT_06b_1ms_errors_after_start_comment.jpg[/attachment]
Does anybody have an idea why this happens?
Best Regards,
Jan
I guess the adl_osclkGetTime ( u64* pTime ) can be used to save on converting time to milliseconds.
My question is, how safe it is to use these delays? For example, I need to perform a set of 10 actions with 5ms delay between them. Evidently, it should take about 50ms for the code to execute. Provided the code is running in main task context and thus has low priority (?), will it be interrupted for OS needs when necessary?