bladox.com Forum Index bladox.com
Turbo SIM Toolkit Adapter Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Accuracy Delay

 
Post new topic   Reply to topic    bladox.com Forum Index -> Development
View previous topic :: View next topic  
Author Message
gustavo.duarte



Joined: 14 Nov 2012
Posts: 5

PostPosted: Fri Nov 16, 2012 12:51 pm    Post subject: Accuracy Delay Reply with quote

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
View user's profile Send private message
pz



Joined: 12 Mar 2004
Posts: 1161

PostPosted: Sat Nov 17, 2012 3:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
gustavo.duarte



Joined: 14 Nov 2012
Posts: 5

PostPosted: Sun Nov 18, 2012 6:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
gustavo.duarte



Joined: 14 Nov 2012
Posts: 5

PostPosted: Sun Nov 18, 2012 7:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
pz



Joined: 12 Mar 2004
Posts: 1161

PostPosted: Mon Nov 19, 2012 9:02 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bladox.com Forum Index -> Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group