Go Down

Topic: Due and PWM resolution (Read 581 times) previous topic - next topic



i tried the examples with the analogWriteResolution(12).
The values can be send up to 4095, that's ok.
But the PWM duty cycle changes all 16 values.
That is a very bad resolution.
I checked it with another Due, but it's the same.
I use IDE 1.8.7

Who can help?


Can you post the code you used.
All 16 values of what are changed?


Nov 07, 2018, 02:13 pm Last Edit: Nov 07, 2018, 02:15 pm by Rubbernose
All 16 values of the A value (0-4095)

Code: [Select]
const int analogOutPin = 10;
int A =0;

void setup() {
  // initialize serial communications at 9600 bps:
   pinMode(analogOutPin, OUTPUT);

void loop() {
  analogWrite(analogOutPin, A);
  if (A>=4095) {A=0;}


You won't be able to get the maximum resolution with analogWrite() function.

Yu can output a PWM waveform either from the PWM peripheral or the Timer Counter. Search in the DUE sub forum for example sketches.


The Due  has the same resolution like the Mega?
4096 / 16 = 255
For what is the analogWriteResolution(12) if it's always the same?


Nov 07, 2018, 03:03 pm Last Edit: Nov 07, 2018, 03:04 pm by ard_newbie
The resolution depends on the frequency you need. The highest frequency with the maximum resolution (16 bit) is obtained with a frequency of 84 MHz/ 65535 ~ 1282 Hz because de duty cycle can vary between 0 (0%) and 65535 (100%).


I give up and prepared a solution with my old MEGA. That program is working with a resolution of 1024 (with changing of the resolution)

Go Up