Go Down

Topic: PWM Resolution (Read 3 times) previous topic - next topic


Hi there.

One thing I don't understand is why the pwm resolution is locked to 12bit. The Output comparator is 16bit, why can't we have 16bit pwm resolution?


Oct 27, 2012, 06:06 pm Last Edit: Oct 27, 2012, 06:27 pm by alvesjc Reason: 1
Ok, next time I'll test first.

The documentation is confusing.

If you read the analogwriteresolution() function documentation, you get the idea that only 12 bit is suported.


Well, in fact, no!

I've tested with the fade test sketch changing to 16 bit resolution and while verifying with a multimeter, I can say, it works!!  ]:D

This is a very nice improvement!!! :D

Sketch used:

Code: [Select]


This example shows how to fade an LED on pin 13
using the analogWrite() function.

This example code is in the public domain.

int led = 13;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 1;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  {
  // declare LED pin to be an output:
  pinMode(led, OUTPUT);

// the loop routine runs over and over again forever:
void loop()  {
  // set the brightness of LED pin :
  analogWriteResolution(16);  // Set pwm to 16bit resolution
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 65535) { //65535 is the maximum value for a 16bit number
    fadeAmount = -fadeAmount ;
  // wait for 5 milliseconds to see the dimming effect   


Oct 27, 2012, 07:47 pm Last Edit: Oct 27, 2012, 07:48 pm by giantsfan3 Reason: 1
Awesome. I can't wait to get a board and use the DAC!
Although I wish there were also a 16-bit ADC on the uC.



I'm speaking about PWM ports, not DAC!

DAC is 12bit only I think.


Thanks for this, it will be interesting to disassemble the sketch and see what is being configured and how.

Reading another post in this section I see that there are timers and separate PWM Channels, I am guessing that the PWM Channels address specific pins like on the AVR's and that withe the timers you can use software PWM on any pin.

Duane B

Go Up