Monday, September 3, 2018

MCP4725 DAC AVR ATmega library


In this post I present an AVR implementation for the MCP4725 DAC.

The MCP4725 DAC is a pretty common and cheap single channel 12 bit buffered voltage DAC, it also has an onboard EEPROM.
To drive this chip we can use I2C interface.



The ATmega8 used for my implementation has an embedded I2C interface, so we just can use that interface.
The selected I2C library is the one proposed by Peter Fleury, you can find it here: http://homepage.hispeed.ch/peterfleury/avr-software.html

To library provides simple functions to set the output channel of the IC by using raw value or a voltage value.


The voltage output of this chip is limited by his voltage input, that is 2.7v to 5.5v, and the current allowed at the output pin is 25mA.
If you need more current, or more voltage, you can use a combination of opamp and power transistors.

Up to 8 MCP4725 can be driven using this library, the IC address has to be selected using the hardware pulldown selector.

This project has been developed and tested on an ATmega8 running at 8Mhz.

An example program is provided in order to help the library usage.



Code

Notes
  • read risk disclaimer
  • excuse my bad english

16 comments:

  1. I want coding in avr mister?

    ReplyDelete
    Replies
    1. Hello, you can find the source code in the blogpost.

      Delete
  2. Sir I want sine wave what change required in code?

    ReplyDelete
    Replies
    1. Hello, in the main.c sample project you should already have a sin as output, indeed the TESTMODE macro is set as TESTMODE_SINE.

      Delete
  3. Sir what is the frequency of this sine wave.if I want change frequency what should i do?

    ReplyDelete
    Replies
    1. Frequency depends on the main loop. In order to change the frequancy you have to code it out using a Timer.

      Delete
    2. Delay function should be work for frequency I want 2 khz frequency

      Delete
    3. You have to setup a 2Khz timer, and output a value from the sine256 hash table.

      Delete
  4. Sir I am successfuly build my project for your help,sir I am required convert 250 mv ac to DC ,what is the idea of this conversion you suggest,ya simply connect low pass filter to 250mv ac ?

    ReplyDelete
    Replies
    1. Great! Just output a voltage using this library. Then pass it through an opamp, take a look at the sample schematic here: http://davidegironi.blogspot.com/2019/09/drive-mcp49xx-series-dac-with-avr-atmega.html

      Delete
  5. This project work for atmega32?

    ReplyDelete
    Replies
    1. Hello, yes it should. You just have to edit a few things.

      Delete
  6. I2C Address
    GND = 1100 00 0 (0x60) (DEFAULT)
    VCC = 1100 00 1 (0x61)

    But sir you address (0*00) of mcp4725?

    ReplyDelete
    Replies
    1. Hello, I'm using the default address.

      Delete
    2. But sir in the code use 8 bit chip address is 0*00 or I am think wrong.

      Delete