SlideShare a Scribd company logo
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

More Related Content

What's hot

Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
ViVek Patel
 
Timers
TimersTimers
Timers
Vima Mali
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
cjbas
 
8051 timers
8051 timers8051 timers
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 counters
forgotteniman
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
Shreyans Pathak
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
Channabasappa Kudarihal
 
Timers
TimersTimers
Timers
PRADEEP
 
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
 
8051e
8051e8051e
8051e
rupalir
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
Jay 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 programming
Mohamed Ali
 
Microprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and CounterMicroprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and Counter
Arkhom Jodtang
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
Patricio Lima
 
Timers in Arduino
Timers in ArduinoTimers in Arduino
Timers in Arduino
VEDANSH SHARMA
 
Lpc 1768 timers
Lpc 1768 timersLpc 1768 timers
Lpc 1768 timers
PriyangaKR1
 
12 mt06ped007
12 mt06ped007 12 mt06ped007
12 mt06ped007
vijaydeepakg
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
Akash Puri
 

What's hot (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
 

Similar to 8051 timers--2

lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
HebaEng
 
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
Rahultater4
 
UNIT-5.ppt
UNIT-5.pptUNIT-5.ppt
UNIT-5.ppt
Kannan Thangarajan
 
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
Rahultater4
 
4.Timer_1.ppt
4.Timer_1.ppt4.Timer_1.ppt
4.Timer_1.ppt
YashwanthChandra7
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
reemasajin1
 
Uc
UcUc
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
AmoghR3
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
maheswariM7
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
SujalKumar73
 
Class9
Class9Class9
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
Pratik Gohel
 
8051 Timers
8051 Timers8051 Timers
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.pdf
SPonmalar1
 
Microcontroller 8051 introduction
Microcontroller 8051 introductionMicrocontroller 8051 introduction
Microcontroller 8051 introduction
Engr umar
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
BASKARS53
 
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
Gowrishankar C
 
Timers of 8051
Timers of 8051Timers of 8051
Timers of 8051
saravanamanikandan02
 

Similar to 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
 

Recently uploaded

UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
ijaia
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
pvpriya2
 
Unit -II Spectroscopy - EC I B.Tech.pdf
Unit -II Spectroscopy - EC  I B.Tech.pdfUnit -II Spectroscopy - EC  I B.Tech.pdf
Unit -II Spectroscopy - EC I B.Tech.pdf
TeluguBadi
 
openshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoinopenshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoin
snaprevwdev
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
OKORIE1
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
DharmaBanothu
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
Dwarkadas J Sanghvi College of Engineering
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
wafawafa52
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 

Recently uploaded (20)

UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
 
Unit -II Spectroscopy - EC I B.Tech.pdf
Unit -II Spectroscopy - EC  I B.Tech.pdfUnit -II Spectroscopy - EC  I B.Tech.pdf
Unit -II Spectroscopy - EC I B.Tech.pdf
 
openshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoinopenshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoin
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 

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