Discussion in "Embedded GSM Development" started by    carlos_10111    Aug 13, 2008.
Wed Aug 13 2008, 06:06 pm
#1
void MSDelay(unsigned int itime)
{
unsigned int i,j;
for (i=0;i<itime;i++)
for (j=0;j<1275;j++);
}



Hi guys, can some one explain this function to me.
I what i need to know, is how do you calculate the delay time in a for loop?
For example if i need a 500ms delay. How did they come up with the 1275 in the function?

Thanx
Tue Aug 26 2008, 08:14 pm
#2
Well its a software delay and probably the coder has tested it on simulator to get this value to generate approximate time delay in ms.

But, There is nothing fixed, if your optimisation settings are different then you wont get the same amount of delay as you expected, so this 1275 probably gonna change. Please do not put enough stress on this.

If you want to play with this code, simply change the optimization settings and you wont get the same delay, this can be checked in simulator.

If this were a timer based routine, then there could be a fixed answer
Wed Aug 27 2008, 12:36 am
#3
the coder has assumed
; (in c) is equivalent to NOP (in asm)

so to calculate a delay of 1 ms. all u need is to find out how many instructions u need to wait..

assuming a crystall of 11.059 Mhz. internally devided by 12 we get = 921583.333333333
i.e in one second uC proccesses instructions so in 1 mS i.e. 1/1000 sec

so a minimum delay of 921.583 instructions is required.. by some hit and trial methods u can easily come somewhere around 1275 mark!!!!..

still it is preferred to use timers for delays.. they are more accurate!

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am