DAC problem with MKRZERO

Hi everyone,

I have a really strange problem with my MKRZERO Arduino. One of the most important things I need to do for my project is to have a perfect control on the DAC. It's not really easy to find a lot of datasheets on this model, I only use the information below:

https://store.arduino.cc/usa/arduino-mkrzero

The Circuit Operating Voltage is 3.3V, and the DAC is supposed to be 10 bits. So normally, I should be able to create steps of 3.3/1023 Volt. In order to test that, I used the code below. (This is not the complete code, I only wrote the important steps, I know that this code cannot work by itself)

pinMode(A0,OUTPUT);                         //W_Voltage
analogWriteResolution(10);

for (float i=0; i <= 1023; i++){
    delay(500);
    analogWrite(A0,i);
    delay(500);
    Serial.println(i);
    }

If I connect a voltmeter between the ground and my A0/DAC Output, I can see by observing the Serial.println(i) on the computer that my DAC evolves in cycles of 2^8 - 1 = 255 steps. Which means that I read a 0V at step 0, step 256, step 512, etc... :confused: But it's not my main problem. The weirdest thing is, my DAC stops at 2.2V, which is related to the 175 step in my cycle of 255 steps. Whatever I do, my DAC cannot reach 3.3V. It is the same if I try this command.

analogWrite(A0,1023);

I will only read 2.2V, just like in my last test. Did this happen to anyone else? I would be really glad if you could tell me what you think, because this a huge problem for me, I mainly bought that Arduino for that, and if that does not work i'm kinda blocked.

Thank you so much for your help!

Sincerely yours,

Maxime Mano.

You may want to include the FULL sketch as partial ones don't always provide much insight.

Also thanks for an otherwise perfect post using code tags etc always nice to see.

Hello LizardOnTheBoard:

I have the same problem with my Arduino M0 and Arduino M0Pro.

Here is the Sketch:

void setup()
{
SerialUSB.begin(9600);
delay(6000);
pinMode(A0,OUTPUT);
pinMode(A1,INPUT);
analogWriteResolution(10);
}

void loop()
{
for(int i=0; i<1024; i++)
{analogWrite(A0,i);
int lee=analogRead(A1);
SerialUSB.println(i);
SerialUSB.println(lee);
SerialUSB.println(" ");
delay(5);}
}

Remove the pinMode(A0, OUTPUT) line.

https://forum.arduino.cc/index.php?topic=525853.0