Simple pwm question, plz help!

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

Hello,
I am using ATmega8.

I am trying to understand pwm set-up. I read many tutorials but I want confirmation that I undestand it.

For pwm, timer goes up and down to a TOP value, there is a compare level (OCR1AH, OCR1AL). When the timer reach this levels, a flag is shown.

So for me, the compare level set the duty cycle and the TOP level the frequency.

However, I do not understand how to set the actual value of the TOP... I dont understand where this is define.
Sorry for this stupid question... :oops:

Many thanks!

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

Somewhere in the data sheet, in the section for the timer you are using, there is a table with the different timer modes. In this table there is a column where it is stated what is used as the TOP value for each mode. For some modes it is a constant fixed value (eg 0xFF), for others it is the value in a register (eg ICR1 or OCR1A).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

this sample code runs at atmega8 16MHz and put a led to OC1A pin (PB1) to see the result. hope it'll help you

	TCCR1A = 0x82;		//inverting fastPWM mod 14
	TCCR1B = 0x1D;		//1024-prescaler
	ICR1 = 15624;		//freq = 1Hz
	OCR1A = 7812;		//duty = 50%	
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you both for your help.