at90usb646 timer0 fast pwm info

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

Hello!!

i have a simple qestion for you about at90usb646.

I'm newbe with fast pwm mode but i know more or less behavior of timers in ctc mode.

I'm reading mcu's datasheet and i'm confused for job of OCR0A register. I read that OCR0A register is used to set TOP of counting.  FOr example, if i set OCR0A = 99, TCNT0 count from 0 to 99. However, i read in a tutorial from another site and in same datasheet that OCRnx register is used to setting the compare value. But, i want to generate a pwm signal and OCR0A can be used to setting frequency or duty cycle?? Because if OCR0A set TOP than it set a frequency but if OCR0A set a compare value than it set a duty cycle.
Excuse me but i'm confused.

in closing i need to generate pwm signals with variable frequency and duty cycle.
Best regards!

Marco
ps: sorry for my bad english writing.

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

When using a mode with OCRxA as TOP, use that to set the period of the PWM and then use OCRxB for the duty cycle of OCxB.

In this mode, you can not use OCRxA for varying the duty of OCxA.

 

Edit: If you use a mode with ICRx as TOP, then both OCRxA and OCRxB may be used for setting duty cycles...

David (aka frog_jr)

Last Edited: Sun. Jul 16, 2017 - 02:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

THank you!

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

uomodellaforesta wrote:
Because if OCR0A set TOP than it set a frequency but if OCR0A set a compare value than it set a duty cycle. Excuse me but i'm confused.

As mentioned, it depends on what timer mode you are using.  I'll have to dig up that datasheet, but isn't there more than one "Fast PWM" line in the mode chart?

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Sun. Jul 16, 2017 - 02:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello theusch!

i've forgotten to explain pwm setup. I use fast pwm setup with 7 mode.

Now i've a new question:

Must i update OCR0B in overflow isr everytime?

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

uomodellaforesta wrote:
Must i update OCR0B in overflow isr everytime?

No.

 

Short answer is that there are normally no ISRs needed for PWM.  Let the timer do the work.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

OK!! thanky ou. 

But in this document http://ww1.microchip.com/downloads/en/DeviceDoc/doc7593.pdf at page 105 i read:

 

"The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches TOP. If the interrupt is enabled, the interrupt handler routine can be used for updating the compare value."

 

for what is this useful?

 

in any case, if i understand, i don't update OCR0B and it correctly work!

Thank you!

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

uomodellaforesta wrote:
for what is this useful?

There are many ways to use timers.  Often, it is useful to have a routine that is carried out when a certain "event"  occurs.  As you see from the timer documentation, this could be a compare match or overflow or input capture or...

 

If you look down the list of interrupt vectors for your device, you see tall of the possible events that could be used with the various subsystems.  A typical full application may use a few of them.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.