8051 Microcontroller Delay Calculation Method:
September 17, 2009.Good Job Saad.
Following is a method to calculate the delay subroutines without using timers in the Microcontroller: (Click Here to Download Pdf version for more examples)
|
Delay |
Calculations |
Code |
Remarks |
|
50mS Xtal freq =11.0592MHz |
50mS/1.085uS = 46082.9 |
|
|
|
|
46082.9/255 = 180.7 |
|
Its an Odd Value, so round off the result i.e. 180.7 to the nearest even number i.e 182 |
|
|
46082.9 / x =182 |
|
Find value of x |
|
|
46082.9 / 253 = 182 |
|
We’ll load 253 in the inner most loop |
|
|
182 / 2 = 91 |
|
Always do this, so its result will be our outer loop |
|
|
|
Delay:Mov R0, #91 Here1:Mov R1, #253 Here:DJNZ R1, here DJNZ R0, here1 RET |
|
|
500mS Xtal freq =11.0592MHz |
500mS/1.085uS = 460829.5 |
|
|
|
|
460829.5 / 255 = 1807.1 |
|
Odd number does not account as its not less than 255, innermost loop = 255 |
|
|
1807.1 / 255 = 7.086 |
|
Round off to nearest higher even i.e 8 |
|
|
1807.1 / x = 8 |
|
|
|
|
1807.1 / 226 = 8 |
|
Inner loop = 226 |
|
|
8 / 2 = 4 |
|
Outer loop = 4 |
|
|
|
Delay:Mov R0,#4 Here2:Mov R1, #226 Here1:Mov R2, #255 Here:DJNZ R2, Here DJNZ R1, Here1 DJNZ R0,Here2 End |
|
|
1Second Xtal freq= 20MHz |
1 / 0.6uS = 1.6 x 10e6 |
|
|
|
|
1.6 x 10e6 / 255 = 6536 |
|
Innermost loop= 255 |
|
|
6536 / 255 = 25.6 |
|
Not Even so make it even i.e. 26 |
|
|
6536 / x = 26 |
|
|
|
|
6536 / 251 = 26 |
|
Inner loop 251 |
|
|
26/2 = 13 |
|
Outer loop = 13 |
|
|
|
Delay:Mov R0, # 13 Here2: Mov R1, # 251 Here1: Mov R2, #255 Here: DJNZ R2, Here DJNZ R1, Here1 DJNZ R0, Here2 Ret |
|
