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

Timer/Counter0 High Speed PWM Mode (ATmega168)

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

Timer0PWMTest

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

#include <avr/io.h>

//-----------------------------------------------------------------------------
//  Initialize Timer/Counter0 for PWM
//-----------------------------------------------------------------------------
void init_PWM_Timer0()
{
    DDRD |= _BV(PD6);       // Set PD6(OC0A) Output

    TCCR0A = 0b10000011;    // Compare Match Low
                            // 8 bit High Speed PWM
    TCCR0B = 0b00000101;    // clk/1024 125nsX1024=128us

    OCR0A = 128;            // Set Output Compare Register
}

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

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

    return 0;
}

Attach file: fileTimer0PWMTest.c 985 download [Information] fileresult.jpg 904 download [Information]