ATmega128 Timer/Counter

  • Upload
    debbie

  • View
    296

  • Download
    10

Embed Size (px)

DESCRIPTION

ATmega128 Timer/Counter. Timer 일정 주기의 Clock 신호를 Counting 일정한 시간 주기를 갖는 펄스의 발생 . 주파수 ( 주기 ) 제어 펄스 폭 제어 Counter 속도 측정 : 외부 핀을 통해서 들어오는 Event 를 일정 시간 동안 Count(Edge Detector) 한다 . Input Capture (Timer1, Timer3) - PowerPoint PPT Presentation

Citation preview

PowerPoint Presentation

KyungHee Univ.2-0 ATmega128 Timer/Counter

0KyungHee Univ.1-1Atmega128 Timer/Counter Timer Clock Counting .() Counter : Event Count(Edge Detector) .Input Capture (Timer1, Timer3) ( ) : Timer/Counter Register Capture ( ) . : Timer/Counter , Input Capture Pin .KyungHee Univ.1-2Atmega128 Timer/CounterTimerClock( ) Event(Interrupt) .Counter (TOSC1, TOSC2, T1, T2, T3) Event Count(Edge Detector) .ATmega128 Timer/Counter4 / .Timer/Counter0(8) Timer/Counter1(16) Timer/Counter2(8) Timer/Counter3(16)KyungHee Univ.1-3Timer/Counter (8-bit 0,2 16-bit 1,3) Clear Timer on Compare Match (Auto Reload)Pulse width Modulator (PWM)Frequency Generator10-bit Clock PrescalerOverflow and Compare Match Interrupt Sources (TOV2 and OCF2)Allows Clocking from External 32 kHz Watch Crystal Independent of the I/O Clock (Timer0)External Event Counter (Timer1,2,3)Input Capture (Timer1, 3)

KyungHee Univ.1-4Timer/Counter0, 2Timer/Counter0 2 8 OVERFOLW, PWM .Counter : 8(0x00 ~ 0xff)Prescaler : 10, 8 Clock Interrupt : Overflow, Output Compare MatchTimer/Counter0, 2 Clock Clock Pre scale Counter Clock .Timer/Counter0 : 32.768kHz(2**15 = 32,768) TOSC1 TOSC2 RTC .KyungHee Univ.1-5Timer/Counter0 Block Diagram

Asn:1 Clock( )Asn:0 Clock() Clock ClockKyungHee Univ.1-6Timer/Counter1,3 Block Diagram

KyungHee Univ.1-7Timer/Counter0 Counter Unit Block Diagram

KyungHee Univ.1-8Timer/Counter2 Counter Unit Block Diagram

EventInputKyungHee Univ.1-9Timer/Counter0 Output Compare Unit, Block Diagram

KyungHee Univ.1-10Timer/Counter0 Compare Match Output Unit

KyungHee Univ.1-11TCCR0 - Timer/Counter Control Register/ Bit 7 : FOC0(Force Output Compare)Non-PWM mode Bit 1 Write TCNT0 OCR0 Rg Compare Match OC0 () . Compare Match OC0 Update . Bit 3,6 : WGM01,WGM00(Waveform Generation Mode) Bit 5,4 : COM01, COM00(Compare Match Output Mode) Bit 2,1,0 : CS02~CS00(Clock Select)

KyungHee Univ.1-12Waveform Generation Mode Bit Description

Compare Output Mode, non-PWM ModeCTC: Clear Timer on Compare Match KyungHee Univ.1-13Timer/Counter 0 Operation ModeNormal ModeOverflow Interrupt Up Counter 0x00~0xff Counting .TCNT .MAX = 0xff Overflow Interrupt Out Compare (COMP) Interrupt Mode KyungHee Univ.1-14Timer/Counter 0 Operation ModeCTC Mode(Clear Timer on Compare Match Mode) Up Counter0x00~OCR0 CountingOCR0 TCNT0 ClearTCNT0 = OCR0 Output Compare Match Interrupt (OVF) (MAX=OCR0 , COMP )KyungHee Univ.1-15Timer/Counter 0 Operation ModeCTC Mode, Timing Diagram

KyungHee Univ.1-16Compare Output Mode, Fast PWM ModeCompare Output Mode, Phase Correct PWM Mode

KyungHee Univ.1-17Timer/Counter 0 Operation ModeFAST PWM PWM (Single-Slope Operation)0x00~0xFF TCNT0 OCR0 Compare Match OC0 LOW(COM0 1:0 = 2)0xFF 0x00 : Overflow OC0 HIGH(COM 1:0 = 2)KyungHee Univ.1-18Timer/Counter 0 Operation ModeFast PWM Mode, Timing Diagram

KyungHee Univ.1-19Timer/Counter 0 Operation ModePhase Correct PWM PWM 0x00 0xFF 0xFF 0x000x00 ~ 0xFF ~ 0x00 Compare Match >> OC0 = 0(COM1:0=2) Compare Match >> OC0 = 1(COM1:0=2)KyungHee Univ.1-20Timer/Counter 0 Operation ModePhase Correct PWM Mode, Timing Diagram

KyungHee Univ.1-21Clock Select Bit Description

KyungHee Univ.1-22Prescaler for Timer/Counter0

KyungHee Univ.1-23TCNT0 - Timer/Counter Register

OCR0 - Output Compare RegisterTimer/Counter 0 8 Count RegisterTimer/Counter 0 8 Counter TCNT0 OC0 8 RegisterKyungHee Univ.1-24ASSR - Asynchronous Status RegisterBit 3 AS0: Asynchronous Timer/Counter0 AS0 = 0 : (clkI/O) AS0 = 1 : (TOSC1) Bit 2 TCN0UB: Timer/Counter0 Update BusyBit 1 OCR0UB: Output Compare Register0 Update BusyBit 0 TCR0UB: Timer/Counter Control Register0 Update Busy

KyungHee Univ.1-25TIMSK - Timer/Counter Interrupt Mask RegisterBit 1 OCIE0: Timer/Counter0 Output Compare Match Interrupt EnableOCIE0 Set Output Compare Match Interrupt .Bit 0 TOIE0: Timer/Counter0 Overflow Interrupt EnableTOIE0 Set Overflow Interrupt . SREG I Bit 1 .

KyungHee Univ.1-26TIFR - Timer/Counter Interrupt Flag RegisterBit 1 OCF0: Output Compare Flag 0TCNT0 OCR0 1 Set, Output Compare Interrupt . 0 Clear.Bit 0 TOV0: Timer/Counter0 Overflow Flag/ Overflow 1 Set Output Compare Interrupt . 0 Clear. Bits 1 Write Flag Clear .

KyungHee Univ.1-27SFIOR - Special Function IO RegisterBit 7 TSM: Timer/Counter Synchronization Mode Bit 1 Writing Timer/Counter Synchronization Mode . Mode PSR0, PSR321(Prescaler Reset ) . Timer/Counter . Bit 0 Write PSR0, PSR321 Hardware Clear Timer/Counter Counting .Bit 1 PSR0: Prescaler Reset Timer/Counter0 Bit 1 Writing Timer/Counter Prescaler Reset . Bit Hardware Clear . (TSM Bit Set Clear .)

KyungHee Univ.2-28Timer

cho_timer1_int_clock_gen cho_key_debounce_timer1 cho_keypad_basic_soft_timer2_delay cho_input_capture_pulse_width_measure cho_led_PWM_bright_control