Go Down

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

Rubbernose

Hello,

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?

weird_dave

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

Rubbernose

#2
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:
  Serial.begin(57600);
   analogWriteResolution(12);
   pinMode(analogOutPin, OUTPUT);
}

void loop() {
  A++;
  analogWrite(analogOutPin, A);
  if (A>=4095) {A=0;}
  Serial.println(A);
  delay(50);
}

ard_newbie


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.

Rubbernose

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

ard_newbie

#5
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%).

Rubbernose

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