Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes

Timer/Counter2 High Speed PWM Mode (ATmega168)

Last-modified: 2012-08-20 (Mon) 00:29:30 (1981d)
Top / Timer / Counter2 High Speed PWM Mode (ATmega168)

Timer2PWMTest

//-----------------------------------------------------------------------------
//  ATmega168
//  Internal 8 MHz RC Osc.
//  (1/8M = 125 ns)
//-----------------------------------------------------------------------------

#include <avr/io.h>

//-----------------------------------------------------------------------------
//  Initialize Timer/Counter2 for PWM
//-----------------------------------------------------------------------------
void init_PWM_Timer2()
{
    DDRB |= _BV(PB3);       // Set PB3(OC2A) Output

    TCCR2A = 0b10000011;    // Compare Match Low
                            // 8 bit High Speed PWM
    TCCR2B = 0b00000111;    // clk/1024 125nsX1024=128us

    OCR2A = 128;            // Set Output Compare Register
}

//-----------------------------------------------------------------------------
//  Main
//-----------------------------------------------------------------------------
int main()
{
    init_PWM_Timer2();

    while (1) {
        asm("sleep"::);
    }

    return 0;
}

Attach file: fileTimer2PWMTest.c 836 download [Information]