Go Down

Topic: Arduino Due Loopback (Read 2179 times) previous topic - next topic


I'd like to create a simple unit test for the Due Dac0.  It seems that the simplest approach would be to loop back Dac0 to A11. However there seem to be a number of people who have burned out their DACs, so I am a bit leery of just hooking them together.

Here are what I believe to be the appropriate specs.

Analog Input (ADC)
P1028 of Atmel_6500_32-bit-Cortex-M3-Microcontroller_SAM3S_Datasheet.pdf
ADVREF Input DC impedance   14 k?

Analog Output (DAC)
P1033 of Atmel_6500_32-bit-Cortex-M3-Microcontroller_SAM3S_Datasheet.pdf
RLOAD   Output Load Resistor   5 ??

So can I wire these pins together directly or do I need to do anything additional? (e.g. a current limiting resistor?  If so, what value?)



The only way I can see of you burning out the DAC is if the analogue input gets switched to a digital output and set to LOW, effectively shorting the DAC to ground.

I would add a small (~100?) resistor between the DAC and the ADC just to be safe.


I placed a 10K resistor between Dac1 and A7 on a Due Board, used the sketch below to look at A7-A11 and got the attached plot. 

  • the bottom limit of A7 is 665, which is close to 4096 * 1/6 (682) which is expected.

  • the top limit of A7 is 3424, which is close to 4096 * 5/6 (3413) which is expected.

  • A8-A10, are not hooked to anything.  From the plot, I would guess that crosstalk is an issue with these boards.  (I also ran the code with no resistor, and a7-a11 were noisy, but not ramping.)  Is that accurate?  Do I need to terminate unused pins on this device, or programmatically initialize them in some particular way?

Code: [Select]

void setup() {
  // put your setup code here, to run once:
  analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)
  analogReadResolution(12);   // set the analog input resolution to 12 bit

  Serial.print("\n>Dac0 ADC Loopback Test\n");

int i = 0;
void loop() {
  // put your main code here, to run repeatedly:
    analogWrite(DAC1, i);
    analogWrite(DAC0, i);
    Serial.print(String(i) + "," + String(analogRead(11)) + "," + String(analogRead(10)) + ","
    + String(analogRead(9)) + "," + String(analogRead(8)) + "," + String(analogRead(7)) + "\n" );
    if(i >= 4096)  // Reset the counter to repeat the wave
      {i = 0;}


It's all to do with the way the ADC works.  It uses a method known as "sample and hold".  There is a small capacitor in the input, and the ADC "samples" the input voltage into that capacitor, then "holds" it there while it converts that stored voltage into a digital value.  With nothing connected to an input pin, when the multiplexer switches the capacitor to sample that input, there will still be some of the old charge left in it - couple that with noise picked up by the pin, and you get a rough trace influenced by the previous channel that had any real input.

One good trick with this kind of ADC is to have one input dedicated as a purging input.  Connect it to ground through a small resistor (say 100 ohms) and sample that channel in between each channel you are interested in.  This ensures that the S&H capacitor is purged of residual charge between readings.  The resistor is important to reduce current flow, but you want it small enough that the capacitor discharges in a reasonable time.  Yes, you could short it direct to ground, but then you run the risk of too much current being drawn through the pin and killing the IO port (what happens if the pin gets switched to output and high?  *pop*).

For instance, compare these two graphs.  4 channels, sampled in the order red, green, glue, magenta.  The red channel has input, the others don't.

In this image all the other inputs are just floating and read in order.

However, in this image an extra channel is linked to ground, with a 10Ω resistor in this case (though that may be a bit small TBH) and is read in between each of the other channels.  You can see how each channel has less and less of the charge from the red channel left in it.


Thanks.  That is a very clear exposition.

Go Up