SlideShare une entreprise Scribd logo
1  sur  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.

Contenu connexe

Tendances

Von Neumann vs Harvard Architecture
Von Neumann vs Harvard ArchitectureVon Neumann vs Harvard Architecture
Von Neumann vs Harvard ArchitectureOLSON MATUNGA
 
Mealy state machine
Mealy state machineMealy state machine
Mealy state machineArif Siyal
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output OrganizationKamal Acharya
 
Register transfer language & its micro operations
Register transfer language & its micro operationsRegister transfer language & its micro operations
Register transfer language & its micro operationsLakshya Sharma
 
Mod 10 synchronous counter updated
Mod 10 synchronous counter updatedMod 10 synchronous counter updated
Mod 10 synchronous counter updatedDANISHAMIN950
 
Subroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerSubroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerbhadresh savani
 
Machine cycles
Machine cyclesMachine cycles
Machine cyclesWafaAbied
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessorVikas Gupta
 
Presentation on 8086 Microprocessor
Presentation  on   8086 MicroprocessorPresentation  on   8086 Microprocessor
Presentation on 8086 MicroprocessorNahian Ahmed
 
Micro operation control of processor
Micro operation control of processorMicro operation control of processor
Micro operation control of processorMuhammad Ishaq
 
Instruction codes and computer registers
Instruction codes and computer registersInstruction codes and computer registers
Instruction codes and computer registersSanjeev Patel
 

Tendances (20)

Von Neumann vs Harvard Architecture
Von Neumann vs Harvard ArchitectureVon Neumann vs Harvard Architecture
Von Neumann vs Harvard Architecture
 
Mealy state machine
Mealy state machineMealy state machine
Mealy state machine
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
Register transfer language & its micro operations
Register transfer language & its micro operationsRegister transfer language & its micro operations
Register transfer language & its micro operations
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
USB protocol
USB protocolUSB protocol
USB protocol
 
Branch prediction
Branch predictionBranch prediction
Branch prediction
 
Read & write
Read & writeRead & write
Read & write
 
Mod 10 synchronous counter updated
Mod 10 synchronous counter updatedMod 10 synchronous counter updated
Mod 10 synchronous counter updated
 
Subroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerSubroutine in 8051 microcontroller
Subroutine in 8051 microcontroller
 
Machine cycles
Machine cyclesMachine cycles
Machine cycles
 
Avr timers
Avr timersAvr timers
Avr timers
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
 
Assembler
AssemblerAssembler
Assembler
 
Chapter 5 counter
Chapter 5 counterChapter 5 counter
Chapter 5 counter
 
Presentation on 8086 Microprocessor
Presentation  on   8086 MicroprocessorPresentation  on   8086 Microprocessor
Presentation on 8086 Microprocessor
 
Micro operation control of processor
Micro operation control of processorMicro operation control of processor
Micro operation control of processor
 
Instruction codes and computer registers
Instruction codes and computer registersInstruction codes and computer registers
Instruction codes and computer registers
 
8251 USART
8251 USART8251 USART
8251 USART
 

Similaire à 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 programmingMohamed Ali
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Ramadan Ramadan
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptxSujalKumar73
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
class12_time.ppt
class12_time.pptclass12_time.ppt
class12_time.pptGauravWaila
 
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 .pptxnaveen088888
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxAmoghR3
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersCorrado Santoro
 
ppt-U3 - (Programming, Memory Interfacing).pptx
ppt-U3 - (Programming, Memory Interfacing).pptxppt-U3 - (Programming, Memory Interfacing).pptx
ppt-U3 - (Programming, Memory Interfacing).pptxRaviKiranVarma4
 
lec3 (1).ppt megerments for peromomence
lec3 (1).ppt megerments   for peromomencelec3 (1).ppt megerments   for peromomence
lec3 (1).ppt megerments for peromomenceMadhuGupta99385
 
Engineering slides venay magen
Engineering slides   venay magenEngineering slides   venay magen
Engineering slides venay magenvenaymagen19
 

Similaire à Timers (20)

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
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
 
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
 

Plus de Islam Samir

Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog worldIslam Samir
 
Introduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIntroduction to Embedded Systems and Microcontrollers
Introduction to Embedded Systems and MicrocontrollersIslam 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-architecturesIslam Samir
 

Plus 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
 

Dernier

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
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 Processorsdebabhi2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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.pdfsudhanshuwaghmare1
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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 TerraformAndrey Devyatkin
 
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 FresherRemote DBA Services
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Dernier (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
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 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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.