PWM generation using ATmega 88 - LED brightness control

Started by nandak84 December 3, 2005
Hi guys,
Finally I have written up a code to generate PWM, and by changing the
output compare I am able to vary the brightness of my LED. I also went
ahead to use interrupts so that everytime there is a match, the
Interrupt Service routine could increment the output compare value, so
that the LED can increase in brightness gradually.

I had written the Following code:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>

#define OC0A PD6
#define OC0B PD5
#define DDROC DDRD
#define sei() __asm__ __volatile__ ("sei" ::)
#define cli() __asm__ __volatile__ ("cli" ::)

// Declare Function prototype
void initialise (void);

int main (void){


void initialise (void){

/* Set the Waveform generation mode using WGM bits and Compare output
mode using COM bits*/
TCCR0A = _BV (WGM00) | _BV (COM0A1) | _BV (COM0A0) | _BV(COM0B1) |

TCCR0B = _BV(WGM02);

/* Set the Clock select bits to determine Clock frequency*/
TCCR0B = _BV (CS00);

/* Set PWM value to 10 : Both LEDs are of same brightness*/
OCR0A = 0x10;
OCR0B = 0x10;

/* Enable OC0A and PD6 as output */
DDROC = _BV(OC0A) | _BV(OC0B) ;

/* Enable interrupts*/

OCR0A = 0CR0A + 0x10;
if (OCR0A >= 0xff)
OCR0A = 0x00;
******************************END of CODE***********************

As you can see that I am tryin to light two LED's starting with the
same brightness, but just setting the interrupts on one of them.
But for some reason, the code does not alter the brightness of the
LEDs, I am a bit puzzled as to why this is so.

I would like to thank all the people who replied to my previous
message, and directed me. This is a great help to a person who is just
getting acquainted to Atmel micro programming.

It would be really helpful if you guys could help me with this
problem. I am currently just learning PWM control on Atmel, eventually
I have been asked to generate a Sine wave using Pwm to control a
brushless DC motor (3 phase).

I would really appreciate any help from you folks. Thanks heaps.