View previous topic :: View next topic |
Author |
Message |
gustavo.duarte
Joined: 14 Nov 2012 Posts: 5
|
Posted: Fri Nov 16, 2012 12:51 pm Post subject: Accuracy Delay |
|
|
Hi all,
We need wait for a short time with milliseconds accuracy. I saw the delay.c example code, and found that the time delay is implemented as:
Code: |
void delayOneUs (void)
{
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
}
|
If I understand well how many calls to __asm__ __volatile__ ("nop"); depends of clock frequency.
My question is how I can know the frequency to set the the time delay with more accuracy.
Thanks in advance. |
|
Back to top |
|
 |
pz
Joined: 12 Mar 2004 Posts: 1161
|
Posted: Sat Nov 17, 2012 3:55 pm Post subject: |
|
|
The problem is that the phone/ME is supplying clock and in general you don't know what freq. It may vary phone to phone. IIRC it's usually something around 3.72MHz. The delayOneUs() is based on this and measured empirically.
So do you need it to be for specific device or in general? For specific you may just try to calibrate such similar loop, in general case you would need some extra device to provide know freq. In TM2 there is a second MCU M168 with own crystal. That could be used somehow. |
|
Back to top |
|
 |
gustavo.duarte
Joined: 14 Nov 2012 Posts: 5
|
Posted: Sun Nov 18, 2012 6:56 pm Post subject: |
|
|
Thanks pz, for your quickly response. The delay is for a specific device, I have to calculate the numbers of NOP empirically, as you suggested.
Regards.
Gustavo. |
|
Back to top |
|
 |
gustavo.duarte
Joined: 14 Nov 2012 Posts: 5
|
Posted: Sun Nov 18, 2012 7:30 pm Post subject: |
|
|
I was modified the numbers "__asm__ __volatile__ ("nop")" in function delayOneUs, however the delay time wasn't changed. In ohter words, call
__asm__ __volatile__ ("nop")
__asm__ __volatile__ ("nop")
made the same result than:
__asm__ __volatile__ ("nop")
Seems that this line no consume clock cycles.
Could be necessary some compilation flags ?
PD: I am compiling over windows environment with Cywing.
thanks. |
|
Back to top |
|
 |
pz
Joined: 12 Mar 2004 Posts: 1161
|
Posted: Mon Nov 19, 2012 9:02 am Post subject: |
|
|
gustavo.duarte wrote: | I was modified the numbers "__asm__ __volatile__ ("nop")" in function delayOneUs, however the delay time wasn't changed. In ohter words, call
__asm__ __volatile__ ("nop")
__asm__ __volatile__ ("nop")
made the same result than:
__asm__ __volatile__ ("nop")
|
Hard to believe. Do "make dis" and look at the disassembled code to see what is really there. And also if you really link against it.
Quote: |
Seems that this line no consume clock cycles.
Could be necessary some compilation flags ?
PD: I am compiling over windows environment with Cywing.
thanks. |
|
|
Back to top |
|
 |
|