SlideShare uma empresa Scribd logo
1 de 24
TIMERS
Prepared by:

Islam Samir
AGENDA






What is a timer? Why do we use it?
Counters.
Prescalars.
Timers, how to make digital hardware that counts time?
TMR0.
WHAT IS A TIMER?
In many applications, we need to do certain action every time
interval T.
 So, we need some hardware which tells the MCU that this time
interval has elapsed to do this action.
Examples
I.
Real time systems.
II.
Data acquisition systems.
III. Time division multiplexing communication systems.
IV.
Digital clocks.
V.
Operating systems.

WHAT IS A TIMER?


To implement such applications, we need some digital
hardware that counts time.



We do this simply by using a digital counter and controlling
the time it takes to overflow.
COUNTERS


A counter is essentially a register that, for every clock cycle, goes
through a predetermined sequence of binary states.(usually, the
numbers sequence 0,1,2,3…..).
COUNTERS
Ex. For a 2-bit counter, it will count from 0 to 4 ( 2 n-1)
and on the next clock edge it will overflow to 0 again.

So, it counted 4 counts ( 2 2 ) to overflow.
Rule#1:
2 ncounts to overflow.
 An n-bit counter will count
PRESCALARES


If you measured the frequency of the MSB in a n-bit counter
operates with Fosc, you’ll find it (Fosc/2 n).

Rule#2:
 The MSB bit in an n-bit counter changes with a frequency
equals the clock frequency divided by 2 n.
-

So, we can use synchronous counters to count, or to divide the
input frequency (used as a clock to this counter).
TIMERS
Ex.
- Suppose using a 4-bit counter, with a clock frequency =100
HZ
1
 The time of each count= 100 sec. = one clock cycle.
 The time for that counter to overflow=
1
1
 24 
 16  0.16 sec.
100
100
TIMERS
If we changed the frequency to 500 HZ,
the time to overflow will be:
-

1
1
4
2 
 16  0.032 sec.
500
500
-

If we used a 6-bit counter, the time to overflow will
1
1
be:
 26 
 64  0.64 sec.
100

100
TIMERS
So, by determining:
1.
The operating frequency of the clock
2. The number of counts.



We can determine the time for this counter to overflow, and
do some action every time this happens
(by generating an interrupt).
-

This is the idea of timers, they are counters which we
configure to count time, according to the relation:

Time to overflow =No. of counts* Time of one count
TIMERS

1.
-

2.

-

We determine the operating frequency by:
Choosing the clock that operates the counter.
This clock can be the bus clock that operates the MCU, it can
be obtained also from another timer’s overflow.
Dividing the frequency before operating the Timer.
This is done by using a Prescaler. In this case, the operating
frequency will be:

Fosc/ 4
prescalar
BASIC BLOCK DIAGRAM
Fosc/4
8-bit Prescalar

3 (selection lines)

Mux

Timer
HOW DO WE USE TIMERS?
Suppose that we want an n-bit counter to overflows every
seconds.
and the operating frequency of the MCU is Fosc:
1.
Determine the number of counts by the relation:



4

Time to overflow =No. of counts* Time of one count

4  prescalar
Time  No.ofcounts (
)
Fosc
change the number of counts, and the prescalar value until you get
the required time.



Time  Fosc
No.ofcounts 
4  prescalar
TIMERS
-

According to the required number of counts, and the timer’s
number of bits, determine the initial value:

2 n - No. of counts
Initial value=
TIMERS
-

Or, we can use the compare mode of the CCP module.
Determine time to
overflow

Set Fosc of the
MCU

Set prescalar value

Get the number of
counts
F

Counts< 2 n - 1
T

Get initial value
TMR0





8-bit timer/counter.
Readable and writable.
8-bit software programmable prescaler.
Clock source selectable to be external or internal

To use TMR0, we can use the ins. clock (Fosc/4), or an external
clock.
 Edge select for external clock.
 Interrupt on overflow from FFh to 00h.
EXAMPLE ON TMR0
Make TMR0 overflow and generate an interrupt every 4 sec.
when using a 32.768 KHZ oscillator.

-

1.

4 sec.  32 .768 KHZ
No.ofcounts 
4  prescalar

Try first the no. of counts

2 n (256) , you’ll get: prescalar=128.
EXAMPLE


Generate a 1HZ square wave only using TMR0.

-

Note that this example can be used to check if the timer
operates as required or not when using it in any application.
7-SEGMENT DISPLAY
APPLICATION: [0->99] COUNTER
[0->99] COUNTER
The program is divided into 2 parts:

1- Updating the counter every 1 second.
2- Switching the operating 7-segment every 1/60 second.
REAL TIME SYSTEMS

-

-

Very important:
The time of execution of the ISR associated with the timer’s
interrupt, must be less than the time that the timer takes to
overflow.
If it takes more time, optimize the code or use higher
oscillator frequency.
ASSIGNMENT

-

Generate a 100KHZ square wave only using TMR0.
Choose the suitable clock frequency and prescalar value.

Mais conteúdo relacionado

Mais procurados

matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdm
Gyana Ranjan Mati
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
Corrado Santoro
 
Comparison of pentium processor with 80386 and 80486
Comparison of pentium processor with  80386 and 80486Comparison of pentium processor with  80386 and 80486
Comparison of pentium processor with 80386 and 80486
Tech_MX
 

Mais procurados (20)

Digital signal processing part2
Digital signal processing part2Digital signal processing part2
Digital signal processing part2
 
matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdm
 
Ec8791 lpc2148 uart
Ec8791 lpc2148 uartEc8791 lpc2148 uart
Ec8791 lpc2148 uart
 
E.s unit 4 and 5
E.s unit 4 and 5E.s unit 4 and 5
E.s unit 4 and 5
 
Serial Data Communication
Serial Data CommunicationSerial Data Communication
Serial Data Communication
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Unit – 2
Unit – 2Unit – 2
Unit – 2
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
 
Spectrum analyzer
Spectrum analyzerSpectrum analyzer
Spectrum analyzer
 
Arm modes
Arm modesArm modes
Arm modes
 
Unit 3 Instruction of tms320C5x
Unit 3  Instruction of tms320C5xUnit 3  Instruction of tms320C5x
Unit 3 Instruction of tms320C5x
 
Comparison of pentium processor with 80386 and 80486
Comparison of pentium processor with  80386 and 80486Comparison of pentium processor with  80386 and 80486
Comparison of pentium processor with 80386 and 80486
 
Multiplexing and Multiple access
Multiplexing and Multiple accessMultiplexing and Multiple access
Multiplexing and Multiple access
 
Advanced microprocessor
Advanced microprocessorAdvanced microprocessor
Advanced microprocessor
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
 
UNIT-I-RTOS and Concepts
UNIT-I-RTOS and ConceptsUNIT-I-RTOS and Concepts
UNIT-I-RTOS and Concepts
 
Lecture5 teletraffic
Lecture5 teletrafficLecture5 teletraffic
Lecture5 teletraffic
 
Mimo radar(1)
Mimo radar(1)Mimo radar(1)
Mimo radar(1)
 
Integrated development environment
Integrated development environmentIntegrated development environment
Integrated development environment
 
EMBEDDED SYSTEMS SYBSC IT SEM IV UNIT V Embedded Systems Integrated Developme...
EMBEDDED SYSTEMS SYBSC IT SEM IV UNIT V Embedded Systems Integrated Developme...EMBEDDED SYSTEMS SYBSC IT SEM IV UNIT V Embedded Systems Integrated Developme...
EMBEDDED SYSTEMS SYBSC IT SEM IV UNIT V Embedded Systems Integrated Developme...
 

Semelhante a Timers

lec3 (1).ppt megerments for peromomence
lec3 (1).ppt megerments   for peromomencelec3 (1).ppt megerments   for peromomence
lec3 (1).ppt megerments for peromomence
MadhuGupta99385
 

Semelhante a Timers (20)

Avr timers
Avr timersAvr timers
Avr timers
 
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
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Timers
TimersTimers
Timers
 
class12_time.ppt
class12_time.pptclass12_time.ppt
class12_time.ppt
 
Timing & Control.pptx
Timing & Control.pptxTiming & Control.pptx
Timing & Control.pptx
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
 
Delay routine
Delay routineDelay routine
Delay routine
 
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
 
Timers
TimersTimers
Timers
 
Timer
TimerTimer
Timer
 
Lpc 1768 timers
Lpc 1768 timersLpc 1768 timers
Lpc 1768 timers
 
ppt-U3 - (Programming, Memory Interfacing).pptx
ppt-U3 - (Programming, Memory Interfacing).pptxppt-U3 - (Programming, Memory Interfacing).pptx
ppt-U3 - (Programming, Memory Interfacing).pptx
 
lec3 (1).ppt megerments for peromomence
lec3 (1).ppt megerments   for peromomencelec3 (1).ppt megerments   for peromomence
lec3 (1).ppt megerments for peromomence
 
8051e
8051e8051e
8051e
 
Timer 2 concept
Timer 2 conceptTimer 2 concept
Timer 2 concept
 
Engineering slides venay magen
Engineering slides   venay magenEngineering slides   venay magen
Engineering slides venay magen
 

Mais de Islam Samir

Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
Islam Samir
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and Microcontrollers
Islam Samir
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures
Islam Samir
 

Mais de Islam Samir (6)

USART
USARTUSART
USART
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
 
Interrupts
InterruptsInterrupts
Interrupts
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and Microcontrollers
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Timers

  • 2. AGENDA      What is a timer? Why do we use it? Counters. Prescalars. Timers, how to make digital hardware that counts time? TMR0.
  • 3. WHAT IS A TIMER? In many applications, we need to do certain action every time interval T.  So, we need some hardware which tells the MCU that this time interval has elapsed to do this action. Examples I. Real time systems. II. Data acquisition systems. III. Time division multiplexing communication systems. IV. Digital clocks. V. Operating systems. 
  • 4. WHAT IS A TIMER?  To implement such applications, we need some digital hardware that counts time.  We do this simply by using a digital counter and controlling the time it takes to overflow.
  • 5. COUNTERS  A counter is essentially a register that, for every clock cycle, goes through a predetermined sequence of binary states.(usually, the numbers sequence 0,1,2,3…..).
  • 6. COUNTERS Ex. For a 2-bit counter, it will count from 0 to 4 ( 2 n-1) and on the next clock edge it will overflow to 0 again. So, it counted 4 counts ( 2 2 ) to overflow. Rule#1: 2 ncounts to overflow.  An n-bit counter will count
  • 7. PRESCALARES  If you measured the frequency of the MSB in a n-bit counter operates with Fosc, you’ll find it (Fosc/2 n). Rule#2:  The MSB bit in an n-bit counter changes with a frequency equals the clock frequency divided by 2 n. - So, we can use synchronous counters to count, or to divide the input frequency (used as a clock to this counter).
  • 8. TIMERS Ex. - Suppose using a 4-bit counter, with a clock frequency =100 HZ 1  The time of each count= 100 sec. = one clock cycle.  The time for that counter to overflow= 1 1  24   16  0.16 sec. 100 100
  • 9. TIMERS If we changed the frequency to 500 HZ, the time to overflow will be: - 1 1 4 2   16  0.032 sec. 500 500 - If we used a 6-bit counter, the time to overflow will 1 1 be:  26   64  0.64 sec. 100 100
  • 10. TIMERS So, by determining: 1. The operating frequency of the clock 2. The number of counts.  We can determine the time for this counter to overflow, and do some action every time this happens (by generating an interrupt). - This is the idea of timers, they are counters which we configure to count time, according to the relation: Time to overflow =No. of counts* Time of one count
  • 11. TIMERS  1. - 2. - We determine the operating frequency by: Choosing the clock that operates the counter. This clock can be the bus clock that operates the MCU, it can be obtained also from another timer’s overflow. Dividing the frequency before operating the Timer. This is done by using a Prescaler. In this case, the operating frequency will be: Fosc/ 4 prescalar
  • 12. BASIC BLOCK DIAGRAM Fosc/4 8-bit Prescalar 3 (selection lines) Mux Timer
  • 13. HOW DO WE USE TIMERS? Suppose that we want an n-bit counter to overflows every seconds. and the operating frequency of the MCU is Fosc: 1. Determine the number of counts by the relation:  4 Time to overflow =No. of counts* Time of one count 4  prescalar Time  No.ofcounts ( ) Fosc change the number of counts, and the prescalar value until you get the required time.  Time  Fosc No.ofcounts  4  prescalar
  • 14. TIMERS - According to the required number of counts, and the timer’s number of bits, determine the initial value: 2 n - No. of counts Initial value=
  • 15. TIMERS - Or, we can use the compare mode of the CCP module.
  • 16. Determine time to overflow Set Fosc of the MCU Set prescalar value Get the number of counts F Counts< 2 n - 1 T Get initial value
  • 17. TMR0     8-bit timer/counter. Readable and writable. 8-bit software programmable prescaler. Clock source selectable to be external or internal To use TMR0, we can use the ins. clock (Fosc/4), or an external clock.  Edge select for external clock.  Interrupt on overflow from FFh to 00h.
  • 18. EXAMPLE ON TMR0 Make TMR0 overflow and generate an interrupt every 4 sec. when using a 32.768 KHZ oscillator. - 1. 4 sec.  32 .768 KHZ No.ofcounts  4  prescalar Try first the no. of counts 2 n (256) , you’ll get: prescalar=128.
  • 19. EXAMPLE  Generate a 1HZ square wave only using TMR0. - Note that this example can be used to check if the timer operates as required or not when using it in any application.
  • 22. [0->99] COUNTER The program is divided into 2 parts: 1- Updating the counter every 1 second. 2- Switching the operating 7-segment every 1/60 second.
  • 23. REAL TIME SYSTEMS  - - Very important: The time of execution of the ISR associated with the timer’s interrupt, must be less than the time that the timer takes to overflow. If it takes more time, optimize the code or use higher oscillator frequency.
  • 24. ASSIGNMENT  - Generate a 100KHZ square wave only using TMR0. Choose the suitable clock frequency and prescalar value.