Timer Calculations(TH & TL).
8051 Crystal Frequency - 11.0592Mhz
Timer frequency  =  Crystal Frequency / 1 machine cycle execution oscillator period.
= 11.0592 / 12
= 0.9216 Mhz.
= 11.0592 / 12
= 0.9216 Mhz.
Timer time   = 1 / Timer frequency.
= 1/ 0.9216 Mhz.
= 1.085 microsec.
= 1/ 0.9216 Mhz.
= 1.085 microsec.
Assuming our Timer is selected in Mode 0 
therefore it would be a 13 bit timer ( 8 bit for TH & 5 bits for TL).
Mode 0 : 13 bits.
             : 2^13.
             : 8192.
Max time of timer in Mode 0 =  8192 * 1.085 microsec.
                                              = 8888.32 microsec.
                                              = 8.8 millisec.   
Now lets say we require a delay of 8 millisec.
(1) We can use the timer just once bcoz it has a maximum timer limit of 8.8 millisec.
                                                           or
(2) We can use the same timer 8 times by resetting the timeroverflow flag(TF).
Here we will be moving ahead by using the timer just once.
required delay = 8 millisec.
8 millisec /1.085 microsec   =   7.373 * 10^3  = 7373 .
8192 - 7373  = 819.
So we have to start our timer from 819 to give us a delay of  8 millisec.
Now convert 819 (dec) into binary.
819( Dec ) = 1100110011 ( Binary )
But our timer is of 13 bits so we need to add 3 more bits 
0001100110011  =    00011001     10011 
                                   TH                 TL
TH = 00011001 - 19H.
TL = 10011       -  13H.
Therefore we have to load TH = 0x19;  & TL = 0x13;
to get the required delay of  8 millisec.
Comments
Post a Comment