SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
Timers of Intel 8051
Ikram R. Qureshi
Instructor: CS-311
Department of Electronic Engineering
Timers
Used For:
l To generate time intervals
l To count an external event
l To generate Baud Rate
8051 Timers
l The 8051 is equipped with two timers
l Both of which may be controlled, set, read, and
configured individually
8052 equipped with three timers
l Works in similar manner as 8051
Intel8051 TIMERS
l Inte8051 has TWO timers (Timer-0 and Timer-1)
l Timer-0
l Two Bytes Wide, Total 16 bits
l Located in SFRs
– TL0-Timer-Low Byte, SFR-Add-8AH
(Not Bit Addressable)
– TH0-Timer-High Byte, SFR-Add-8CH
(Not Bit Addressable)
l Low and High Bytes are not consecutive
bytes
Intel8051 Timers
l Timer-1
l Two Bytes Wide, Total 16 bits
l Located in SFRs
– TL1-Low Byte..SFR-8BH (Not Bit
Addressable)
– TH1-High Byte..SFR-8DH(Not Bit
Addressable)
Low and High Bytes are not consecutive
bytes
8051 timers location
l Timers are located in SFR’s
A Flip Flop used as counter
l One flip-flop have two states 0 or 1
– Need two clock cycle to generate one complete cycle
at the output Q
– Output Q become a clock to the next stage flip-flop
if more FF are cascaded
– While /Q is used to feed the data input.
– Start: (first cycle) 2
nd
cycle
– Clock=high to low Clock=high to low
– Data=Low Data=High
– /Q=high /Q0= low
– Q0=low Q0= high
A Flip Flop used as counter
l Hardware concept
l Three flip can count up to 8
How does a timer count?
l A timer always counts up
l It doesn’t matter whether the timer
is being used as
– a timer, a counter,
– a baud rate generator
How does a timer count? Timer Clock
l Timer needs a pulse to tick (cycle falling edge)
l 8051 clock crystal is used to generate this cycle (pulse)
l Each machine cycle generate one tick
l 12 crystal cycle makes one machine cycle
l 12 MHz crystal generate one tick in 1 micro sec
one machine cycle time t = 12/12MHz = 1 micro second
12MHz crystal
Timer Operation (How does a timer
works?)
l After timer is started, it increment once by each machine cycle
l Timer keep incrementing until it’s register over flows after
reaching to it’s maximum value
l Example:
l Initial value in TH0, TL0= FFFCH.
l By each machine cycle the timer will increment;
from FFFCH FFFDH FFFE FFFF 0000
l Timer over flow flag will be set on the 4th
m/c
TF=1
l Over flow flag set, timer stop working
l Need to restart the timer again
l For 12 MHz System
USING TIMERS TO MEASURE TIME
l How long does a timer take to increment?
l Timer is incremented once by each machine cycle
l With 11.0592 MHz crystal, the timer will be
incremented
frequency = 11.0592 MHz/12 = 921,583 Hz or time/sec
time lapse = 1/921583 = 1.085 micro sec
l If timer has to count 100,00 times, It will take
100,00 x 1.085 micro sec = 0.01085 sec
Timer Registers
l Both bytes of timer registers can be treated as any
other register like R0, A, B
Example of assembly instruction (using direct addressing mode):
l MOV TL0, #55H ;move hex number 55 into low byte of
timer-0
l MOV A, TH1 ;save high byte of timer- into
accumulator
Timer Mode
Register(TMOD)
l Eight bit timer mode register is used to set the
operating modes of both timers
l Located in SFR
l Address 89H, Not bit addressable
– Lower 4-bits are used to set mode of timer-0
– Higher 4-bits are used to set mode of Timer-1
TMOD
l TMOD register bits
l M0 Mode bit 0
l M1 Mode bit 1
l C/T Timer or counter
l ‘Set’ to perform counter operations (C/T=1)
l ‘Clear’ to perform timer operations (C/T=0)
l Gate
l G=1, external hardware to set this bit
cause the timer to start/stop
l G=0, Software instruction may use to
start/stop action by manipulation the TR0
and TR1 bits.(SETB RT1, CLR TR1)
TMOD (89h) SFR
Timer Mode
Register(TMOD)
l Bit M0 and M1 together set the operating mode of
the timer
Both bytes THx and TLx are worked together
Timer Control Register-
TCON
l TCON
l One Byte Wide
l Located in SFRs, Address-88H
l Bit addressable
– This register contains status and control bits
for timer-0 and timer-1(Scrambled)
TCON
l Timer/Counter control register
l Only 4-bits are used for timer function(to start the timer,
overflow flag)
MODE-0
l 13 Bit timer, 5 bits pre scalar
l This mode is there to keep 8051 compatible with its
predecessor 8048. (No longer it has any good use)
– Lower 5 bits of TLx with 8 bits of THx generate a 13 bits
time action. Upper 3 bits of TLx are not used
– It increments from 0 to 1FFFH then it rolls over to 0000
and set TF flag
– It will increment 8192 times before setting up the overflow
flag
Mode-1
l 16 bits timer
l In this mode both bytes TLx and THx work together
l The timer increments from:
l 0000H to FFFFH ( sixteen bit number = 65535)
l 2^16 = 65536 [from 65535 65536 timer over flow occurs]
Timer Mode -1
l Procedure to set this timer mode
– Clear M1 and set M0 bits in TMOD register( to set mode-1)
– Load TH and TL with initial value, the timer must be started
by setting up the TR0 or TR1 bit in TCON register.
SETB TCON.4 or SETB TR0 for timer-0
SETB TCON.6 or SETB TR1 for timer-1
l Timer will count up from the initial value, till it reach max (FFFFH)
and rolls over to 0000h, at the time of roll over it will set TFx in
TCON register
l By monitoring TFx flag the program control may be directed
l To restart the timer, a) TF must need to be cleared, b) TH, TL need
to be re initialized and c) TR bit need to be set again.
Timer Mode-1 in Action Example
A program to generate square wave on pin #P1.1 with
50% duty cycle. Use timer-1 to control the pulse width.
MOV TMOD, #10H ;set timer-1 to mode-1(M0=1,M1=0)
BAK: MOV TL1, #0F0H ;load initial value in timer-1 low byte
MOV TH1,#0FFH ;load initial value in time-1 high byte
............
The using software is free version, you can upgrade it to the upgrade
version.http://www.allofficetool.com

Mais conteúdo relacionado

Mais procurados

Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counterscjbas
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)Mashood
 
Chapter 16 timers and counters
Chapter 16 timers and countersChapter 16 timers and counters
Chapter 16 timers and countersforgotteniman
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and CountersShreyans Pathak
 
Timer programming
Timer programming Timer programming
Timer programming vijaydeepakg
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND CPIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C raosandy11
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerJay Makwana
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programmingMohamed Ali
 
Microprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and CounterMicroprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and CounterArkhom Jodtang
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programmingAkash Puri
 

Mais procurados (20)

Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
Timers
TimersTimers
Timers
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
8051 timers
8051 timers8051 timers
8051 timers
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)
 
Chapter 16 timers and counters
Chapter 16 timers and countersChapter 16 timers and counters
Chapter 16 timers and counters
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
 
Timers
TimersTimers
Timers
 
Timer programming
Timer programming Timer programming
Timer programming
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND CPIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
 
8051e
8051e8051e
8051e
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
 
Microprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and CounterMicroprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and Counter
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
Timers in Arduino
Timers in ArduinoTimers in Arduino
Timers in Arduino
 
Lpc 1768 timers
Lpc 1768 timersLpc 1768 timers
Lpc 1768 timers
 
12 mt06ped007
12 mt06ped007 12 mt06ped007
12 mt06ped007
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 

Semelhante a 8051 timers--2

lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptHebaEng
 
5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptx5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptxRahultater4
 
6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptx6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptxRahultater4
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptreemasajin1
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxAmoghR3
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptxSujalKumar73
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfSPonmalar1
 
Microcontroller 8051 introduction
Microcontroller 8051 introductionMicrocontroller 8051 introduction
Microcontroller 8051 introductionEngr umar
 
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptxUNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptxGowrishankar C
 

Semelhante a 8051 timers--2 (19)

lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptx5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptx
 
UNIT-5.ppt
UNIT-5.pptUNIT-5.ppt
UNIT-5.ppt
 
6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptx6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptx
 
4.Timer_1.ppt
4.Timer_1.ppt4.Timer_1.ppt
4.Timer_1.ppt
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
 
Uc
UcUc
Uc
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
Class9
Class9Class9
Class9
 
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdf
 
Microcontroller 8051 introduction
Microcontroller 8051 introductionMicrocontroller 8051 introduction
Microcontroller 8051 introduction
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptxUNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
 
Timers of 8051
Timers of 8051Timers of 8051
Timers of 8051
 

Último

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 

Último (20)

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 

8051 timers--2

  • 1. Timers of Intel 8051 Ikram R. Qureshi Instructor: CS-311 Department of Electronic Engineering Timers Used For: l To generate time intervals l To count an external event l To generate Baud Rate 8051 Timers l The 8051 is equipped with two timers l Both of which may be controlled, set, read, and configured individually 8052 equipped with three timers
  • 2. l Works in similar manner as 8051 Intel8051 TIMERS l Inte8051 has TWO timers (Timer-0 and Timer-1) l Timer-0 l Two Bytes Wide, Total 16 bits l Located in SFRs – TL0-Timer-Low Byte, SFR-Add-8AH (Not Bit Addressable) – TH0-Timer-High Byte, SFR-Add-8CH (Not Bit Addressable) l Low and High Bytes are not consecutive bytes Intel8051 Timers l Timer-1 l Two Bytes Wide, Total 16 bits l Located in SFRs – TL1-Low Byte..SFR-8BH (Not Bit Addressable) – TH1-High Byte..SFR-8DH(Not Bit Addressable) Low and High Bytes are not consecutive bytes 8051 timers location
  • 3. l Timers are located in SFR’s A Flip Flop used as counter l One flip-flop have two states 0 or 1 – Need two clock cycle to generate one complete cycle at the output Q – Output Q become a clock to the next stage flip-flop if more FF are cascaded – While /Q is used to feed the data input. – Start: (first cycle) 2 nd cycle – Clock=high to low Clock=high to low – Data=Low Data=High – /Q=high /Q0= low – Q0=low Q0= high A Flip Flop used as counter l Hardware concept l Three flip can count up to 8 How does a timer count? l A timer always counts up l It doesn’t matter whether the timer is being used as – a timer, a counter, – a baud rate generator How does a timer count? Timer Clock l Timer needs a pulse to tick (cycle falling edge) l 8051 clock crystal is used to generate this cycle (pulse)
  • 4. l Each machine cycle generate one tick l 12 crystal cycle makes one machine cycle l 12 MHz crystal generate one tick in 1 micro sec one machine cycle time t = 12/12MHz = 1 micro second 12MHz crystal Timer Operation (How does a timer works?) l After timer is started, it increment once by each machine cycle l Timer keep incrementing until it’s register over flows after reaching to it’s maximum value l Example: l Initial value in TH0, TL0= FFFCH. l By each machine cycle the timer will increment; from FFFCH FFFDH FFFE FFFF 0000 l Timer over flow flag will be set on the 4th m/c TF=1 l Over flow flag set, timer stop working l Need to restart the timer again l For 12 MHz System USING TIMERS TO MEASURE TIME l How long does a timer take to increment? l Timer is incremented once by each machine cycle l With 11.0592 MHz crystal, the timer will be
  • 5. incremented frequency = 11.0592 MHz/12 = 921,583 Hz or time/sec time lapse = 1/921583 = 1.085 micro sec l If timer has to count 100,00 times, It will take 100,00 x 1.085 micro sec = 0.01085 sec Timer Registers l Both bytes of timer registers can be treated as any other register like R0, A, B Example of assembly instruction (using direct addressing mode): l MOV TL0, #55H ;move hex number 55 into low byte of timer-0 l MOV A, TH1 ;save high byte of timer- into accumulator Timer Mode Register(TMOD) l Eight bit timer mode register is used to set the operating modes of both timers l Located in SFR l Address 89H, Not bit addressable – Lower 4-bits are used to set mode of timer-0 – Higher 4-bits are used to set mode of Timer-1 TMOD
  • 6. l TMOD register bits l M0 Mode bit 0 l M1 Mode bit 1 l C/T Timer or counter l ‘Set’ to perform counter operations (C/T=1) l ‘Clear’ to perform timer operations (C/T=0) l Gate l G=1, external hardware to set this bit cause the timer to start/stop l G=0, Software instruction may use to start/stop action by manipulation the TR0 and TR1 bits.(SETB RT1, CLR TR1) TMOD (89h) SFR Timer Mode Register(TMOD) l Bit M0 and M1 together set the operating mode of the timer Both bytes THx and TLx are worked together Timer Control Register- TCON l TCON l One Byte Wide l Located in SFRs, Address-88H l Bit addressable
  • 7. – This register contains status and control bits for timer-0 and timer-1(Scrambled) TCON l Timer/Counter control register l Only 4-bits are used for timer function(to start the timer, overflow flag) MODE-0 l 13 Bit timer, 5 bits pre scalar l This mode is there to keep 8051 compatible with its predecessor 8048. (No longer it has any good use) – Lower 5 bits of TLx with 8 bits of THx generate a 13 bits time action. Upper 3 bits of TLx are not used – It increments from 0 to 1FFFH then it rolls over to 0000 and set TF flag – It will increment 8192 times before setting up the overflow flag Mode-1 l 16 bits timer l In this mode both bytes TLx and THx work together l The timer increments from: l 0000H to FFFFH ( sixteen bit number = 65535) l 2^16 = 65536 [from 65535 65536 timer over flow occurs] Timer Mode -1
  • 8. l Procedure to set this timer mode – Clear M1 and set M0 bits in TMOD register( to set mode-1) – Load TH and TL with initial value, the timer must be started by setting up the TR0 or TR1 bit in TCON register. SETB TCON.4 or SETB TR0 for timer-0 SETB TCON.6 or SETB TR1 for timer-1 l Timer will count up from the initial value, till it reach max (FFFFH) and rolls over to 0000h, at the time of roll over it will set TFx in TCON register l By monitoring TFx flag the program control may be directed l To restart the timer, a) TF must need to be cleared, b) TH, TL need to be re initialized and c) TR bit need to be set again. Timer Mode-1 in Action Example A program to generate square wave on pin #P1.1 with 50% duty cycle. Use timer-1 to control the pulse width. MOV TMOD, #10H ;set timer-1 to mode-1(M0=1,M1=0) BAK: MOV TL1, #0F0H ;load initial value in timer-1 low byte MOV TH1,#0FFH ;load initial value in time-1 high byte ............ The using software is free version, you can upgrade it to the upgrade version.http://www.allofficetool.com