5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

More fun with Timer/Counters
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
The PIC uCs PIC Microcontroller and Embedded Systems Muhammad Ali Mazidi, Rolin McKinlay and Danny Causey Eng. Husam Alzaq The Islamic Uni. Of Gaza 9-1.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Taking timing further Chapter Nine 9.1 – 9.8 Dr. Gheith Abandah1.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
8051 timer/counter.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
ARM Timers.
System Clocks.
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
Chapter 4 TIMER OPERATION
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
The Silicon Laboratories C8051F020
Working with Time: Interrupts, Counters and Timers
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
TIMERS.
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
16F877A.
Chapter 9 PIC18 Timer Programming in Assembly
Why are Timer Functions Important?
V.V.P. ENGINEERING COLLEGE,RAJKOT
Timer and Interrupts.
Microprocessor Systems Design I
Timer Source: under
Interrupts, Counter and Timers
AVR Addressing Modes Subject: Microcontoller & Interfacing
Microprocessors Timers
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
8-bit Timer/Counter0 with PWM
8051 Timers Prof. Rajiv R Bhandari.
Pugazhendhi.M 11/12/2018 TIMERS 11/12/2018 CCET CCET.
Timer.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
8-bit Timer/Counter2 with PWM and Asynchronous Operation
Timer Source: under
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
EECE.3170 Microprocessor Systems Design I
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
EECE.3170 Microprocessor Systems Design I
Timer Source: under
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
PIC18 Interrupt Programming
Timers Chapter 2.
Presentation transcript:

5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses  generate pulses of specific periods  time events  generate delays accurately We can use Timer/Counters for all the above

5-2 Binary Counters n-bit Counter Overflow bit Clock signal Counter increments by one for every clock pulse Counter can be pre-loaded with a starting value This bit is set to one when the binary counter rolls over from all 1's back to 0's (Can be reset to zero by software)

5-3 Timer/Counters The clock source can be  a fixed known frequency usually the cpu clock or some fraction of it  An external signal – connected to an external pin. This allows the counting of pulses Some systems connect the overflow bit via a flip-flop to an output pin which is toggled every time an overflow occurs. Used for waveform generation (PWM). The overflow flag can be polled or used to generate an interrupt to the CPU.

5-4 PIC 18F452 Timer0 – 8 bit mode

5-5 PIC 18F452 Timer0 – 16 bit mode Note: Upon RESET, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.

5-6 T0CON – Timer 0 Control register

5-7 To generate a fixed delay Configure T0CON  timer mode  8 or 16 bit  prescaler Load TMR0 with vale to give correct time delay  NOTE: - High byte first then low byte Clear TMR0IF to zero (Bit 2 of INTCON register) Start timer by setting TMR0ON (bit 7 of T0CON) Poll TMR0IF – wait until bit is set. Alternatively use interrupts (a future lecture topic).

5-8 To measure a time period  Configure T0CON timer mode 8 or 16 bit prescaler  Clear TMR0 - High byte first then low byte  Clear TMR0IF to zero (may not be required)  When the event starts Start timer by setting TMR0ON (bit 7 of T0CON)  When the event is over Stop the timer by clearing TMR0ON  Read the value from TMR0 (Read low byte first!)

5-9 A 100ms delay CPU Clock frequency f osc = 4MHz, Timer input clock frequency = 4MHz /4 = 1MHz so period = 1us Max count for 16-bit TMR0 = 2^16 = counts So max timer period = x 1us =65.536ms Need to use prescaler Prescaler Resolution Max period 22us65536x2us = ms 44us ms etc uS seconds

5-10 Cont. So need prescaler set to 2. Timer input period = 2x1us = 2us Number of counts = time period/timer input period = 100ms/2us = /2 = Value to load into timer = – = movlwhigh(15536) movwfTMR0H movwflow(15536) movwfTMR0L bcfINTCON,TMR0IF

5-11 Measure a time period ;Initialise timer 0 movlw 0x03 ;Prescaler = 16, so increment timer every 16us movwf T0CON ; with 4MHz Osc ;reset timer registers to zero clrf TMR0H ;notice order:high then low byte clrf TMR0L ; The event start is detected so start timer bsf T0CON,TMR0ON ; Wait for the event to end ; The event is over so stop timer bcf T0CON,TMR0ON ;Calc time taken movff TMR0L,TIML ;Note order of reading - Low then high byte movff TMR0H,TIMH