0

I use a simple serial connection to tell the Due what to output into an analog output pin. However, the outputs are offset about 550mV (as seen on an oscilloscope) and the maximum value of 255 gives ~2.7V. What am I missing? Why can't the DAC output 0V - 3.3V mapped onto 0 - 255 values?

int output = DAC1; // analog output pin
String inData;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  while (Serial.available() > 0) {
    char value = Serial.read();
    inData += value;
    if(value == '\n'){
      val = inData.toInt(); // 0..255
      analogWrite(output, val);
      Serial.println(val);
      inData = "";
    }
  }
}
7
2

I don't know how old this thread is, anyway I thought it doesn't hurt to give some insight because I experienced the same problem. Look at: http://www.atmel.com/Images/Atmel-42187-ATSAM3X-and-ATSAM3A-Series-Checklist_AP-Note_AT03462.pdf page 13: DAC0 and 1 voltage lays between 1/6 ADVREF and 5/6 ADVREF which corresponds to approximately ADVREF=3.2v; Span is (4/6)*3.2 = 2.1v for periodic signals, Offset can be removed by using a small decoupling capacitor which will act as a high pass filter. Hope this helps

1
  • Thank you for help! Numbers on atmega datasheet do make sense, they are close to what I see on oscilloscope. – aaaaa says reinstate Monica Mar 24 '15 at 18:29
0
int output = DAC1; // analog output pin
String inData;
int val; 


void setup()
{
  Serial.begin(9600);

}

void loop() {
  while (Serial.available() > 0) {
    char value = Serial.read();
    inData += value;
    if(value == '\n'){
      val = inData.toInt(); // 0..255
      val=constrain(val, 543, 2720);
      analogWrite(output, map(val,543,2720, 0, 255));
      Serial.println(val);
      inData = "";
    }
  }
}
1
  • 2
    Hi and welcome. Please edit your answer and provide an explanation as to why your code works. Code only answers are frowned upon. Thanks. – Greenonline Aug 11 '20 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.