Fast PWM using atmega2560 .

#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#define PIN_OCOB PG5

void initPWM();

int main(void)
{
	
     initPWM();	
		
    while (1) 
    {
	//set the duty cycle
	OCR0B = 128;//50% duty cycle
		
	_delay_ms(10);
    }
}

void initPWM()
{
	
	//        FAST PWM                | CLEAR OCOA ON COMPARE
	TCCR0A |= (1<<WGM01) | (1<<WGM00) | (1<<COM0B1) | (0<<COM0B0);
	
	//CS = NO PRESCALE  
	TCCR0B |= (1<<CS00) ;
	
	//Enable OCOA PWM pin	
	DDRG |= 1<<PIN_OCOB;
	
}

About PraveenMax
My Interests: ------------------ Programming , Drawing & Music

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: