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

More Related Content

What's hot

Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
JyotiprakashMishra18
 
Interrupts and types of interrupts
Interrupts and types of interruptsInterrupts and types of interrupts
Interrupts and types of interrupts
Muhammad Sheharyar Asif
 
Pipelining
PipeliningPipelining
Pipelining
AJAL A J
 
Timer
TimerTimer
Arm
ArmArm
isa architecture
isa architectureisa architecture
isa architecture
AJAL A J
 
Unit 1 Introduction to Embedded computing and ARM processor
Unit 1 Introduction to Embedded computing and ARM processorUnit 1 Introduction to Embedded computing and ARM processor
Unit 1 Introduction to Embedded computing and ARM processor
Venkat Ramanan C
 
ARM- Programmer's Model
ARM- Programmer's ModelARM- Programmer's Model
ARM- Programmer's Model
Ravikumar Tiwari
 
8086 assembly
8086 assembly8086 assembly
8086 assembly
Shehrevar Davierwala
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
HebaEng
 
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV Designing Embedded System with 8051...
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV  Designing Embedded System with 8051...SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV  Designing Embedded System with 8051...
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV Designing Embedded System with 8051...
Arti Parab Academics
 
How to Measure RTOS Performance
How to Measure RTOS Performance How to Measure RTOS Performance
How to Measure RTOS Performance
mentoresd
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Interfacing With High Level Programming Language
Interfacing With High Level Programming Language Interfacing With High Level Programming Language
Interfacing With High Level Programming Language
.AIR UNIVERSITY ISLAMABAD
 
Clock divider by 3
Clock divider by 3Clock divider by 3
Clock divider by 3
Ashok Reddy
 
hardwired control unit ppt
hardwired control unit ppthardwired control unit ppt
hardwired control unit ppt
SushmithaAcharya7
 
Superscalar Architecture_AIUB
Superscalar Architecture_AIUBSuperscalar Architecture_AIUB
Superscalar Architecture_AIUB
Nusrat Mary
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
John Williams
 
Pipelinig hazardous
Pipelinig hazardousPipelinig hazardous
Pipelinig hazardous
jasscheema
 
8086 Microprocessor
8086 Microprocessor 8086 Microprocessor
8086 Microprocessor
Vijay Kumar
 

What's hot (20)

Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
 
Interrupts and types of interrupts
Interrupts and types of interruptsInterrupts and types of interrupts
Interrupts and types of interrupts
 
Pipelining
PipeliningPipelining
Pipelining
 
Timer
TimerTimer
Timer
 
Arm
ArmArm
Arm
 
isa architecture
isa architectureisa architecture
isa architecture
 
Unit 1 Introduction to Embedded computing and ARM processor
Unit 1 Introduction to Embedded computing and ARM processorUnit 1 Introduction to Embedded computing and ARM processor
Unit 1 Introduction to Embedded computing and ARM processor
 
ARM- Programmer's Model
ARM- Programmer's ModelARM- Programmer's Model
ARM- Programmer's Model
 
8086 assembly
8086 assembly8086 assembly
8086 assembly
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
 
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV Designing Embedded System with 8051...
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV  Designing Embedded System with 8051...SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV  Designing Embedded System with 8051...
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT IV Designing Embedded System with 8051...
 
How to Measure RTOS Performance
How to Measure RTOS Performance How to Measure RTOS Performance
How to Measure RTOS Performance
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Interfacing With High Level Programming Language
Interfacing With High Level Programming Language Interfacing With High Level Programming Language
Interfacing With High Level Programming Language
 
Clock divider by 3
Clock divider by 3Clock divider by 3
Clock divider by 3
 
hardwired control unit ppt
hardwired control unit ppthardwired control unit ppt
hardwired control unit ppt
 
Superscalar Architecture_AIUB
Superscalar Architecture_AIUBSuperscalar Architecture_AIUB
Superscalar Architecture_AIUB
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Pipelinig hazardous
Pipelinig hazardousPipelinig hazardous
Pipelinig hazardous
 
8086 Microprocessor
8086 Microprocessor 8086 Microprocessor
8086 Microprocessor
 

Similar to Timers

Avr timers
Avr timersAvr timers
Avr timers
Utsav Jain
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
Mohamed Ali
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16
Ramadan Ramadan
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
SujalKumar73
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
Aarav Soni
 
Timers
TimersTimers
Timers
PRADEEP
 
class12_time.ppt
class12_time.pptclass12_time.ppt
class12_time.ppt
GauravWaila
 
Timing & Control.pptx
Timing & Control.pptxTiming & 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
naveen088888
 
Delay routine
Delay routineDelay routine
Delay routine
Yash Gandhi
 
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
Pratik Gohel
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
AmoghR3
 
Timers
TimersTimers
Lpc 1768 timers
Lpc 1768 timersLpc 1768 timers
Lpc 1768 timers
PriyangaKR1
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
Corrado Santoro
 
ppt-U3 - (Programming, Memory Interfacing).pptx
ppt-U3 - (Programming, Memory Interfacing).pptxppt-U3 - (Programming, Memory Interfacing).pptx
ppt-U3 - (Programming, Memory Interfacing).pptx
RaviKiranVarma4
 
lec3 (1).ppt megerments for peromomence
lec3 (1).ppt megerments   for peromomencelec3 (1).ppt megerments   for peromomence
lec3 (1).ppt megerments for peromomence
MadhuGupta99385
 
8051e
8051e8051e
8051e
rupalir
 
Timer 2 concept
Timer 2 conceptTimer 2 concept
Timer 2 concept
v Kalairajan
 
Engineering slides venay magen
Engineering slides   venay magenEngineering slides   venay magen
Engineering slides venay magen
venaymagen19
 

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

More from Islam Samir

USART
USARTUSART
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
Islam Samir
 
Interrupts
InterruptsInterrupts
Interrupts
Islam Samir
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
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
 

More from 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
 

Recently uploaded

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

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.