Discussion in "Embedded GSM Development" started by    carlos_10111    Aug 13, 2008.
Wed Aug 13 2008, 06:06 pm
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?

Tue Aug 26 2008, 08:14 pm
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
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


Powered by e107 Forum System



Tue May 21 2024, 02:06 am
Sun May 19 2024, 05:39 pm
Sun May 19 2024, 03:06 pm
Sun May 19 2024, 07:39 am
Sat May 18 2024, 07:28 am
Fri May 17 2024, 06:14 pm
Fri May 17 2024, 10:28 am
Fri May 17 2024, 10:19 am