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.

Slides:



Advertisements
Similar presentations
ECE/CS-352: Embedded Microcontroller Systems The Silicon Laboratories C8051F020 Enhanced 8051 Part 5 Other Subsystems.
Advertisements

More fun with Timer/Counters
Microcontroller Programming II MP6-1
Kuliah Mikrokontroler AVR Comparator AVR Eru©September 2009 PENS.
Analog/Digital Subsystem
COMP3221: Microprocessors and Embedded Systems Lecture 16: Interrupts II Lecturer: Hui Wu Session 2, 2005.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
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 
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Pulse Width Modulation modes
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
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.
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Slides created by: Professor Ian G. Harris Interrupts  Embedded systems often perform some tasks which are infrequent and possibly unpredictable Hang.
Timer/counter Chapter 12
ARM Timers.
System Clocks.
A Few Words From Dilbert
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
1 Lecture 1: Embedded Systems Overview, AVR Hardware/Software Introduction.
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.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
ELE22MIC Lecture 18 The AVR Sleep Modes The ATMEGA128’s Timer System
Counter/Timer/PWM. incoming Lab. Counter counter is a device which stores the number of times a particular event or process has occurred synchronous/asynchronous.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
AVR Programming: Timers October 8, What is a timer? A register that keeps track of a current value This value is updated at a certain frequency.
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
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.
Timers and Interrupts Mark Neil - Microprocessor Course.
Timers and Scheduled Interrupts
Interrupt On a very basic level, an interrupt is a signal that interrupts the current processor activity. It may be triggered by an external event (change.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi.
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Timers Presented by: Griffin Reid Rohit Vardhan Freddie Wilson Date: October 25, 2005.
INSTITUTE: INSTITUTE:PARUL INSTITUTE OF TECHNOLOGY BRANCH : BRANCH :B.E. E.C.5 TH SEM. SUBJECT:MICROCONTROLLER & INTERFACING TOPIC:AVR INTTRUPT TOPIC:AVR.
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
V.V.P. ENGINEERING COLLEGE,RAJKOT
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
BITS EDU. CAMPUS , VARNAMA
AVR Addressing Modes Subject: Microcontoller & Interfacing
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
Timer/Counter Modified from Dr. Lam Phung’s Slides.
16-bit Timer/Counter1 Features
8-bit Timer/Counter0 with PWM
ATmega103 Timer0 and Interrupts
8-bit Timer/Counter2 with PWM and Asynchronous Operation
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Timers/Counters.
Wave Generation and Input Capturing
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

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 1. Measuring time between two event occurrences Motor speed based on time for a full revolution 2. Invoking an action at precise intervals Injecting fuel into an engine’s combustion chamber 3. Measuring the number of events that occur within a specific time interval Number of engine misfires 4. Generating a waveform at a specific frequency

CS-280 Dr. Mark L. Hornick 2 Atmega32 Timer/Counter subsystem has 3 T/C units Timer/Counter 0 8-bit timer Timer/Counter 1 16-bit timer Timer/Counter 2 8-bit timer Subsequent slides will focus on Timer/Counter 0

CS-280 Dr. Mark L. Hornick 3 8-bit Timer/Counter 0 Overview Counter value is stored in 8-bit I/O register TCNT0 TCNT0 is automatically incremented TCNT0 can be read or written at any time The counter is driven by either: External signal on pin T0 (PB0) CPU internal clock A scale factor can be applied to slow down the clock signal to the T/C TCNT0 is incremented with each clock tick A specified number of increments corresponds to a precise time interval

Basic operation of the Timer/Counter (8-bit) CS-280 Dr. Mark L. Hornick 4 MAX=TOP = 0xFF BOTTOM = 0x00 ticks TCNT0 value Counter is started here and automatically increments at a precise rate Counter reaches its MAX value and is automatically reset to 0

CS-280 Dr. Mark L. Hornick 5 Controlling the frequency of the Timer/Counter Controlled by bits CS00:CS02 of the TCCR0 (Timer/Counter 0 Control Register) Counter/Timer stopped (does not increment) 0 0 1: Counter incremented every CPU clock tick 0 1 0: Counter incremented every 8 clock ticks 0 1 1: Counter incremented every 64 clock ticks 1 0 0: Counter incremented every 256 clock ticks 1 0 1: Counter incremented every 1024 clock ticks 1 1 0: use external clock source on T0 (PB0) pin; falling edge 1 1 1: use external clock source on T0 (PB0) pin; rising edge  Ext clock source can be anything that generates a signal (e.g. pushbutton)

CS-280 Dr. Mark L. Hornick 6 The Timer/Counter has several modes of operation: Mode is determined by bits WGM00:WGM01 0:0 – Normal mode TOP is 0xFF  After reaching 0xFF, rolls over to 0x00 and starts over 0:1 – (CTC) mode : Clear Timer on Compare match TOP is determined by the value assigned to OCR0  When TCNT0=OCR0 (compare match) TCNT0 is reset to 0 There are also two other modes we’ll discuss later…

Behavior of T/C in Normal vs. CTC Modes CS-280 Dr. Mark L. Hornick 7 MAX=TOP = 0xFF MAX=0xFF TOP BOTTOM = 0x00 ticks Counter value Normal Mode CTC Mode BOTTOM = 0x00 Value of TOP is the value of OCR0, which you can modify at any time within your program

CS-280 Dr. Mark L. Hornick 8 Normal Mode Interrupt of Timer/Counter 0 When TCNT0 overflows from 0xFF to 0, TOV0 flag in TIFR is set The TIMSK Register controls generation of interrupts on overflow When TOV0 is set and TOIE0 is enabled: Overflow interrupt is generated ISR is setup via jump vector 0x16 TOV0 is cleared when the ISR is executed

Normal mode interrupt CS-280 Dr. Mark L. Hornick 9 MAX=TOP = 0xFF BOTTOM = 0x00 ticks TCNT0 value Counter is started here and automatically increments at a precise rate Timer interrupt TOIE1 occurs when TCNT0 overflows (resets) TOV0 flag is set on overflow and resets automatically when TOIE1 ISR is vectored Normal Mode

CS-280 Dr. Mark L. Hornick 10 CTC Mode Interrupts of Timer/Counter 0 When TCNT0=OCR0, OCF0 flag in TIFR is set When in CTC mode, TCNT0 is automatically reset to 0 The TIMSK Register controls generation of Output Comparator interrupts (as well as Counter Overflow interrupts described earlier) When OCF0 is set and OCIE0 is enabled: Compare Match interrupt is generated ISR is setup via jump vector 0x14 OCF0 is cleared when the ISR is executed

CTC mode interrupt CS-280 Dr. Mark L. Hornick 11 Counter is started here and automatically increments at a precise rate Timer interrupt OCIE1 occurs when TCNT0=OCR0 (compare match) OCF0 flag is set on match and resets automatically when OCIE1 ISR is vectored MAX=0xFF TOP ticks Counter value CTC Mode BOTTOM = 0x00

CS-280 Dr. Mark L. Hornick 12 The Output Comparator circuitry can be configured to drive a voltage on OC0 (PB3) high or low When in CTC mode, bits COM01:COM00 affect the operation as follows: 0 0: OC0 disconnected 0 1: Toggle OC0 on compare match 1 0: Clear OC0 on compare match 1 1: Set OC0 on compare match PB3 must be setup for output

Signal patterns on OC0 CS-280 Dr. Mark L. Hornick 13 MAX=0xFF TOP ticks Counter value CTC Mode BOTTOM = 0x00 COM01:COM00 = 1:1 Set OC0 on compare match COM01:COM00 = 1:0 Clear OC0 on compare match COM01:COM00 = 0:1 Toggle OC0 on compare match

Interrupt frequency can be varied by modifying the value of OCR0 CS-280 Dr. Mark L. Hornick 14

CS-280 Dr. Mark L. Hornick 15 Review SFIOR – A/D Special Function Register ADC can be configured to perform A/D conversion based on Counter overflow or Output Comparator match