Generating PWM question (Mega128)

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

Hello,

I just want to straighten things out.

so to generate a PWM.. all i have to do, is use a timmer channel, and a compare register.. once they match.. just have it do what i want with the output.. is it really that simple??

Also, i'm a bit confused.. on the mega128, I know i can use the timmer channels 0 and 2 to do this.. but i'm confused about 2 and 3. cause they are 16 bit counters.. is there a way to use these as 8 bit counters??

thanks

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

- Configure the OCnx pin as an output by modifying the correct DDR.
- Configure the TCCRnx register(s) to operate the timer in the correct WGM mode, with the correct timer prescaler, and the correct COMnxy setting for PWM operation.
- Load the OCRnx register with the correct number for the duty cycle you want.

You can make make the 16-bit counters operate in 8-bit PWM mode if you want. Or you can operate them in 8, 9, 10, or arbitrary-resolution modes if you want more precise control over the available duty-cycles.

Look at table 61 in the ATmega128 datasheet.

You can access 8-bit fast (phase-incorrect) mode by using WGM mode 5, or modes 14 or 15 with the appropriate TOP (0xFF) defined in OCRnA or ICRn.

You can access 8-bit phase-correct PWM using WGM mode 1. Or modes 8, 9, 10, 11 with the appropriate TOP (0xFF) defined in OCRnA or ICRn.