Wave Generation and Input Capturing

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

Kuliah Mikrokontroler AVR Comparator AVR Eru©September 2009 PENS.
Timers in Hardware ECE152. Overview Why are timers important – Watchdog – Task switching – Accurate time of day Can use polling or interrupts.
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
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).
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)
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.
A Few Words From Dilbert
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
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 ?
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
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.
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.
Application of Interrupt and Timer : Measurement of Motor Speed.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Timers and Interrupts Mark Neil - Microprocessor Course.
Timers and Scheduled Interrupts
Application of Interrupt and Timer : Motor Position Control.
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.
충북인력개발원 전자과 공학박사 강원찬 3. Timer & Counter &PWM. uP AVR (Atmega128) PWM1=OC1A(PB5) PWM2=OC1B(PB6) T0=T1(PD6) T1=T2(PD7)
#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.
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
Why are Timer Functions Important?
Servos Elementary Robotics with Servos
Outline Introduction to Arduino UNO Programming environment setup GPIO
V.V.P. ENGINEERING COLLEGE,RAJKOT
ECE 3430 – Intro to Microcomputer Systems
PWM and DC Motor Control
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
COMP2121: Microprocessors and Interfacing
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.
COMP2121: Microprocessors and Interfacing
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
ADC and DAC Programming in AVR
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Timers/Counters.
Interrupt Chapter 10.
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Presentation transcript:

Wave Generation and Input Capturing

Topics Wave characteristics Timer0 review Wave generating using Timer0 Music and frequencies Timer0 review Wave generating using Timer0 Wave generating using Timer2 Wave generating using Timer1 Capturing 2

Wave characteristics Period Duty cycle Amplitude Frequency 1 T f = T ×100 = ×100 T t0 + t1 t0 t1

Music and Frequencies Music 4

Waveform generators in ATmega328

Timer0 Review TCCR0A TCCR0B OCR0A TCNT0 OCR0B TOV0 = = OCF0A OCF0B 6

0 1 0 CTC (Clear Timer on Compare Match) 0 1 1 Fast PWM 1 0 0 Reserved WGM02 WGM01 WGM00 Comment 0 0 0 Normal 0 0 1 Phase correct PWM 0 1 0 CTC (Clear Timer on Compare Match) 0 1 1 Fast PWM 1 0 0 Reserved 1 0 1 Phase correct PWM 1 1 0 Reserved 1 1 1 Fast PWM Timer Mode (WGM)

Normal mode TCNT0 0xFF TOV TOV TOV time FF 1 FE TOV0: 2 1 TOV0 = 1 8

CTC (Clear Timer on Compare match) mode TCNT0 0xFF OCR0A OCF0A OCF0A OCF0A time OCR0A TOV0: xx 2 1 OCF0A: 1 TOV0 = no change OCF0A = 1 9

Waveform Generator 10

Waveform Generator 11

Frequency = changeable WGM02 WGM01 WGM00 Comment 0 0 0 Normal 0 0 1 Phase correct PWM 0 1 0 CTC (Clear Timer on Compare Match) 0 1 1 Fast PWM 1 0 0 Reserved 1 0 1 Phase correct PWM 1 1 0 Reserved 1 1 1 Fast PWM Timer Mode (WGM) TCNT0 OCF0x OCR0x 0xFF OC0x fclk 2N(OCR0x+1) FOC0= CTC, Toggle Mode Duty cycle = 50% Frequency = changeable COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Toggle OC0 on compare match Clear OC0 on compare match Set OC0 on compare match

Assuming XTAL = 16 MHz, make a pulse with duty cycle = 50% and frequency = 1MHz fclk 2N(OCR0x+1) FOC0= 16MHz 16MHz 1MHz= N(OCR0x+1) = 2N(OCR0x+1) 2MHz N = 1 and OCR0 = 7 N(OCR0+1) = 8 N = 8 and OCR0 = 0 OCR0A = 7; TCCR0A = (1<<COM0A0)|(1<<WGM01); //toggle, CTC TCCR0B = 0x01; //prescaler = 1 OCR0A = 0; TCCR0A = (1<<COM0A0)|(1<<WGM01); //toggle, CTC TCCR0B = 0x02; //prescaler = 8 13

Wave generating in Timer2 Like Timer0

The difference between Timer0 and Timer2 CS02 CS01 CS00 Comment 0 0 0 Timer/Counter stopped 0 0 1 clk (No Prescaling) 0 1 0 clk / 8 0 1 1 clk / 64 1 0 0 clk / 256 1 0 1 clk / 1024 1 1 0 External clock (falling edge) 1 1 1 External clock (rising edge) CS22 CS21 CS20 Comment 0 0 0 Timer/Counter stopped 0 0 1 clk (No Prescaling) 0 1 0 clk / 8 0 1 1 clk / 32 1 0 0 clk / 64 1 0 1 clk / 128 1 1 0 clk / 256 1 1 1 clk / 1024

Timer1 Timer1 has two waveform generators

In non PWM modes

Capturing in Timer/counter 1

Capturing Usages Measuring duty cycle Measuring period TCNT1H TCNT1L ICR1H ICR1L 19

Capturing 20

Copied from ATmega328 datasheet page 239 Comparator Copied from ATmega328 datasheet page 239 21

ICNC1: Input Capture Noise Canceller 0:disabled 1:Enabled (captures after 4 successive equal valued samples) ICSES1: Input Capture Edge Select 0: Falling edge 1: Rising edge ACIC: Analog Comparator Input Capture Enable 0: ICP1 provides the capture signal 1: analog comparator is connected to the capturer 22

Measuring duty cycle and period 23

Example: Measuring the frequency of a wave which is between 1 µs and 250 µs. #include <avr/io.h> int main ( ) { unsigned char t1; DDRD = 0xFF; //Port D as output PORTB |= (1<<0); TCCR1A = 0; //Timer Mode = Normal TCCR1B = 0x42; //rising edge, prescaler = 8, no noise canc. while ((TIFR1&(1<<ICF1)) == 0); t1 = ICR1L; TIFR1 = (1<<ICF1); //clear ICF1 flag TCCR1B = 0x02; //falling edge PORTD = ICR1L - t1; //pulse width = falling - rising while (1); //wait forever return 0; }