SlideShare a Scribd company logo
8051 Microcontroller
Timer
Prof. Anish Goel
Embedded Systems
Timer and Counter
Embedded Systems Prof.Anish Goel2
•The microcontroller oscillator uses quartz crystal for its operation.
•As the frequency of this oscillator is precisely defined and very stable, pulses it
generates are always of the same width, which makes them ideal for time
measurement.
•Such crystals are also used in quartz watches. In order to measure time
between two events it is sufficient to count up pulses coming from this
oscillator.
•That is exactly what the timer does. If the timer is properly programmed, the
value stored in its register will be incremented (or decremented) with each
coming pulse, i.e. once per each machine cycle.
•A single machine-cycle instruction lasts for 12 quartz oscillator periods, which
means that by embedding quartz with oscillator frequency of 12MHz, a number
stored in the timer register will be changed million times per second, i.e. each
microsecond.
•The 8051 microcontroller has 2 timers/counters called T0 and T1. As their
names suggest, their main purpose is to measure time and count external
events. Besides, they can be used for generating clock pulses to be used in serial
communication, so called Baud Rate.
Timer T0
Embedded Systems Prof.Anish Goel3
As seen in figure below, the timer T0 consists of two registers – TH0 andTL0 representing
a low and a high byte of one 16-digit binary number.
Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers
it consists of will contain 0. If the timer contains for example number 1000
(decimal), then theTH0 register (high byte) will contain the number 3, while the
TL0 register (low byte) will contain decimal number 232.
Timer 0
Embedded Systems Prof.Anish Goel4
Formula used to calculate values in these two registers is very simple:
TH0 × 256 +TL0 =T
Matching the previous example it would be as follows:
3 × 256 + 232 = 1000
TMOD Register (Timer Mode)
Embedded Systems Prof.Anish Goel5
TheTMOD register selects the operational mode of the timersT0 andT1.As seen in
figure below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 -
bit7) refer to the timer 1.There are 4 operational modes and each of them is described
herein.
Bits of this register have the following function:
GATE1 enables and disablesTimer 1 by means of a signal brought to the INT1 pin
(P3.3):
1 - Timer 1 operates only if the INT1 bit is set.
0 - Timer 1 operates regardless of the logic state of the INT1 bit.
C/T1 selects pulses to be counted up by the timer/counter 1:
1 - Timer counts pulses brought to theT1 pin (P3.5).
0 - Timer counts pulses from internal oscillator.
T1M1,T1M0 These two bits select the operational mode of theTimer 1.
Timer Modes
Embedded Systems Prof.Anish Goel6
This is one of the rarities being kept only for the purpose of compatibility with the
previuos versions of microcontrollers. This mode configures timer 0 as a 13-bit timer
which consists of all 8 bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0
uses only 13 of 16 bits. How does it operate? Each coming pulse causes the lower
register bits to change their states. After receiving 32 pulses, this register is loaded
and automatically cleared, while the higher byte (TH0) is incremented by 1. This
process is repeated until registers count up 8192 pulses. After that, both registers are
cleared and counting starts from 0.
Timer 0 in mode 0 (13-bit timer)
Timer Modes
Embedded Systems Prof.Anish Goel7
Timer 0 in mode 1 (16-bit timer)
Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers TH0
and TL0. That's why this is one of the most commonly used modes. Timer operates in the
same way as in mode 0, with difference that the registers count up to 65 536 as allowable
by the 16 bits.
Timer 0 in mode 2 (Auto-ReloadTimer)
Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit register
for counting and never counts from 0, but from an arbitrary value (0-255) stored in
another (TH0) register.
Timer 0 in Mode 3 (SplitTimer)
Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers.
In other words, the 16-bit timer consisting of two registers TH0 and TL0 is split into two
independent 8-bit timers. This mode is provided for applications requiring an additional 8-
bit timer or counter. The TL0 timer turns into timer 0, while the TH0 timer turns into timer
1. In addition, all the control bits of 16-bit Timer 1 (consisting of the TH1 and TL1 register),
now control the 8-bit Timer 1. Even though the 16-bit Timer 1 can still be configured to
operate in any of modes (mode 1, 2 or 3), it is no longer possible to disable it as there is no
control bit to do it.Thus, its operation is restricted when timer 0 is in mode 3.
Timer Control (TCON) Register
Embedded Systems Prof.Anish Goel8
TF1 bit is automatically set on theTimer 1
overflow.
TR1 bit enables theTimer 1.
1 - Timer 1 is enabled.
0 - Timer 1 is disabled.
TF0 bit is automatically set on theTimer 0
overflow.
TR0 bit enables the timer 0.
1 - Timer 0 is enabled.
0 - Timer 0 is disabled.

More Related Content

What's hot

8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
ATTO RATHORE
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
Channabasappa Kudarihal
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
Aarav Soni
 
Unit 2 mpmc
Unit 2 mpmcUnit 2 mpmc
Unit 2 mpmc
tamilnesaner
 
8086 in minimum mode
8086 in minimum mode8086 in minimum mode
8086 in minimum mode
Sridari Iyer
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
Shreyans Pathak
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
THANDAIAH PRABU
 
8086 signals
8086 signals8086 signals
8086 signals
mpsrekha83
 
Control Memory
Control MemoryControl Memory
Control Memory
mahesh kumar prajapat
 
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
Tarun Khaneja
 
Minimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorMinimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorNikhil Kumar
 
microprocessor architecture
microprocessor architecture microprocessor architecture
microprocessor architecture
Nadeem Hilal Wani
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
ATTO RATHORE
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
ARM Processor
ARM ProcessorARM Processor
ARM Processor
Aniket Thakur
 
Dma and dma controller 8237
Dma and dma controller 8237Dma and dma controller 8237
Dma and dma controller 8237Ashwini Awatare
 
Microprocessor 8086
Microprocessor 8086Microprocessor 8086
Microprocessor 8086
Gopikrishna Madanan
 
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptxLecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
VikasMahor3
 

What's hot (20)

8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Unit 2 mpmc
Unit 2 mpmcUnit 2 mpmc
Unit 2 mpmc
 
8086 in minimum mode
8086 in minimum mode8086 in minimum mode
8086 in minimum mode
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
8086 signals
8086 signals8086 signals
8086 signals
 
Control Memory
Control MemoryControl Memory
Control Memory
 
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
8051 microcontroller lecture ppt by Tarun Khaneja ( 9034406598 )
 
Timers
TimersTimers
Timers
 
Minimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorMinimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 Microprocessor
 
microprocessor architecture
microprocessor architecture microprocessor architecture
microprocessor architecture
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
ARM Processor
ARM ProcessorARM Processor
ARM Processor
 
Dma and dma controller 8237
Dma and dma controller 8237Dma and dma controller 8237
Dma and dma controller 8237
 
Microprocessor 8086
Microprocessor 8086Microprocessor 8086
Microprocessor 8086
 
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptxLecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
 

Similar to 8051 Microcontroller Timer

8051 timer counter
8051 timer counter8051 timer counter
8051 timer counterankit3991
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
vishalgohel12195
 
Timers
TimersTimers
Timers
Vima Mali
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
maheswariM7
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
HebaEng
 
Timers
TimersTimers
Timers
afzal pa
 
Timers of 8051
Timers of 8051Timers of 8051
Timers of 8051
saravanamanikandan02
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
Syed Basharat Hussain
 
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
 
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
 
8051 Timers
8051 Timers8051 Timers
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
reemasajin1
 
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
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
SujalKumar73
 
8051 timer
8051 timer8051 timer
8051 timer
Bkannan2
 

Similar to 8051 Microcontroller Timer (20)

8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
Timers
TimersTimers
Timers
 
Timers
TimersTimers
Timers
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
Timers
TimersTimers
Timers
 
Timers of 8051
Timers of 8051Timers of 8051
Timers of 8051
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
8051 ch9
8051 ch98051 ch9
8051 ch9
 
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
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 
8051e
8051e8051e
8051e
 
Avr timers
Avr timersAvr timers
Avr timers
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.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
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
Uc
UcUc
Uc
 
8051 timer
8051 timer8051 timer
8051 timer
 

More from anishgoel

Computer Organization
Computer OrganizationComputer Organization
Computer Organization
anishgoel
 
Learning vhdl by examples
Learning vhdl by examplesLearning vhdl by examples
Learning vhdl by examples
anishgoel
 
Dot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry PiDot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry Pi
anishgoel
 
Input interface with Raspberry pi
Input interface with Raspberry piInput interface with Raspberry pi
Input interface with Raspberry pi
anishgoel
 
Learning Python for Raspberry Pi
Learning Python for Raspberry PiLearning Python for Raspberry Pi
Learning Python for Raspberry Pi
anishgoel
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
anishgoel
 
learning vhdl by examples
learning vhdl by exampleslearning vhdl by examples
learning vhdl by examples
anishgoel
 
Digital System Design Basics
Digital System Design BasicsDigital System Design Basics
Digital System Design Basics
anishgoel
 
digital design of communication systems
digital design of communication systemsdigital design of communication systems
digital design of communication systems
anishgoel
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
anishgoel
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
anishgoel
 
Serial Communication Interfaces
Serial Communication InterfacesSerial Communication Interfaces
Serial Communication Interfaces
anishgoel
 
Embedded systems ppt iv part d
Embedded systems ppt iv   part dEmbedded systems ppt iv   part d
Embedded systems ppt iv part d
anishgoel
 
Embedded systems ppt iv part c
Embedded systems ppt iv   part cEmbedded systems ppt iv   part c
Embedded systems ppt iv part c
anishgoel
 
Embedded systems ppt iv part b
Embedded systems ppt iv   part bEmbedded systems ppt iv   part b
Embedded systems ppt iv part b
anishgoel
 
Embedded systems ppt ii
Embedded systems ppt iiEmbedded systems ppt ii
Embedded systems ppt ii
anishgoel
 
Embedded systems ppt iii
Embedded systems ppt iiiEmbedded systems ppt iii
Embedded systems ppt iii
anishgoel
 
Embedded systems ppt iv part a
Embedded systems ppt iv   part aEmbedded systems ppt iv   part a
Embedded systems ppt iv part a
anishgoel
 
Embedded systems ppt i
Embedded systems ppt iEmbedded systems ppt i
Embedded systems ppt i
anishgoel
 
Cpld fpga
Cpld fpgaCpld fpga
Cpld fpga
anishgoel
 

More from anishgoel (20)

Computer Organization
Computer OrganizationComputer Organization
Computer Organization
 
Learning vhdl by examples
Learning vhdl by examplesLearning vhdl by examples
Learning vhdl by examples
 
Dot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry PiDot matrix module interface wit Raspberry Pi
Dot matrix module interface wit Raspberry Pi
 
Input interface with Raspberry pi
Input interface with Raspberry piInput interface with Raspberry pi
Input interface with Raspberry pi
 
Learning Python for Raspberry Pi
Learning Python for Raspberry PiLearning Python for Raspberry Pi
Learning Python for Raspberry Pi
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
learning vhdl by examples
learning vhdl by exampleslearning vhdl by examples
learning vhdl by examples
 
Digital System Design Basics
Digital System Design BasicsDigital System Design Basics
Digital System Design Basics
 
digital design of communication systems
digital design of communication systemsdigital design of communication systems
digital design of communication systems
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
Serial Communication Interfaces
Serial Communication InterfacesSerial Communication Interfaces
Serial Communication Interfaces
 
Embedded systems ppt iv part d
Embedded systems ppt iv   part dEmbedded systems ppt iv   part d
Embedded systems ppt iv part d
 
Embedded systems ppt iv part c
Embedded systems ppt iv   part cEmbedded systems ppt iv   part c
Embedded systems ppt iv part c
 
Embedded systems ppt iv part b
Embedded systems ppt iv   part bEmbedded systems ppt iv   part b
Embedded systems ppt iv part b
 
Embedded systems ppt ii
Embedded systems ppt iiEmbedded systems ppt ii
Embedded systems ppt ii
 
Embedded systems ppt iii
Embedded systems ppt iiiEmbedded systems ppt iii
Embedded systems ppt iii
 
Embedded systems ppt iv part a
Embedded systems ppt iv   part aEmbedded systems ppt iv   part a
Embedded systems ppt iv part a
 
Embedded systems ppt i
Embedded systems ppt iEmbedded systems ppt i
Embedded systems ppt i
 
Cpld fpga
Cpld fpgaCpld fpga
Cpld fpga
 

Recently uploaded

一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
AkolbilaEmmanuel1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 

Recently uploaded (20)

一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 

8051 Microcontroller Timer

  • 2. Timer and Counter Embedded Systems Prof.Anish Goel2 •The microcontroller oscillator uses quartz crystal for its operation. •As the frequency of this oscillator is precisely defined and very stable, pulses it generates are always of the same width, which makes them ideal for time measurement. •Such crystals are also used in quartz watches. In order to measure time between two events it is sufficient to count up pulses coming from this oscillator. •That is exactly what the timer does. If the timer is properly programmed, the value stored in its register will be incremented (or decremented) with each coming pulse, i.e. once per each machine cycle. •A single machine-cycle instruction lasts for 12 quartz oscillator periods, which means that by embedding quartz with oscillator frequency of 12MHz, a number stored in the timer register will be changed million times per second, i.e. each microsecond. •The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest, their main purpose is to measure time and count external events. Besides, they can be used for generating clock pulses to be used in serial communication, so called Baud Rate.
  • 3. Timer T0 Embedded Systems Prof.Anish Goel3 As seen in figure below, the timer T0 consists of two registers – TH0 andTL0 representing a low and a high byte of one 16-digit binary number. Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it consists of will contain 0. If the timer contains for example number 1000 (decimal), then theTH0 register (high byte) will contain the number 3, while the TL0 register (low byte) will contain decimal number 232.
  • 4. Timer 0 Embedded Systems Prof.Anish Goel4 Formula used to calculate values in these two registers is very simple: TH0 × 256 +TL0 =T Matching the previous example it would be as follows: 3 × 256 + 232 = 1000
  • 5. TMOD Register (Timer Mode) Embedded Systems Prof.Anish Goel5 TheTMOD register selects the operational mode of the timersT0 andT1.As seen in figure below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 - bit7) refer to the timer 1.There are 4 operational modes and each of them is described herein. Bits of this register have the following function: GATE1 enables and disablesTimer 1 by means of a signal brought to the INT1 pin (P3.3): 1 - Timer 1 operates only if the INT1 bit is set. 0 - Timer 1 operates regardless of the logic state of the INT1 bit. C/T1 selects pulses to be counted up by the timer/counter 1: 1 - Timer counts pulses brought to theT1 pin (P3.5). 0 - Timer counts pulses from internal oscillator. T1M1,T1M0 These two bits select the operational mode of theTimer 1.
  • 6. Timer Modes Embedded Systems Prof.Anish Goel6 This is one of the rarities being kept only for the purpose of compatibility with the previuos versions of microcontrollers. This mode configures timer 0 as a 13-bit timer which consists of all 8 bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0 uses only 13 of 16 bits. How does it operate? Each coming pulse causes the lower register bits to change their states. After receiving 32 pulses, this register is loaded and automatically cleared, while the higher byte (TH0) is incremented by 1. This process is repeated until registers count up 8192 pulses. After that, both registers are cleared and counting starts from 0. Timer 0 in mode 0 (13-bit timer)
  • 7. Timer Modes Embedded Systems Prof.Anish Goel7 Timer 0 in mode 1 (16-bit timer) Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers TH0 and TL0. That's why this is one of the most commonly used modes. Timer operates in the same way as in mode 0, with difference that the registers count up to 65 536 as allowable by the 16 bits. Timer 0 in mode 2 (Auto-ReloadTimer) Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit register for counting and never counts from 0, but from an arbitrary value (0-255) stored in another (TH0) register. Timer 0 in Mode 3 (SplitTimer) Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers. In other words, the 16-bit timer consisting of two registers TH0 and TL0 is split into two independent 8-bit timers. This mode is provided for applications requiring an additional 8- bit timer or counter. The TL0 timer turns into timer 0, while the TH0 timer turns into timer 1. In addition, all the control bits of 16-bit Timer 1 (consisting of the TH1 and TL1 register), now control the 8-bit Timer 1. Even though the 16-bit Timer 1 can still be configured to operate in any of modes (mode 1, 2 or 3), it is no longer possible to disable it as there is no control bit to do it.Thus, its operation is restricted when timer 0 is in mode 3.
  • 8. Timer Control (TCON) Register Embedded Systems Prof.Anish Goel8 TF1 bit is automatically set on theTimer 1 overflow. TR1 bit enables theTimer 1. 1 - Timer 1 is enabled. 0 - Timer 1 is disabled. TF0 bit is automatically set on theTimer 0 overflow. TR0 bit enables the timer 0. 1 - Timer 0 is enabled. 0 - Timer 0 is disabled.