DAC setVoltage behaving weird

Hey,

I just bought an MCP4725 DAC to my current project where I'm trying to control an engine by RPM by increasing and decreasing voltage.

I'm however having some difficulties with the setVoltage method. It seems like when I've set it once, it can't change.

I left the loop out because it's not relevant at the moment.

#include <Adafruit_MCP4725.h>   
#include <FreqMeasure.h>
#include <PWM.h>

Adafruit_MCP4725 dac;

int pwm_output = 11; 
int32_t frequency = 17500;  
long new_freq; 
long RPM;
long RPM_tot;
long RPM_wanted = 0; 
long voltage = 4095; 

void setup() {
  Serial.begin(9600);
  dac.begin(0x62); 
  dac.setVoltage(voltage, false);
  InitTimersSafe();
  FreqMeasure.begin();
  SetPinFrequency(pwm_output, frequency);
  pinMode(pwm_output, OUTPUT);  
  int sensorValue = analogRead(A0);
  pwmWrite(pwm_output, sensorValue/4);
  bool volt_change = dac.setVoltage(0,false); //motor should here stop, but continues. 
  if(volt_change){
    Serial.println("VOLT CHANGED.");
  }
}

The weird part is that it still prints "VOLT CHANGED". Any ideas what could be wrong? Or does the setVoltage method have limitations?

Thanks

W

I had problem like this due to wrong address at dac.begin(), check the datasheet

Thanks, but from what I've read the default adress for Unos is 0x62

Just tried a sketch that finds the i2c address, and it was indeed 0x62.

Just figured out my silly mistake. I must of course read from A0 again to change the speed, not only change the voltage output to A0.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.