Questions about speeding up i2c dac.

warpigs330

Active member
I am working with the MCP 4728. I am using it to output control voltage for a modular synth. I am using the adafruit library to interface with it. I am basically making an LFO and am running into an issue. when I control volume with the dac I get some zipper noise when the signal moves fast. I am assuming this is based on rate at which I write to the dac, and I noticed that my code ran like 10 times faster when not writing to the dac. I built a very basic test script which times how long it takes to loop 1000 times, each loop writing to the dac. The fastest I can get it to go is ~ 1000 writes per second. Ideally I could output smooth waveforms up into audio rate. What is it about writing to i2c that slows everything down? Should I get a different dac that communicates with a different protocol?

Here is my test script.

Code:
// Basic demo for configuring the MCP4728 4-Channel 12-bit I2C DAC
#include <Adafruit_MCP4728.h>
#include <Wire.h>

Adafruit_MCP4728 mcp;
int counter = 0;
bool re = false;
void setup(void) {
  Serial.begin(115200);

  Serial.println("Adafruit MCP4728 test!");

  // Try to initialize!
  if (!mcp.begin()) {
    Serial.println("Failed to find MCP4728 chip");
    while (1) {
      delay(10);
    }
  }

  
}

void loop() { 
  if(counter > 1000 && !re){
    Serial.println(float(millis())/100);
    re = true;
  }
  counter++;
  mcp.fastWrite(1000,1000,1000,1000);
}
 
Default I2C is very slow by digital standards - you could try HS mode, the MCP4728 supports that.

You ideally want to update the DAC at ultrasonic rate to avoid breakthrough in the audio band, but
even 10k updates/second would be very much better than what you have now I suspect which is
directly injecting tones around 1kHz when slewing the output.

SPI DACs are preferred for signals unless you simply using the DAC for DC levels, as SPI can easily
handle DACs upto 500kSPS. I2C's strength is fewer wires and its addressing, not speed.
 
I tried doing Wire.setClock(); and it didn't seem to make a difference when I changed the values, but I might be addressing the wrong i2c bus or something. How might I go about finding a DAC that would fit my needs? I need 4 outputs at 12 bit resolution, that part is easy, but what do I look at to see the speed of updates?

Specifically I am looking at the MAX5232 which is suspiciously cheap compared to all the other options. I am also looking at the LTC2634 and the DAC7617

Also I have been using the adafruit library for this chip. Will I need to write my own driver for one of these chips? Is there a generalized way to address SPI dacs?

Thanks for all the help.
 
Hi, I realise this an old post but would like to know how your experience was and if you moved to using an I2S or SIP DAC. I was considering using the MPC4728 to use for generating waveforms for a digital oscillator so similar to using it for LFO. Is the MPC4728 capable of this, and do you have any DAC recommendations from your experience. The biggest problem I'm having is not good DAC options but drivers and examples where people have used them.
 
Back
Top