SlideShare uma empresa Scribd logo
1 de 40
Presented by :
 AKASH GUPTA 111257
 ANKIT SAHA 111340
 Introduction
 TMOD Register
 Modes of Operation
 TCON Register
 Counters
 The 8051 comes equipped with two timers, both of
which may be controlled, set, read, and configured
individually.
 The 8051 timer has three general functions:
 Keeping time and calculating the amount of time between
events.
 Counting the events .
 Generating baud rates for the serial port.
When a timer is in interval timer mode and correctly
configured, it will increment by „ONE‟ every machine cycle.
We have:
1,10,59,000 / 12 = 9,21,583 machine cycles / sec
 The 8051 uses a 11.059 MHz crystal.
 A machine cycle equals 12 clock (crystal) pulses.
Thus the counter increments 9,21,583 times per second.
Thus if a timer has counted from 0 to 50,000 you may calculate:
50,000 / 9,21,583 = .0542 seconds
 The 8051 has 2 timers/counters:
◦ Timer/Counter 0
◦ Timer/Counter 1
 Registers Used in the Timer :
◦ Timer 0 registers:
TH0, TL0
Exclusive
◦ Timer 1 registers:
TH1, TL1
◦ TMOD (Timer mode register)
Shared by both
◦ TCON (Timer control register)
 Registers THx & TLx
They are 16 bit wide.
 These registers store:
The time delay as a timer.
The number of events as a counter.
 Timer 0: TH0 & TL0
Timer 0 high byte , timer 0 low byte
 Timer 1: TH1 & TL1
Timer 1 high byte, timer 1 low byte
D15 D8D9D10D11D12D13D14 D7 D0D1D2D3D4D5D6
TH0 TL0
D15 D8D9D10D11D12D13D14 D7 D0D1D2D3D4D5D6
TH1 TL1
Timer 0
Timer 1
Timer Registers
 Timer mode register = TMOD
◦ An 8-bit register
 lower 4 bits : Timer 0 Mode setting (0000 : not used)
 upper 4 bits : Timer 1 Mode setting (0000 : not used)
◦ Not bit-addressable
GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
(MSB) (LSB)
BIT NAME EXPLANATION OF THE FUNCTION TIMER
7 GATE1
When this bit is set the timer will only run
when INT1 (P3.3) is high. When this bit is
clear the timer will run regardless of the
state of INT1.
1
6 C/T1
When this bit is set the timer will count
events on T1 (P3.5). When this bit is clear
the timer will be incremented every machine
cycle.
1
5 T1M1 Timer mode bit 1
4 T1M0 Timer mode bit 1
3 GATE0
When this bit is set the timer will only run
when INT0 (P3.2) is high. When this bit is
clear the timer will run regardless of the
state of INT0.
0
2 C/T0
When this bit is set the timer will count
events on T0 (P3.4). When this bit is clear
the timer will be incremented every machine
cycle.
0
1 T0M1 Timer mode bit 0
0 T0M0 Timer mode bit 0
0 : Timer operation
(clock : Machine cycle)
1 : Counter operation
(clock : Tx input pin)
GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
(MSB) (LSB)
 Every timer has a mean of starting and stopping.
Timer is enabled only while the INT pin is high and TR
control pin(in TCON) is set.
◦ GATE = 0
 Internal control
 The start and stop of the timer are controlled by the software
(Set/clear the TR)
◦ GATE = 1
 External control
 The hardware way of starting and stopping the timer by
software and an external source.
 M0 and M1 select the timer mode for timers 0 & 1.
M1 M0 Mode Operating Mode
0 0 0 13-bit timer mode
8-bit THx + 5-bit TLx (x= 0 or 1)
0 1 1 16-bit timer mode
8-bit THx + 8-bit TLx
1 0 2 8-bit auto reload
8-bit auto reload timer/counter;
THx holds a value which is to be reloaded
into TLx each time it overflows.
1 1 3 Split timer mode
TxM1 TxM0 Timer Mode Description of Mode
0 0 0 13-bit Timer
0 1 1 16-bit Timer
1 0 2 8-bit Auto Reload
1 1 3 Split Timer Mode
4
Operating
Modes
 This is a relic mode.
◦ Included in 8051 to maintain compatibility with its predecessor
8048.
 The counters are counting up:
◦ TLx will count from 0 to 31.
◦ When TLx is incremented from 31, it will “reset” (overflow) to
0.
◦ Now THx will be incremented.
 Hence effectively only 13 bits are used.
◦ Bits 0-4 of TLx.
◦ Bits 0-7 of THx..
 This is the most commonly used mode.
 This mode operates in a fashion almost like the Mode 0, only
this time all 16 bits are used.
 The counting:
◦ TLx is incremented from 0(00h) to 255(FFh).
◦ When TLx is incremented from 255, it resets to 0 and
causes THx to be incremented by 1.
◦ Hence we have a maximum count of „65,025‟ (255*255)
machine cycles.
1. Choose mode 1 timer 0
MOV TMOD,#01H
2. Load registers TL and TH with initial count values
MOV TH0,#FFH
MOV TL0,#FCH
3. Clear the flag TF0
CLR TF0
4. Start the timer.
SETB TR0
5. The 8051 starts to count up by incrementing the TH0-TL0.
◦ TH0-TL0= FFFCH,FFFDH,FFFEH,FFFFH,0000H
FFFC FFFD FFFE FFFF 0000
TF = 0 TF = 0 TF = 0 TF = 0 TF = 1
TH0 TL0Start timer
Stop timer
Monitor TF until TF=1
TR0=1 TR0=0
TF
÷ 12
TR
TH TL TF
Timer
overflow
flag
C/T = 0
TF goes high when FFFF 0
XTAL
oscillator
 When a timer is in mode 2, THx holds the "reload value" and
TLx is the timer itself.
 Thus the counting proceeds as:
◦ TLx starts counting up.
◦ TLx reaches 255 and is subsequently incremented.
◦ Now instead of resetting to 0 (as in the case of modes 0
and 1), it will be reset to the value stored in THx.
1. Choose mode 2 timer 0
MOV TMOD,#02H
2. Set the original value to TH0.
MOV TH0,#38H
3. Clear the flag to TF0=0.
CLR TF0
4. After TH0 is loaded with the 8-bit value, the 8051 gives a copy of it
to TL0.
TL0=TH0=38H
5. Start the timer.
SETB TR0
6. The 8051 starts to count up by incrementing the TL0.
TL0= 38H, 39H, 3AH,....
7. When TL0 rolls over from FFH to 00, the 8051 set TF0=1. Also, TL0 is
reloaded automatically with the value kept by the TH0.
TL0= FEH, FFH, 00H (Now TF0=1)
The 8051 auto reload TL0=TH0=38H.
Clr TF0
Go to Step 6 (i.e., TL0 is incrementing continuously).
 Note that we must clear TF0 when TL0 rolls over. Thus, we can monitor
TF0 in next process.
8.Clear TR0 to stop the process.
Clr TR0
XTAL
oscillator ÷ 12
TR1
TL1
TH1
TF1 overflow flag
reload
C/T = 0
 When Timer 0 is placed in mode 3, it essentially becomes two separate 8-
bit timers.
 That is to say, Timer 0 is TL0 and Timer 1 is TH0.
Both timers count from 0 to 255 and overflow back to 0 independently.
 What happens to timer1?
◦ All the bits that are related to Timer 1 will now be tied to TH0.
◦ While Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be
put into modes 0, 1 or 2 normally.
◦ However, you may not start or stop the real timer 1 since the bits that do
that are now linked to TH0.
◦ The real timer 1, in this case, will be incremented every machine cycle
no matter what.
A good possible use of using split timer mode is if you need to have two
separate timers and, additionally, a baud rate generator.
In such case you can use the real Timer 1 as a baud rate generator
and use TH0/TL0 as two separate timers.
 Finally, there is one more SFR that controls the two
timers and provides valuable information about them.
 Timer control register: TCON
◦ Upper nibble : TIMER
◦ Lower nibble : INTERRUPTS
The Register bits represent the following values :
BIT NAME BIT ADDRESS EXPLANATION OF
THE FUNCTION
TIMER
7 TF1 8Fh
Timer 1 Overflow. This
bit is set by the
microcontroller when
Timer 1 overflows.
1
6 TR1 8Eh
Timer 1 Run.
When this bit is set
Timer 1 is turned on.
When this bit is clear
Timer 1 is off.
1
5 TF0 8Dh
Timer 0 Overflow. This
bit is set by the
microcontroller when
Timer 0 overflows.
0
4 TR0 8Ch
Timer 0 Run.
When this bit is set
Timer 0 is turned on.
When this bit is clear
Timer 0 is off.
0
 TF (timer flag, control flag)
◦ TF0 : timer 0
◦ TF1 : timer 1.
◦ TF is like a carry.
Originally, TF=0.
When TH-TL roll over to 0000
from FFFFH
Then , TF is set to 1
 TF=0:not reached
 TF=1:reached
TR (run control bit)
TR0 : Timer 0
TR1: Timer 1
Turn timer - ON or OFF
TR = 0 : OFF (stop)
TR = 1 : ON (start)
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
Timer 1 Timer0 for Interrupt
(MSB) (LSB)
This SFR is “Bit-Addressable”
What does this mean ?
It means that if you want to set the bit TF1
(which is the highest bit of TCON)
you could execute the command :
SETB TF1
Rather than executing this command :
MOV TCON , #80h
Because it is bit-addressable.
It decreases program execution time.
 As far as the use of a timer/counter as an event counter is
concerned ,everything that we have talked about in the last
section also applies to programming it as a counter ,except
the source of the frequency.
 When used as a timer ,the 8051‟s crystal is used as the
source of the frequency.
 However ,when used as a counter ,it is a pulse outside of the
8051 that increments the TH,TL registers.
 These timers can also be used as counters counting
events happening outside the 8051.
Pin Port Pin Function Description
14 P3.4 T0 Timer/Counter 0 external input
15 P3.5 T1 Timer/Counter 1 external input
GATE C/T=1 M1 M0 GATE C/T=1 M1 M0
Timer 1 Timer 0
(MSB) (LSB)
 16-bit counter (TH0 and TL0)
 TH0-TL0 is incremented when TR0 is set to 1 and an external
pulse (in T0) occurs.
 When the counter (TH0-TL0) reaches its maximum of FFFFH, it
rolls over to 0000, and TF0 is raised.
 Programmers should monitor TF0 continuously and stop the
counter 0.
 Programmers can set the initial value of TH0-TL0 and let
TF0=1 as an indicator to show a special condition. (ex: 100
people have come).
Timer 0
external
input Pin
3.4
TR0
TH0 TL0 TF0
TF0 goes high when
FFFF 0
overflow
flag
C/T = 1
 8-bit counter.
It allows only values of 00 to FFH to be loaded into TH0
 Auto-reloading
• TL0 is incremented if TR0=1 and external pulse occurs.
Thank You!

Mais conteúdo relacionado

Mais procurados

Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerJay Makwana
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded cVikas Dongre
 
7 segment led interfacing with 8051
7 segment led interfacing with 80517 segment led interfacing with 8051
7 segment led interfacing with 8051Sam Patel
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller Gaurav Verma
 
System bus timing 8086
System bus timing 8086System bus timing 8086
System bus timing 8086mpsrekha83
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counterscjbas
 
8257 DMA Controller
8257 DMA Controller8257 DMA Controller
8257 DMA ControllerShivamSood22
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing ModesSenthil Kumar
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripheralsamrutachintawar239
 
23. serial and parallel data communication
23. serial and parallel data communication23. serial and parallel data communication
23. serial and parallel data communicationsandip das
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingAnkur Mahajan
 

Mais procurados (20)

Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded c
 
7 segment led interfacing with 8051
7 segment led interfacing with 80517 segment led interfacing with 8051
7 segment led interfacing with 8051
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
System bus timing 8086
System bus timing 8086System bus timing 8086
System bus timing 8086
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
8257 DMA Controller
8257 DMA Controller8257 DMA Controller
8257 DMA Controller
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
8051 ch9
8051 ch98051 ch9
8051 ch9
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
23. serial and parallel data communication
23. serial and parallel data communication23. serial and parallel data communication
23. serial and parallel data communication
 
Intel 8051 - pin description
Intel 8051  - pin descriptionIntel 8051  - pin description
Intel 8051 - pin description
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 

Semelhante a 8051 timer counter (20)

lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
8051 timers
8051 timers8051 timers
8051 timers
 
Timers
TimersTimers
Timers
 
Timers
TimersTimers
Timers
 
8051 Timer
8051 Timer8051 Timer
8051 Timer
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
 
4.Timer_1.ppt
4.Timer_1.ppt4.Timer_1.ppt
4.Timer_1.ppt
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
Timers
TimersTimers
Timers
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 
Uc
UcUc
Uc
 
UNIT-5.ppt
UNIT-5.pptUNIT-5.ppt
UNIT-5.ppt
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
 
Timers of 8051
Timers of 8051Timers of 8051
Timers of 8051
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
Microprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and CounterMicroprocessor Week 9: Timer and Counter
Microprocessor Week 9: Timer and Counter
 

Último

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

8051 timer counter

  • 1. Presented by :  AKASH GUPTA 111257  ANKIT SAHA 111340
  • 2.  Introduction  TMOD Register  Modes of Operation  TCON Register  Counters
  • 3.
  • 4.  The 8051 comes equipped with two timers, both of which may be controlled, set, read, and configured individually.  The 8051 timer has three general functions:  Keeping time and calculating the amount of time between events.  Counting the events .  Generating baud rates for the serial port.
  • 5. When a timer is in interval timer mode and correctly configured, it will increment by „ONE‟ every machine cycle. We have: 1,10,59,000 / 12 = 9,21,583 machine cycles / sec  The 8051 uses a 11.059 MHz crystal.  A machine cycle equals 12 clock (crystal) pulses. Thus the counter increments 9,21,583 times per second. Thus if a timer has counted from 0 to 50,000 you may calculate: 50,000 / 9,21,583 = .0542 seconds
  • 6.
  • 7.  The 8051 has 2 timers/counters: ◦ Timer/Counter 0 ◦ Timer/Counter 1  Registers Used in the Timer : ◦ Timer 0 registers: TH0, TL0 Exclusive ◦ Timer 1 registers: TH1, TL1 ◦ TMOD (Timer mode register) Shared by both ◦ TCON (Timer control register)
  • 8.  Registers THx & TLx They are 16 bit wide.  These registers store: The time delay as a timer. The number of events as a counter.  Timer 0: TH0 & TL0 Timer 0 high byte , timer 0 low byte  Timer 1: TH1 & TL1 Timer 1 high byte, timer 1 low byte
  • 9. D15 D8D9D10D11D12D13D14 D7 D0D1D2D3D4D5D6 TH0 TL0 D15 D8D9D10D11D12D13D14 D7 D0D1D2D3D4D5D6 TH1 TL1 Timer 0 Timer 1 Timer Registers
  • 10.
  • 11.  Timer mode register = TMOD ◦ An 8-bit register  lower 4 bits : Timer 0 Mode setting (0000 : not used)  upper 4 bits : Timer 1 Mode setting (0000 : not used) ◦ Not bit-addressable
  • 12. GATE C/T M1 M0 GATE C/T M1 M0 Timer 1 Timer 0 (MSB) (LSB) BIT NAME EXPLANATION OF THE FUNCTION TIMER 7 GATE1 When this bit is set the timer will only run when INT1 (P3.3) is high. When this bit is clear the timer will run regardless of the state of INT1. 1 6 C/T1 When this bit is set the timer will count events on T1 (P3.5). When this bit is clear the timer will be incremented every machine cycle. 1 5 T1M1 Timer mode bit 1 4 T1M0 Timer mode bit 1 3 GATE0 When this bit is set the timer will only run when INT0 (P3.2) is high. When this bit is clear the timer will run regardless of the state of INT0. 0 2 C/T0 When this bit is set the timer will count events on T0 (P3.4). When this bit is clear the timer will be incremented every machine cycle. 0 1 T0M1 Timer mode bit 0 0 T0M0 Timer mode bit 0
  • 13. 0 : Timer operation (clock : Machine cycle) 1 : Counter operation (clock : Tx input pin) GATE C/T M1 M0 GATE C/T M1 M0 Timer 1 Timer 0 (MSB) (LSB)
  • 14.  Every timer has a mean of starting and stopping. Timer is enabled only while the INT pin is high and TR control pin(in TCON) is set. ◦ GATE = 0  Internal control  The start and stop of the timer are controlled by the software (Set/clear the TR) ◦ GATE = 1  External control  The hardware way of starting and stopping the timer by software and an external source.
  • 15.  M0 and M1 select the timer mode for timers 0 & 1. M1 M0 Mode Operating Mode 0 0 0 13-bit timer mode 8-bit THx + 5-bit TLx (x= 0 or 1) 0 1 1 16-bit timer mode 8-bit THx + 8-bit TLx 1 0 2 8-bit auto reload 8-bit auto reload timer/counter; THx holds a value which is to be reloaded into TLx each time it overflows. 1 1 3 Split timer mode
  • 16.
  • 17. TxM1 TxM0 Timer Mode Description of Mode 0 0 0 13-bit Timer 0 1 1 16-bit Timer 1 0 2 8-bit Auto Reload 1 1 3 Split Timer Mode 4 Operating Modes
  • 18.  This is a relic mode. ◦ Included in 8051 to maintain compatibility with its predecessor 8048.  The counters are counting up: ◦ TLx will count from 0 to 31. ◦ When TLx is incremented from 31, it will “reset” (overflow) to 0. ◦ Now THx will be incremented.  Hence effectively only 13 bits are used. ◦ Bits 0-4 of TLx. ◦ Bits 0-7 of THx..
  • 19.  This is the most commonly used mode.  This mode operates in a fashion almost like the Mode 0, only this time all 16 bits are used.  The counting: ◦ TLx is incremented from 0(00h) to 255(FFh). ◦ When TLx is incremented from 255, it resets to 0 and causes THx to be incremented by 1. ◦ Hence we have a maximum count of „65,025‟ (255*255) machine cycles.
  • 20. 1. Choose mode 1 timer 0 MOV TMOD,#01H 2. Load registers TL and TH with initial count values MOV TH0,#FFH MOV TL0,#FCH 3. Clear the flag TF0 CLR TF0 4. Start the timer. SETB TR0
  • 21. 5. The 8051 starts to count up by incrementing the TH0-TL0. ◦ TH0-TL0= FFFCH,FFFDH,FFFEH,FFFFH,0000H FFFC FFFD FFFE FFFF 0000 TF = 0 TF = 0 TF = 0 TF = 0 TF = 1 TH0 TL0Start timer Stop timer Monitor TF until TF=1 TR0=1 TR0=0 TF
  • 22. ÷ 12 TR TH TL TF Timer overflow flag C/T = 0 TF goes high when FFFF 0 XTAL oscillator
  • 23.  When a timer is in mode 2, THx holds the "reload value" and TLx is the timer itself.  Thus the counting proceeds as: ◦ TLx starts counting up. ◦ TLx reaches 255 and is subsequently incremented. ◦ Now instead of resetting to 0 (as in the case of modes 0 and 1), it will be reset to the value stored in THx.
  • 24. 1. Choose mode 2 timer 0 MOV TMOD,#02H 2. Set the original value to TH0. MOV TH0,#38H 3. Clear the flag to TF0=0. CLR TF0 4. After TH0 is loaded with the 8-bit value, the 8051 gives a copy of it to TL0. TL0=TH0=38H
  • 25. 5. Start the timer. SETB TR0 6. The 8051 starts to count up by incrementing the TL0. TL0= 38H, 39H, 3AH,.... 7. When TL0 rolls over from FFH to 00, the 8051 set TF0=1. Also, TL0 is reloaded automatically with the value kept by the TH0. TL0= FEH, FFH, 00H (Now TF0=1) The 8051 auto reload TL0=TH0=38H. Clr TF0 Go to Step 6 (i.e., TL0 is incrementing continuously).  Note that we must clear TF0 when TL0 rolls over. Thus, we can monitor TF0 in next process. 8.Clear TR0 to stop the process. Clr TR0
  • 26. XTAL oscillator ÷ 12 TR1 TL1 TH1 TF1 overflow flag reload C/T = 0
  • 27.  When Timer 0 is placed in mode 3, it essentially becomes two separate 8- bit timers.  That is to say, Timer 0 is TL0 and Timer 1 is TH0. Both timers count from 0 to 255 and overflow back to 0 independently.  What happens to timer1? ◦ All the bits that are related to Timer 1 will now be tied to TH0. ◦ While Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be put into modes 0, 1 or 2 normally. ◦ However, you may not start or stop the real timer 1 since the bits that do that are now linked to TH0. ◦ The real timer 1, in this case, will be incremented every machine cycle no matter what.
  • 28. A good possible use of using split timer mode is if you need to have two separate timers and, additionally, a baud rate generator. In such case you can use the real Timer 1 as a baud rate generator and use TH0/TL0 as two separate timers.
  • 29.
  • 30.  Finally, there is one more SFR that controls the two timers and provides valuable information about them.  Timer control register: TCON ◦ Upper nibble : TIMER ◦ Lower nibble : INTERRUPTS
  • 31. The Register bits represent the following values : BIT NAME BIT ADDRESS EXPLANATION OF THE FUNCTION TIMER 7 TF1 8Fh Timer 1 Overflow. This bit is set by the microcontroller when Timer 1 overflows. 1 6 TR1 8Eh Timer 1 Run. When this bit is set Timer 1 is turned on. When this bit is clear Timer 1 is off. 1 5 TF0 8Dh Timer 0 Overflow. This bit is set by the microcontroller when Timer 0 overflows. 0 4 TR0 8Ch Timer 0 Run. When this bit is set Timer 0 is turned on. When this bit is clear Timer 0 is off. 0
  • 32.  TF (timer flag, control flag) ◦ TF0 : timer 0 ◦ TF1 : timer 1. ◦ TF is like a carry. Originally, TF=0. When TH-TL roll over to 0000 from FFFFH Then , TF is set to 1  TF=0:not reached  TF=1:reached TR (run control bit) TR0 : Timer 0 TR1: Timer 1 Turn timer - ON or OFF TR = 0 : OFF (stop) TR = 1 : ON (start) TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Timer 1 Timer0 for Interrupt (MSB) (LSB)
  • 33. This SFR is “Bit-Addressable” What does this mean ? It means that if you want to set the bit TF1 (which is the highest bit of TCON) you could execute the command : SETB TF1 Rather than executing this command : MOV TCON , #80h Because it is bit-addressable. It decreases program execution time.
  • 34.
  • 35.  As far as the use of a timer/counter as an event counter is concerned ,everything that we have talked about in the last section also applies to programming it as a counter ,except the source of the frequency.  When used as a timer ,the 8051‟s crystal is used as the source of the frequency.  However ,when used as a counter ,it is a pulse outside of the 8051 that increments the TH,TL registers.  These timers can also be used as counters counting events happening outside the 8051.
  • 36. Pin Port Pin Function Description 14 P3.4 T0 Timer/Counter 0 external input 15 P3.5 T1 Timer/Counter 1 external input GATE C/T=1 M1 M0 GATE C/T=1 M1 M0 Timer 1 Timer 0 (MSB) (LSB)
  • 37.  16-bit counter (TH0 and TL0)  TH0-TL0 is incremented when TR0 is set to 1 and an external pulse (in T0) occurs.  When the counter (TH0-TL0) reaches its maximum of FFFFH, it rolls over to 0000, and TF0 is raised.  Programmers should monitor TF0 continuously and stop the counter 0.  Programmers can set the initial value of TH0-TL0 and let TF0=1 as an indicator to show a special condition. (ex: 100 people have come).
  • 38. Timer 0 external input Pin 3.4 TR0 TH0 TL0 TF0 TF0 goes high when FFFF 0 overflow flag C/T = 1
  • 39.  8-bit counter. It allows only values of 00 to FFH to be loaded into TH0  Auto-reloading • TL0 is incremented if TR0=1 and external pulse occurs.