Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Questions about speeding up i2c dac.

  1. #1
    Junior Member
    Join Date
    Oct 2020

    Questions about speeding up i2c dac.

    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.

    // 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.println("Adafruit MCP4728 test!");
      // Try to initialize!
      if (!mcp.begin()) {
        Serial.println("Failed to find MCP4728 chip");
        while (1) {
    void loop() { 
      if(counter > 1000 && !re){
        re = true;

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    You can try to use a higher I2C frequency:
    It may be needed to use stronger pullup resistors, then.

  3. #3
    Senior Member
    Join Date
    Jul 2020
    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.

  4. #4
    Junior Member
    Join Date
    Oct 2020
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts