Fast PWM in Mega8

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

I can't seem to make my Mega8 work in fast PWM mode /w Timer1
Just to be sure, I set all bits in the compare registers to 1 before anything else.
Then I set the apropriate bits for Mode 7 - 10bit fast PWM:

Mode   WGM13   WGM12(CTC1)   WGM11(PWM11)   WGM10(PWM10)
7      0       1             1              1

When running the code in latest AStudio, the counter bounces at $03FF and counts backwards down to $0000 and then fires the interrupt.
That looks more like mode 3 - PWM, Phase Correct, 10-bit.
To me, this looks like it might be a bug in AVRStudio, and it's ignoring the WGM12 bit, but I'm not sure...

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

AVRStudio does not do a good job at PWM simulation. Try the real chip.

Lee

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

Erf...
I'll try that.
This code is going into a mega48 eventually, but that order haven't arrived yet, so I'm testing some PWM stuff on the M8 just as "proof of consept".

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

If I remember correctly, AVRStudio does the "old" fixed-resolution fast PWM modes correctly, but has problems with the highe-numbered modes. Good luck; AFAIK the AVRs do PWM as described in the datasheets.

Lee

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

theusch wrote:

Quote:
If I remember correctly, AVRStudio does the "old" fixed-resolution fast PWM modes correctly.

A while back I was using AVRStudio to simulate "Fast PWM" and it became apearent that the timer/counter counted up to OCRx and then reversed, counting back down to zero, rahter then simply resetting the timer/counter to zero. Not being too fimiliar with assembly coding for the AVR, this gave me fits for a while, until I moved over to real hardware and discovered that the code was, in fact, working correctly.

I was using a Mega64 or a Mega128, I think.

Because of this, I tend to stay away from the AVRStudio simulator and use real hardware for all but simple I/O port and integer math experimentation.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston