DAC-ADC

I just got an Arduino Due, and in testing the ADC and DAC functionality came across an issue I couldn't resolve.

I tested the ADC/DAC by connecting A0 and DAC0 together. I then set the output of the DAC0 in the loop between the values of 0 and 4095. Then I read A0 with analogRead. A funny thing happens with the read though. While I set the DAC to go between 0-4095, the values I read with the ADC range from 663-3400 (approximately 600 bits off either rail). I have generated an image showing this (http://i50.tinypic.com/2hcp8wx.png).

I could map to the acquired range to the desired range, but this doesn't really fix the issue. I'm hoping someone can help me understand why this is happening and offer a solution to reading values between 0 and 4095. When I probe VCC and GND with the ADC I read 4080 and 0 respectively.

My code is below:

const uint32_t DACPIN = DAC0;
const uint32_t ADCPIN = A0;

void setup( void ) {
  // Set up serial port
  Serial.begin( 115200 );
  
  // Set up ADC/DAC
  analogWriteResolution( 12 );
  analogReadResolution( 12 ); 
  
  pinMode( DACPIN, OUTPUT );  
}

// Main loop
uint16_t val = 0; 
void loop( void ) {
  val = (val+1) & 0x0FFF;
  
  // Write and read the values 
  analogWrite( DACPIN, val ); 
  delay( 1 ); 
  const int adcVal = analogRead( ADCPIN ); 
  delay( 1 ); 
  
  Serial.print( "[" ); 
  Serial.print( val ); 
  Serial.print( "," ); 
  Serial.print( adcVal ); 
  Serial.print( "],\n" ); 
}

Hi,
This is a feature of the SAMX chip, the DAC does not output from 0 to 3.3v, it does offer 12 bit resolution, but in a narrower analog range.

There is a previous post somewhere which will give your the range - or you could calculate it from your analog in readings which offer 12 bit resolution over the full 0 to 3.3v range.

Finally - look after your DAC, a few of use have killed ours by accidentally drawing too much current.

Duane B

rcarduino.blogspot.com

Hello,

I followed your code. And my Arduino due ADC reading from DAC pin is noisy and the difference is large. Please see the pic.
Is this normal?

Thank you.

compare.jpg