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.

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

C Examples 1.
COMP3221: Microprocessors and Embedded Systems Lecture 16: Interrupts II Lecturer: Hui Wu Session 2, 2005.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
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
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”
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
The Use of Microcontrollers
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.
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)
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
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.
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.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
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.
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.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
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.
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.
The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi.
C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
#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.
INSTITUTE: INSTITUTE:PARUL INSTITUTE OF TECHNOLOGY BRANCH : BRANCH :B.E. E.C.5 TH SEM. SUBJECT:MICROCONTROLLER & INTERFACING TOPIC:AVR INTTRUPT TOPIC:AVR.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
Why are Timer Functions Important?
Outline Introduction to Arduino UNO Programming environment setup GPIO
V.V.P. ENGINEERING COLLEGE,RAJKOT
BITS EDU. CAMPUS , VARNAMA
Interrupts, Counter and Timers
AVR Addressing Modes Subject: Microcontoller & Interfacing
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
DC motor and PWM.
8-bit Timer/Counter2 with PWM and Asynchronous Operation
Timers/Counters.
Wave Generation and Input Capturing
Timer Source: under
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

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 internal clock after it has passed through the prescaler. -TCNT2 can run off of an external or the internal clock. Since TCNT0 can run off a clock asynchronous to the CPU, some issues occur: -control register writes are delayed by two Tosc edges, @ 32Khz, = 61uS! -entering power save modes must be delayed after writing control registers -async clock may take up to 1sec to stabilize at power up 32Khz crystal

8-Bit Timer/Counter 0 Counters, timers, PWM generators are all easily implemented. Two interrupt sources exist -overflow (counter register over or under flows) -output compare (counter register = compare register) TCNT0 can be clocked internally or by an external 32Khz clock. The external clock oscillator is optimized for 32.768 Khz watch crystals. Applying a 32.768 Khz oscillator output to the Tosc pins is not recommended.

8-Bit Timer/Counter 0 Four Registers: TCNT0, OCR0, TCCR0, ASSR -TCNT0: (timer/counter register) -the 8-bit counter itself -holds the present value of count -OCR0: (output compare register) -this register is always compared against TCNT0 -TCCR0: (timer/counter 0 control register) -determines the mode of operation -ASSR: (asynchronous status register) -coordinates writing to TCNT0, OCR0, TCCR0 when in asynchronous mode

8-Bit Timer/Counter 0 Timer/Counter 0 Clock Sources: -AS0 bit in ASSR determines if clock source is internal or external -internal clock is fclk @ 16Mhz -external clock is Tosc @ 32Khz Once choice of clock is made, it may be divided by the prescaler by -8, 64, 256, or 1024 If no clock is selected, the timer is stopped and disabled.

8-Bit Timer/Counter 0 Output Compare Unit: -8-bit comparator continuously compares TCNT0 and OCR0. -If equal, the output compare flag is set (OCF0) and an interrupt can be issued. -The waveform generator uses this signal to generate an output to a pin.

8-Bit Timer/Counter 0 Modes of Operation: Determined by -waveform generation mode (WGM01:0) -compare output mode (COM01:0) Normal Mode (WGM1:0 =0) -simplest mode -count up to TOP @ 0xFF and wrap to BOTTOM @ 0x00 -TOV0 flag is set when the wrap around occurs (overflow) -to reset TOV0, ISR must be executed or flag manually cleared -no output pins are enabled

8-Bit Timer/Counter 0 Modes of Operation: Clear Timer on Compare Match (CTC) Mode (WGM1:0 =2) -counter resolution manipulated by output compare register (OCR0) -counter cleared to zero when its value equals OCR0 -TOP defined by OCR0 -interrupt can be generated at compare point -output pin (OC0) can be utilized -output pin can toggle, set, or clear on match -duty cycle constant, frequency is variable OCR0=0xF000 OCR0=0x7F00 OCR0=0x00FF OCR0=0x003F note: fixed duty cycle, variable frequency

8-Bit Timer/Counter 0 Modes of Operation: Fast PWM Mode (WGM1:0 =3) -used to create high resolution PWM waveforms -same frequency, different duty cycle -count from BOTTOM to 0xFF, then reset to BOTTOM -output compare behaviour: -set on compare match -reset at TOP -TOP is defined by OCR0 -limited to 7 different PWM frequencies compare value sets duty cycle value of TOP sets frequency note: fixed frequency, variable duty cyele

8-Bit Timer/Counter 0 Code examples // tcnt0_normal.c // setup TCNT0 in normal mode and blink PB0 LED at 1 sec intervals // blink frequency = (32768)/(2^8 * 64 * 2) = 1.000000 blinks per sec // #include <avr/io.h> int main() { uint8_t count=0; DDRB = 0x01; //set port B bit zero to output ASSR |= (1<<AS0); //use ext oscillator TCCR0 |= (1<<CS00); //normal mode, no prescaling while(1) { while (! (TIFR & (1<<TOV0))){} //spin till overflow TIFR |= (1<<TOV0); //clear by writing a one to TOV0 count++; //extend counter //toggle PB0 every 64 overflows if((count % 64) == 0){PORTB ^= 0x01;} } //while } // main

8-Bit Timer/Counter 0 Code examples // tcnt0_normal_int.c // use interrupts now // setup TCNT0 in normal mode and blink PB0 LED at 1 sec intervals // blink frequency = (32768)/(2^8 * 64) = 1.000000 blinks per sec // #include <avr/io.h> #include <avr/interrupt.h> ISR(TIMER0_OVF_vect){ static uint8_t count=0; //hold value of count between interrupts count++; //extend counter //toggle PB0 each time this happens if((count % 64) == 0){PORTB ^= 0x01;} }//TIMER0_OVF_vect int main() { DDRB = 0x01; //set port B bit zero to output TCCR0 |= (1<<CS00); //normal mode, no prescaling ASSR |= (1<<AS0); //use ext oscillator TIMSK |= (1<<TOIE0); //allow interrupts on overflow sei(); //interrupts turned on while(1) {} //spin forever waiting on interrupts //(note nearly empty main, no need for volatile count variable) } // main