MCP4725: Easily Generate a True Analogue Voltage using this Tiny Chip. This is a 12 bit DAC (with memory) to output a voltage for controlling analogue systems such as a PSU level or opamp offsets.

MCP4725:

  • A 12bit DAC that outputs a proportion of the Supply Voltage.

  • Outputs a True Analog voltage.

  • Find out if you can use it as a signal generator (Ans: a bit slow!).

  • Similar chips 4726 vs 4725: Why you might want to use an MCP4726.

The MCP4725 is an analogue DAC - it generates a voltage at its output just like a potentiometer. The difference is that this chip sets the output via digital control with a voltage buffer that is controlled from an I2C serial interface.

It outputs a proportion of the input voltage. Since it's a 12bit device its resolution is Vref/4096. So you can choose very fine steps dividing down from the reference.

It also contains an EEPROM memory so the device can power up immediately to an output voltage without requiring programming each time. You obviously have to program it the first time, but after that it remembers the voltage setting.

This is useful in a production setup environment where you program in opamp offsets during production, then the main system program does not need to worry about them.

This page also compares the MCP4726 with the MCP4725 since they are very similar devices. The main difference is that the 4726 has a reference voltage input - there are other differences as well.

MCP4725 Breakout board

MCP4725 Breakout Board

In the breakout board, the three solder blobs labelled ADDR let you control the value of A0 which changes the i2C address of the chip. The chip is upside down with A0 at bottom left which connects to the middle 'ADDR' solder blob. A0 is used to select from one of two I2C addresses.

The resistor to the right of the solder blobs should be a 1k pull-down but it was put in series from GND to the middle solder blob, so it does nothing - that 1k is useless - that means you must solder something otherwise the address input is left floating and you may get random operation!

You have to solder either the top 2 blobs (A0=0), or the bottom two blobs (A0=1) forming a solder bridge, otherwise A0 is left floating. Don't solder them all together - it will short the supply!

The two top resistors are 4k7 and pull-ups for SDA and SCL. On the back there are "cut-tracks" that can be cut to isolate these resistors. Cut these "cut tracks" if there are already pull-ups with other attached I2C devices.

MCP4725 Pinout

The chip comes in a tiny SOT-23 six pin package.


MCP4725 pinout
                    [Source: Datasheet]

MCP4725 Block Diagram

MCp4725 Block Diagram
                            [Source: Datasheet]

MCP4725 Datasheet

Download the MCP4725 datasheet here.

MCP4725 Specification

  Parameter
MCP4725
Voltage Supply (Vs)
2V7 ~ 5V5
Abs. Max VDD
-0V3 ~ 6V5
Interface
I2C
I2C rate
100kHz, 400kHz, 3.4MHz
Resolution
12 bit
Power Down I (VDD=5V5 - typ, max)
0.06uA, 2uA
No load current (typ, max) 210uA, 400uA
Short circuit (Vout=GND) (min,typ, max)
7mA, 15mA, 24m
Offset error (typ,max)
±0.02, 0.75 %FSR
Offset error drift (-45~25, 25~85ºC, typ) ±1ppm, ±2ppm
INL (typ,max) LSB
±2, ±14.5 [3]
DNL (min,typ,max) LSB
-0.75, ±0.2, ±0.75 [2,3]
Gain error (min, typ, max) %FSR -2, -0.1, 2
Gain error drift
-3 ppm/ºC
Phase margin
66º
Capacitive load stability (5k load)
1000pF
Slew rate
0.55V/us
Output voltage settling time
6us
I2C Addresses (h/w selected = 8off)
0x60, 0x61 [1]
Operating temperature
-40°C ~ 125°C
    [1] For more devices on a single I2C bus order pre-programmed devices.
    [2] A number below 1 LSB means no codes are missed.
    [3] Code Range 100 to 4000 (see Accuracy)

I2C Address

Addressing Scheme

The MCP4725 has a single A0 address input pin, meaning that only two devices can be placed on a single I2C bus. However there is a workaround that allows you to place 8 devices on a single bus.

Warning: You can only use two devices on a single I2C bus unless...

The work around is that you must order different versions of the MCP4725 that have hard coded A1 and A2 address bits programmed in at the time of manufacture.

MCP4725 Address mapping

The lower three bits of the address consist of the three digital inputs A2, A1, A0 while the upper bits are fixed at 1100xxx.  A1 and A2 are assigned at manufacture and will usually be zero.

The the last bit( LSB ' 'L), sent following the address bits, is ignored as it is the read write bit (R/Wn). Therefore the addresses with only A0 available as an address control are:

        0x60, 0x61

For each device you can set A0 to one or zero. The rest (A1 and A2) are specified on purchase.

I2C commands

There are two write commands and one read command (Datasheet Table 6-2):

  1. Fast mode DAC register write.
  2. Write DAC control register (optional EEPROM write).

Writing

The first command "Fst Mode" (Datasheet Figure 6-1) is a fast update command and writes only to the DAC register and does not update the EEPROM. It also uses a different data format to the second. It allows the data to fit into two bytes whereas the second format uses three.

  • 1st command uses 2 data bytes making 3 I2C packets (including address).
  • 2nd command uses 3 data bytes making 4 I2C packets (including address).

Confusingly when you use the second command (Datasheet Figure 6-2) and set C2,C1,C0 to 010 it has the same effect as the first command and just sets the DAC registers but does not program the EEPROM.

The real use of the second command is to update the EEPROM as well when C2,C1,C0 = 011. In this case a new command can not be used until the EEPROM has finished being written.

Warning: An EEPROM update takes up to 50ms and blocks operation.

EEPROM write can take up to 50ms (typically 20ms ) and no other action is allowed until the update is completed (Read the RDY/BSYn flag to check).

Faster updates

To avoid really slow operation, use the first command that does not write to the EEPROM - this is the "Fast Update" command.

To improve the speed of operation a bit more you can repeat the data packet so you don't have to stop and start the I2C. So instead of a stop bit at the end of an I2C transaction you just repeat the two data bytes that update the DAC output. The output is then continuously updated at the end of every second I2C ACK signal.

This means you can update the output at a rate determined by the transmission speed of 2 I2C packets (an I2C packet holds 8 bits and you need 12 bits so 2 packets are needed).

Note: I2C operation is not that fast. Speed test results are here.

Reading

For reading data back, you set the R/Wn bit in the first I2C packet high (Datasheet Figure 6-3). Then you read back 5 bytes from the MCP4725. The first byte contains the RDY/BSYn bit which is used to check if an EEPROM write has completed.

Accuracy

There are several factors that contribute to the MCP4725 accuracy:

  • Code range used
  • INL - Integral Non Linearity.
  • DNL - Differential Non Linearity.
  • Gain error - Slope of the transfer function.
  • Offset - Offset voltage at Zero Output.
  • Noise sources.
  • Quality of the voltage input (power supply input).

Warning: The code range used is the biggest factor affecting accuracy.

The datasheet suggests that to get 1% accuracy use only codes between 100 and 4900 due to opamp saturation.

Code Range

At the top and bottom end of MCP4725 DAC codes, the linearity of the output becomes worse. The recommended area of use is for a code output range of 100 to 4000, which is the range defined for measurement of INL and DNL.

This is the datasheet diagram showing the transfer function across the whole range of codes. You can see that at higher codes the transfer function departs from the straight line. For codes below 100 the output is also non linear (not shown). This is why INL and DNL measurements are defined only for codes 100 ~ 4000.

MCP4725 gain erro transfer function
             [Source: Datasheet]

MCP4725 Uses

Once you have setup the desired voltage, the beauty of the chip is that you can program the internal EEPROM to output the same voltage at every power-up .i.e. you calibrate the unit and it is set-and-forget.

There are several uses for the chip:

  • Calibration.
  • Repeated output (remembers output after power down).
  • Waveform generation (very slow with Arduino Uno - use DSP e.g. ESP32).

Calibration

The ideal use for this chip is to setup fixed output voltages for calibration of a unit. Once you have calibrated the system the chip will remember the output setting and output the same voltage at power up.

Digital Power Supply

Another use could be in a digital power supply where you want the output to keep the same value that was last set i.e a programmable power supply.

Waveform Generation

You could use it to generate waveforms (fairly slow) but it can you can speed it up using the fast mode DAC write command.

Using the I2C 3.4MHz mode would make the output dependent only on the chip specification of slew rate and settling time, and command used (plus a bit more for the serial interface update). Don't forget processor speed of update i.e. how fast round the main loop (or use and interrupt generated update).

Disadvantages

  • No separate reference voltage input.
  • Limited addressing.
  • No Synchronous update.

The Voltage Reference is the Supply

One problem is that the chip uses the supply voltage as the reference voltage source. Supply voltage chips generally have a tolerance, specified by the manufacturer of between 2% and 10% so you can end up with this tolerance at the output.  (See this page for some measurements on 5V supply variation)

You could get around this by the MCP4725 with an accurate voltage reference at the VDD pin, but then you need to make sure that the reference is capable of supplying all attached chips with enough current.

Alternatively use the MCP4726 which also has an optional buffer amplifier at the reference input pin.

Addressing

The addressing scheme is discussed here (it is a bit limited).

Synchronised Update

This is a subtle disadvantage. You can not update the outputs of multiple MCP4725 at the same time. This is not really a disadvantage of the chip - it is just something you might not think about unless you really need this feature.

You can only update each MCP4725 using and individual I2C sequence, so if you have 8 chips it is going to take 8 I2C data packets which takes time. If you really need synchronous updates use the MCP4728 or MCP4922 that have a hardware update control signal.

Arduino Example with the MCP4725

Software

Arduino IDE : Version 1.8.9+

Arduino Library

  • Library: Adafruit_MCP4725

Goto Arduino Menu: Sketch-->Include Library-->Library Manager.

Then enter MCP4725 in the search box which will show the result:

Adafruit_MCP4725 by Adafruit Version 1.0.0 - Click Install.

You can see that the library is installed by going to Menu: Sketch-->Include Library, scroll down in the drop down box that appears and you will see an entry labelled : Adafruit MCP4725 Library.

Library Notes

The code in this library always uses the 400kHz I2C mode. It does this by storing the current TWBR value and restoring it at the end of the function setVoltage(). So whatever you do you can't change the speed unless you edit the library code (Adafruit_MCP4725.cpp). This is probably about as fast as the UNO can go.

    #ifdef TWBR
      uint8_t twbrback = TWBR;
      TWBR = ((F_CPU / 400000L) - 16) / 2; // Set I2C frequency to 400kHz
    #endif

The definition TWBR is set elsewhere to indicate that the processor has a TWBR register.

Warning: Don't continuously write to the EEPROM as it has a lifetime.

The second parameter, in the setVoltage() function, writes the EEPROM if set true.

Hardware

Components

  • Arduino Uno R3/Arduino Nano.
  • MCP4725 breakout board (Use A0 solder bridge to GND).
  • Connection wires.

Connections

For testing use an Arduino Uno and connect it as follows:


Arduino MCP4725
5V
VDD
GND
GND
A5
SCL
A4
SDA
GND
A0

Example Sketch

This example generates a sinewave output using stored values that are programmed into the Flash memory. Note that this does not use the fast method mentioned here. The Arduino output is using I2C at 400kHz.

#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

#define DAC_RESOLUTION    5
#define DAC_ARRAY_INDICES (pow(2,DAC_RESOLUTION))

const PROGMEM uint16_t SineLookup_5bits[32]
{
2048, 2447, 2831, 3185, 3495, 3750, 3939, 4056,
4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447,
2048, 1648, 1264,  910,  600,  345,  156,   39,
   0,   39,  156,  345,  600,  910, 1264, 1648
};

void setup(void) {
   dac.begin(0x60);
}
void loop(void) {
   for (int i = 0; i < DAC_ARRAY_INDICES; i++) {
      dac.setVoltage(pgm_read_word(&(SineLookup_5bits[i])), false);
   }
}

Note: The sine table is from https://github.com/adafruit/Adafruit_MCP4725/blob/master/examples/sinewave/sinewave.ino where you can find more tables (up to 9 bits).

MCP4725 Sine Waveform Speed

This sketch is setup using 32 intervals in a complete sine wave (16 steps from top to bottom). So that is going through 360/32 degrees and obtaining a DAC result for each angle. It is setup with 1V per division and has a frequency of 218Hz. If you used fast updates you would get slightly better than double the frequency.


MCp4725 DAC 32 bit sine wave output

Timebase: 500us/div, Yellow 1V/div.

For this interval each step represents 5/16 = 312mV. The chip is capable of a resolution of 4096 giving steps of 5/4096 = 1.2mV.

The second waveform shows the I2C clock. You can see that there are four 9 bit I2C packets per update. The clock period is 2.5us, 1/T = 400kHz.

mcp4725 i2c clock 4 packets

Notice also how there is noise on the output (image below) - this could be reduced by power supply filtering, output filtering  and board layout (possibly). The screen shot below has the yellow channel at 50mV per division. It shows noise from the I2C packets imposed on the output (~30mVpp noise).

Timebase: 10us/div, Blue 10v/Div, Yellow 50mV/div.

mcp4725 output noise with i2c command

The implication is, that for accuracy the I2C interface should be shutdown while a measurement is made (when using the MCP4725 as a calibration output).

Filtering the output using a 10k and 100nF to GND (fc=159Hz) gives the following waveforms:

mcp4725 filtered output

The 400kHz signal is attenuated out but there is still system noise.
Timebase: 10us/div, Yellow 10v/Div, Blue 50mV/div.

The full waveform is here (10k ,100nF):

mcp4725 filtered output 10k 100n

You can see that the above output (blue) is phase shifted and attenuated. This is a problem if you want to generate waveforms. If you only need a dc output then noise will be filtered out better by the 10k and 100nF filter. The effect will be a longer settling time after changing the DAC output.

If you relax the filter to 10k and 100n Fc=1.59kHz. Then you get an output that is closer to the original i.e. it is not attenuated and not phase shifted as much because the corner frequency of the filter (Fc) is a long way from 218Hz. However, system noise will be increased.

MCP4725 filtered 10k 100n on output

Timebase:500us/div, Yellow 1V/div, Blue 1V/div.
Note the output of the voltage regulator is 4.76V.

Theoretical maximum speed

Approximately how fast could this chip go in generating a 32 bit sinewave?

The sinewave goes through a cycle of 32 bits from max to min, and then to max again, so from top to bottom there are 16 steps.

Ignoring slew rate, and settling time, and processor time. From the waveforms you can see that 4*9=36 bits must be output. If the clock is 3.4Mhz (MAX I2C speed) then this would take 39*(1/3.4e6) = 11.47us.

To generate 32 segments will take 32*11.47e-6=367us.

That generates a frequency of 1/367e-6 = 2.724kHz.

This is the maximum theoretical sine wave (using normal Stop/Start I2C transmission) - remember this is a low resolution sine wave and would slow down if more segments were needed.

Warning: This is a low resolution sinewave. More steps = slower.

You could increase the speed using the fast mode by 25% (sending only 3 packets) ~ 3.4kHz.

If you use the continuous update method where you don't release the I2C bus, then you can double the output rate to 5.9kHz. This output generator should be controlled from a priority interrupt routine.

Warning: Calculations assume the processor is dedicated to this task!

MCP4726

This section allows you to compare the MCP4726 to the MPC4725.

The MCP4726 is nearly the same as the MCP4725 but has two new features:

  • An external reference input with optional input buffer.
  • A gain selectable opamp.

By adding the external reference input, the address pin A0 is lost, so the device has an even more restricted address capability (you have to order pre-programmed devices if you want more than one device on a single I2C bus).

MCP4726 pinout

The chip comes in a tiny SOT-23 six pin package.

mcp4726
                  pinout
                            [Source: Datasheet]

MCP4726 Datasheet

Download the MCP4726 datasheet here.

MCP4726 Block Diagram

MCP4726 Block Diagram
MCp4726 Block Diagram
        [Source: Datasheet]

Voltage reference

From the above diagram you can see that the reference section and opamp have been enhanced.

For the reference you can select between:

  • Power supply as reference.
  • Unbuffered input pin as reference.
  • Buffered input pin as reference.

The first is obvious!

When using the second option (unbuffered input) the voltage source must be able to drive enough current into the ~210kOhm (±20%) resistor ladder.

The third option is used when you can't load the voltage reference source (you should try to use a source that can drive enough current). Using the buffer amplifier does result in a slight reduction in input range (10mV ~ VDD-40mV). the buffer amplifier has low noise and low offset voltage but they are not zero

Opamp

The opamp has a selectable gain of 1 or 2. So if you have a low voltage reference e.g. 1.25V you can double it up as long as the voltage input at the reference voltage pin remains below Vdd/2.

MCP4726 compared to MCP4725

The MCP4726 is virtually identical to the MCP4725 but has two new features:

  • An external reference input.
  • A gain selectable opamp (x1 or x2 gain).

The MPC4726 addresses the main problem of the MCP4725 - that the power supply is used as a reference. This is not the best thing to use if you want to create a highly accurate system.

What you really want is a separate input pin to supply your own defined and accurate reference and this is exactly what has happened in the MCP4726. However, a sacrifice was made and that was to change the function of a pin.

The only pin that can be replaced (in the same package size) is the A0 (address input pin).

This pin has been turned into the reference input pin in the MCP4726.

MCP4726 Specification vs MCP4725

  Parameter
MCP4725
MCP4726
Voltage Supply (Vs)
2V7 ~ 5V5 Same
Abs. Max VDD
-0V3 ~ 6V5
Same
Interface
I2C
Same
I2C rate
100kHz, 400kHz, 3.4MHz Same
Resolution
12 bit Same
Power Down I (VDD=5V5 - typ, max)
0.06uA, 2uA
0.09uA,2uA
No load current (typ, max) 210uA, 400uA
Same
Short circuit (Vout=GND) (min,typ, max)
7mA, 15mA, 24mA
Same
Offset error (typ,max)
±0.02, 0.75 %FSR Same
Offset error drift (-45~25, 25~85ºC,typ) ±1ppm, ±2ppm Same
INL (typ,max) LSB
±2, ±14.5 [3]
Same
DNL (min,typ,max) LSB
-0.75, ±0.2, ±0.75 [2,3]
Same
Gain error (min, typ, max) %FSR -2, -0.1, 2
Same
Gain error drift
-3 ppm/ºC
Same
Phase margin
66º Same
Capacitive load stability (5k load)
1000pF 100pF
Slew rate
0.55V/us
Same
Output voltage settling time
6us
Same
I2C Addresses (h/w selected = 8off)
0x60, 0x61 [1] 0x60[1]
Operating temperature
-40°C ~ 125°C
Same
    [1] For more devices on a single I2C bus order pre-programmed devices.
    [2] A number below 1 LSB means no codes are missed.
    [3] Code Range 100 to 4000 (see Accuracy)

    Note: Other parameters specific to the MCP4726 are not listed here.
    Note: Current consumed is more than the MCP4725 as more is going on.

MCP4726 Advantages

  • MCP4726 Accepts an external reference voltage the MCP4725 does not.
  • They both use the same package: SOT-23-6.
  • Selectable gain opamp (G=1 or 2).
  • Very low typical power down current (only a bit worse than the MCP4725).

MCP4726 Disadvantages

Its address capability is even less than the MCP4725; It does not have an address input. To get more than one chip on a single I2C bus requires that you buy different devices with pre-programmed addresses built in!

You use up to 8 devices on the same I2C bus but must specify the A0, A1 and A2 address bits on ordering.

Conclusions

General Usage

These chips (MCP4725 and MCP4726) are very useful for sprinkling around a board as they occupy very little board area, and can be tied to a single I2C bus. You can use them to setup calibration for analogue circuits with ease.

Note: The (typical) power down current is very low for these chips.

The only fly-in-the-ointment is that for more than 2 (MCP4725), and for more than 1 (MCP4726) you have to order differently programmed devices from the manufacture in order to make use of the full address range of each chip (max 8 of either type on a single I2C bus).

For a large firm, this is just a procurement exercise, then feeding the chips into the correct slot on the pick and place machine. If you are going to debug this system, it is another matter. You'll be sitting on the bench figuring out which SMD device is which, and trying to keep it all under control.

This is why I think the MCP4728 was created.

You can find out more about the MCP4728 here, where you'll see how it incorporates ideas from the MCP4726 and MCP4725.

Waveform generation

The MCP4725 is not really useful as a waveform generator and for the Arduino Uno the maximum output frequency is 218Hz for a 16 step waveform!

If you increase the number of steps to 4096 it is going to take a very long time to output a waveform so it will have even lower frequency. Testing shows a 9 bit waveform 512 elements (256 top to bottom) gives: 13.66Hz.

However the examples in this document use a maximum I2C speed of 400kHz (dependent on the Arduino Uno speed). The chip is capable of a 3.4MHz speed. If you used a faster processor then the output rate would be increased but does this make much difference? The rate would increase from 400kHz to 3400kHz which is a factor of 8.5. So the above outputs would increase from 218Hz to 1853Hz (16 steps), and 13.66Hz to 116.11Hz (256 steps). So in fact these are still not impressive speeds.

As you can see from the "Theoretical maximum speed" even using a DSP processor will only result in a maximum output rate of 2.7kHz (this is again generating only a 32 bit sinewave with 16 steps top to bottom). You can push this to 5.9kHz with continuous output mode but the processor is dedicated to this task alone.

Alternatively use an SPI version of the DAC: MCP4922. However, even with that device the theoretical maximum output frequency is 39kHz i.e 10 times better - this is still only for a 16 step waveform so not as good as it sounds!

If you really want high speed output you need a dedicated DDS such as an AD9833 (this is not a DAC though and generates sine, triangle or a square wave at up to12.5MHz).

Another alternative is to use a parallel DAC such as the 8bit DAC from Analogue Devices DAC08. With that one you can write 8 bits on a parallel bus so its fast (updating within 85ns). Speed = 1.0/(512 * 85e-9) = 22.9kHz (if you can drive it that fast!).


Comments

Have your say about what you just read! Leave me a comment in the box below.

Don’t see the comments box? Log in to your Facebook account, give Facebook consent, then return to this page and refresh it.




Privacy Policy | Contact | About Me

Site Map | Terms of Use