Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
:
:
Don't worry -- youre-mail address is totally secure. I promise to use it only to send you MicroZine.

MCP4725

The MCP4725 is an analogue DAC - it generates a voltage at its output just like a potentiometer (the fancy name for a 3 terminal resistor with adjustable centre position). The difference is that this chip sets its output via digital control.

It is a buffered voltage output device 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 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. 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.

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 (since that takes up to 50ms to complete) - 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 ACK signal.

This means you can update the output at a rate determined by the transmission speed of 2 I2C packets.

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.

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.4MHzSame
  Resolution
12 bitSame
  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, ±2ppmSame
  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)
1000pF100pF
  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 it is even less capable than the MCP4725 and does not have an address input. In this case to get more than one chip on a single address 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.

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 single sine waves).

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


New! Comments

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




Privacy Policy | Contact | About Me

Site Map | Terms of Use



Visit our Facebook Page:

   Click Here


  1. How to use the MCP23017 I/O Expander on the Arduino

    How to use the MCP23017 to increase your I/O by 16 pins (or more) and use its interrupt system.

    Read more

  2. Arduino Battery Charger: How to save the planet one battery at a time; Recycle and re-use Alkaline battries

    Arduino Battery Charger: A very useful project that lets you charge 'un-rechargeable' alkaline batteries!

    Read more

  3. Digispark Attiny85 Easy IDE install and setup

    Digispark ATtiny85: Essential information on setting up and using this tiny, but powerful, chip

    Read more



Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Back to Top