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 = "";
 }
 }
}
Greenonline
3,1527 gold badges36 silver badges48 bronze badges
asked Mar 20, 2015 at 22:17
7
  • What is the voltage on VDDANA? Commented Mar 20, 2015 at 22:27
  • how do I check that? Commented Mar 20, 2015 at 22:31
  • With the black lead of the DMM on ground and the red lead on VDDANA, with the DMM in DC volts mode. Commented Mar 20, 2015 at 23:36
  • it reads about 4.2V, if by VDDANA you mean Vin pin. I don't know where to measure VDDANA otherwise Commented Mar 21, 2015 at 1:11
  • The datasheet for the MCU gives its pinout. Commented Mar 21, 2015 at 1:11

2 Answers 2

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

answered Mar 24, 2015 at 9:01
1
  • Thank you for help! Numbers on atmega datasheet do make sense, they are close to what I see on oscilloscope. Commented Mar 24, 2015 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 = "";
 }
 }
}
Greenonline
3,1527 gold badges36 silver badges48 bronze badges
answered Aug 11, 2020 at 20:47
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. Commented Aug 11, 2020 at 21:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.