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....