DAC on Arduino Duo Bug - large (0.54 V) zero offset.

Hi,

I am trying to use the Arduino DACs to generate reference voltages for some discriminators that will be used (eventually) to generate interrupts. It seems to me there is a bug in code/hardware for writing to the DACs. The following code should produce about zero voltage. The output measured with a 100 MOhm DVM is 0.542 V

int threshold = 0; // Set threshold //
void setup()
{
analogWriteResolution(12); ; // set resolution to 12 bits (4096)
}
//
void loop()
{
analogWrite(DAC0, threshold); // analogWrite values from 0 to 4095
delay(10);
}

Likewise, setting the first line to: int threshold = 4095; gives 2.74 V, while: int threshold = 2047; gives 1.64 V. I deduce from this that the conversion follows a V = A*threshold + 0.542V law, where A is the conversion value. Reading the data sheet for the processor (AT91SAM.pdf) indicates the zero offset should be ±4 LSB which should corresponds to about ±10 mV for a 2.74 V max output. This is much less than the ~0.54 V actually measured. :o ADC1 behaves exactly the same way. ::slight_smile:

This issue is not a big problem for AC coupled circuits, such as audio processors. However, it is a problem when you want to digitally produce low frequency and DC voltages for control purposes.

The only workaround I have found is to use pulse width modulation (PWM) for low frequency voltages. It is unfortunate as it increases the component count by a resistor, and two capacitors per channel. :blush:

If anybody has a solution, I am grateful.

Harry J. Whitlow

Read the datasheet. The code example should NOT produce 0v. The designers of the SAM3X chip decided not to include rail-to-rail output.

A rail-to-rail opamp is a specialised device, which comes with certain limitations. If you can design to those limitations, then put one into your circuit. Otherwise, use a regular opamp with a negative-rail power supply.

Dear MorganS,

Thanks for the quick reply.

I had indeed read the manual (11057B–ATARM–28-May-12) for the SAM3X, but not the latest one :-[ , Atmmel-11057C-ATARM-SAM3X-SAM3A-Datasheet_23Mar_15 (which is still marked "DRAFT"). There on page 1412 there is a new Table (45-44) which defines the output span as 1/6 to 5/6 times the reference voltage. Taking the reference voltage to be 3.3 V This gives the DAC output span is 0.55 to 2.75 V, which is almost identical to the voltage I measured.

Since the DAC output voltage span is quite an important piece of information for users, this (new) information could usefully be included in the official Arduino Duo page.

I also agree with your comment about rail-to rail analogue devices. The best practice is to use dual ± supplies. I simply use a Max556 voltage inverter fed from the +5V line to give a -5V line so that no extra supply is needed.

Many thanks!

Harry J. Whitlow

Like anyone, it's difficult to admit to a mistake. The Due probably is a mistake to try to include it in the Arduino system. It doesn't seem to get the support it needs, like correct documentation and a Serial method that moves faster than a glacier.

I'm surprised to hear there's another datasheet. I haven't come across that before.