Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne

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.
ECT 357 Ch 16 Output Control. Today’s Quote: The measure of a man is not how great his faith is bt how great his love is. The measure of a man is not.
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.
ATtiny2313 Timers/Counters CS-423 Dick Steflik. What Do You Use Timers For? Timing of events (internal or external)‏ Scheduling Events Measuring the width.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Taking timing further Chapter Nine 9.1 – 9.8 Dr. Gheith Abandah1.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Microcontroller Architecture PIC18F Family
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
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.
Software Three Main Functions Records/Monitors Zero Detection Points Gives our PWM a starting point Data used to dynamically adjust carrier frequency Detects.
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.
V 0.21 Timers A timer on a  C is simply a counter The input clock frequency to a timer can be prescaled so that it is some fraction of the system clock.
8254 Programmable Interval Timer
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
8254 Counter/Timer Counter Each of the three counter has 3 pins associated CLK: input clock frequency- 8 MHz OUT GATE: Enable (high) or disable.
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.
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.
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Timer Peripherals.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Microprocessoren lesson 6. PWM /motor control/servo.
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
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.
Microcontroller Applications ELEC 421 Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
Timer 1 and 2 operation, PWM Principles. Timer 1 Operation.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
C Examples 6. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
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.
Chapter 9 PIC18 Timer Programming in Assembly
Why are Timer Functions Important?
V.V.P. ENGINEERING COLLEGE,RAJKOT
Timer and Interrupts.
Programmable Interval Timer
AVR Addressing Modes Subject: Microcontoller & Interfacing
Microprocessors Timers
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
Timer/Counter Modified from Dr. Lam Phung’s Slides.
8-bit Timer/Counter0 with PWM
Pugazhendhi.M 11/12/2018 TIMERS 11/12/2018 CCET CCET.
Timer.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
Timer Source: under
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Figure CCP1 Control Register
Timer Source: under
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Timers Chapter 2.
Presentation transcript:

Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning ELEC 330

Hardware Counters and Timers Counter (register) Can be decremented or incremented per clock cycle Time calculation Find difference between beginning count and last count Multiply the count difference by the clock period 330_11

Hardware Counters and Timers Counter (register) Replace the clock with a signal from an event Count is incremented (or decremented) Total number of events can be counted 330_11

Types of Counters Up-counter Counter is incremented at every clock cycle When count reaches the maximum count, a flag is set Counter can be reset to zero or to the initial value Down-counter Counter is decremented at every clock cycle When count reaches zero, a flag is set Counter can be reset to the maximum or the initial value Free-running counter Counter runs continuously and only readable When it reaches the maximum count, a flag is set 330_11

Timer Applications Time delay Pulse wave generation Pulse width or frequency measurement Timer as an event counter 330_11

Capture, Compare, and PWM (CCP) Modules CCP modules are common in recent MCUs Registers specially designed to perform the following functions (in conjunction with timers) Capture: The CCP pin can be set as an input to record the arrival time of a pulse. Compare: The CCP pin is set as an output, and at a given count, it can be driven low, high, or toggled. Pulse width modulation (PWM): The CCP pin is set as an output and the duty cycle of a pulse can be varied. 330_11

Pulse Width Modulation Duty cycle Percentage ratio of on time of a pulse to its period Changing of the duty cycle is defined as PWM CCP pin is set as an output Count for period and duty cycle loaded into CCP registers Varying the duty cycle generates PWM 330_11

PIC18 Timers PIC18 timers Timer0 Timer1 (and Timer3) All up-counters 8-bit and 16-bit Timer0 8-bit or 16-bit timer Timer1 (and Timer3) 16-bit timers Timer2 (and Timer4) 8-bit timer SFRs T0CON-T2CON 330_11

Timer0 8-bit or 16-bit timer Readable and writable Parameters in T0CON register Eight pre-scale values (Bit2-Bit0) Clock source (Bit5) Internal (instruction cycle) External clock connected to pin RA4/T0CK1 Rising edge or falling edge (Bit4) Generates an interrupt or sets a flag when it overflows TMR0IF Flag must be cleared to start the timer again 330_11

Timer0 T0CON 330_11

Timer1 16-bit counter/timer Two 8-bit registers (TMR1H and TMR1L) Four prescale values (Bit5-Bit4) Clock source (Bit1) Internal (instruction cycle) External (pin RC0/T13CK1) on rising edge 330_11

Timer1 Interrupt Resetting Timer1 using CCP module Generates an interrupt or sets a flag when it overflows TMR1IF Flag must be cleared to start the timer again Resetting Timer1 using CCP module CCP1 in the Compare mode Timer1 and CCP1compared at every cycle When a match is found, Timer1 is reset 330_11

Timer2 8-bit timer (TMR2) 8-bit period register (PR2) TMR2 and PR2 are readable and writable Three prescale values (Bit1-Bit0) 16 postscale values (Bit6-Bit3) Flag (TMR2IF) is set when TMR2 matches PR2 Can generate an interrupt 330_11

Timer2 Timer2 operation 8-bit number is loaded in PR2 When TMR2 and PR2 match Output pulse is generated and the timer is reset Output pulse goes through postscaler Sets the flag TMR2IF 330_11

CCP Modules Capture, Compare, and Pulse Width Modulation (PWM) CCPR1H (high) and CCPR1L (low) 16-bit Capture register 16-bit Compare register Duty-cycle PWM register Timer1 used as clock for Capture and Compare Timer2 used as clock for PWM 330_11

CCP in the Capture Mode CCPR1 captures the 16-bit value of Timer1 When an event occurs on pin RC2/CCP1 Interrupt request flag bit CCP1IF is set Must be cleared for the next operation To capture an event Set up pin RC2/CCP1 of PORTC as the input Initialize Timer1 T1CON register Initialize CCP1 CCP1CON register 330_11

CCP in the Compare Mode CCPR1 constantly compared with TMR1 When a match occurs Pin RC2/CCP1 on PORTC Driven high, low, or toggled Interrupt flag bit CCP1IF is set To set up CCP1 in Compare mode Set up pin RC2/CCP1 of PORTC as output Initialize Timer1 and CCP1 Clear the flag CCP1IF 330_11

PWM Mode CCP module with Timer2 Duty cycle Period Output a pulse wave form for a given frequency/duty cycle Duty cycle CCPR1 register Period PR2 register When TMR2 is equal to PR2 TMR2 is cleared Pin RC2/CCP1 of PORTC is set high PWM duty-cycle byte loaded into CCPR1 330_11