PWM simple program not working

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey I read tutorials on PWM from tutorials section and then tried to implememnt P&F correct PWM. But unfortunately I can't see any o/p on the led.Im using an atmega8 can anyone point out the problem.

#include
#include

void main()
{int count=0;
DDRB=(1<<2);
OCR1B=49;
TCCR1A=(1<<WGM10);
TCCR1B=(1<<WGM13);
TCCR1A|=(1<<COM1B0);
TCCR1B|=(1<<CS10)|(1<<CS12);

while(1)
{
while ((TIFR & _BV(TOV1))==0); // wait for timer overflow
		TIFR |= _BV(TOV1);	// Clear the flag by writing 1


if(count>=10)
{OCR1B=490;
count=0;
}

else
{count++;
}

}

}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm not realy sure, but isn't only OCR1A enabled and not OCR1B?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i wish to toggle OCR1B so i have enabled just that pin for OCR1B is PB,2

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

aha... but setting that pin to output doesn't make it a pwm output automaticly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey i found my mistake in that code actually the mode i selected had ocr1a as TOP since i hadn't given that output remained low.thanks for the reply.I will post a re vised code and see if that works.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
hey i found my mistake in that code actually the mode i selected had ocr1a as TOP since i hadn't given that output remained low.

that's what i ment ;)