DAC MCP4725 programming problems

Hello,

I am attempting to use a MCP4725 DAC to output a constant analog voltage to a circuit. The analog output should be constant, but adjustable from 0 - 5V. I have a problem with the function dac.setVoltage(value, storeflag).

Sometimes it works and sometimes it doesnt. For instance if I say dac.setVoltage(100, false), it uploads fine, and using the analogRead function I read my output from the DAC and I get a value of about 50. This is what it should be since the DAC is 12-bit and the arduino ADC is only 10 bit (10-bit read values should be about 1/4 of the 12-bit output). HOWEVER, if in the next upload I say dac.setVoltage (400, false), it does not change the voltage that I read (still 50!) even though the program uploads successfully. It generally works for value values 0-300, won't work 500- about 1000 and then will work for some higher values as well. Every time it doesn't work it just keeps the value from the last run that works.

To simplify my troubleshooting and make sure I didn't make some small error elsewhere, I just modified the triangular wave example code to not set the voltage equal to the counter but to the constant voltage that I want, and to read back the voltage from the output:

#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

void setup(void) {
Serial.begin(9600);
Serial.println("Hello!");
dac.begin(0x62);
Serial.println("Generating a triangle wave");
}

void loop(void) {
uint32_t counter;
for (counter = 0; counter < 4095; counter++)
{
dac.setVoltage(400, false);
int k=(analogRead(A2));
Serial.println(k);
}
for (counter = 4095; counter > 0; counter--)
{
dac.setVoltage(400, false);
int k=(analogRead(A2));
Serial.println(k);;
}
}

I don't think this is a hardware problem, because the triangle and the sine wave both work, and the values that are "forbidden" when I attempt to access them as a constant voltage, are accessed when the program does the triangle wave or sine wave.

Thanks in advance for any help, can't figure this one out....

Oh, maybe I should have mentioned that earlier today that there was a small problem where I accidentally plugged the A0 pin into a external power supply that was set at 12 V (powering op amps). This caused the board to short out and even turned my computer off. Everything seemed to work properly after this though. I'm not sure if the dac.setvoltage function worked properly before this because I never tested it. But again the triangle wave and sine wave both work perfectly, so I don't see how this could be a hardware problem...

Are you talking about your Arduino? Yes, you should have mentioned that.

Go to Atmel's site and download the datasheet for the ATmega328p. Get the full one, not the summary. Find the Absolute Maximum Ratings in the Electrical Characteristics section. It will inform you that the maximum operating voltage is 6.0 V, and that the maximum voltage on any pin is half a volt higher than Vdd.

It also says this next to the table (emphasis added):

Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent da-
mage to the device. This is a stress rating only and
functional operation of the device at these or
other conditions beyond those indicated in the
operational sections of this specification is not
implied. Exposure to absolute maximum rating
conditions for extended periods may affect
device reliability.

There is a good chance you have damaged your chip's ADC, and possibly more. Try a different pin. If it's bad, I believe Sparkfun and Adafruit sell 328Ps with the Arduino bootloader preloaded.