[AVR]/Mega82012. 5. 9. 23:51

[ATmeag88] Timer2 테스트 - 8-bit Timer/Counter2 with PWM

[ATmeag88] Timer2 테스트 - 8-bit Timer/Counter2 with PWM


- Single Channel Counter
- Clear Timer on Compare Match (Auto Reload)
- Glitch-free, Phase Correct Pulse Width Modulator (PWM)
- Frequency Generator
- 10-bit Clock Prescaler
- Overflow and Compare Match Interrupt Sources (TOV2, OCF2A and OCF2B)
- Allows Clocking from External 32 kHz Watch Crystal Independent of the I/O Clock





Timer2 초기화

#define TIMER2_VALUE      (256-115)


#define TIMER2_CLK_DIVCLK                   1
#define TIMER2_CLK_DIV8                     2
#define TIMER2_CLK_DIV32                    3
#define TIMER2_CLK_DIV64                    4
#define TIMER2_CLK_DIV128                   5
#define TIMER2_CLK_DIV256                   6
#define TIMER2_CLK_DIV1024                  7


#define TIMER2_DISABLE_PWM                 0



#define TIMSK        TIMSK2
#define TIMER2_INT_ENABLE     BIT0
#define Timer2Set(Value)     (TCNT2 = Value)
#define TCCR2        TCCR2B


//Initialize Timer2

void IntitTime2(void)

    // Enable Timer 2 output compare interrupt


    // Start timer 2 with prescaler 128

    Sbi(TCCR2, TIMER2_CLK_DIV128);

   //set 1ms



Timer Interrupt Handler








Posted by nexp

댓글을 달아 주세요