Friday, 24 June 2016

TIMER PROGRAMMING

TIMER PROGRAMMING
(Toggle LED using timer programming ON time delay greater than 3 times OFF time delay)
v What is timer?
Timer is a clock that controls the sequence of an event while counting in fixed intervals of time. A Timer is used for producing precise time delay. Secondly, it can be used to repeat or initiate an action after/at a known period of time. This feature is very commonly used in several applications. An example could be setting up an alarm which triggers at a point of time or after a period of time.
v Types of timer?
Two types of timer in 8051
Ø  Timer0
Ø  Timer1


Timer0 register



D15
D14
D13
D12
D11
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0


Timer1 register



D15
D14
D13
D12
D11
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0


TMOD register
GATE
Timer/counter
M1
M0
GATE
Timer/Counter
M1
M0

GATE
Gate=0 Internally run timer
Gate=1 External pin are used for timer run
TIMER/COUNTER
C/T=0 for Timer mode
C/T=1 for Counter mode
MODE

M1
M0
Mode description
0
0
13 bit timer/counter mode
THx= 8 bit
TLx= 5 bit
0
1
16 bit timer/counter mode
THx=8 bit
TLx= 8 bit
1
0
 8 bit auto reload mode
THx=TLx
1
1
Split mode

TCON register
TF1 = Timer1 overflow flag
TR1 = Timer1 run flag
TF0 = Timer0 overflow flag
TR0 = Timer0 run flag

Timer calculation
Clock frequency of atmel microcontroller = 11.0592 MHZ
Time period =1/11.0592
Time period = 1.085 microsecond
For 5 ms second delay generate
                             =5 ms/ 1.085 us
                             =4608
For TH and TL value = 65536 – 4608
                               = 60927
60927 convert into hex value = EDFFh
TH=EDh
TL=FFh               


No comments:

Post a Comment