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
I want coding in avr mister?
ReplyDeleteHello, you can find the source code in the blogpost.
DeleteSir I want sine wave what change required in code?
ReplyDeleteHello, in the main.c sample project you should already have a sin as output, indeed the TESTMODE macro is set as TESTMODE_SINE.
DeleteSir what is the frequency of this sine wave.if I want change frequency what should i do?
ReplyDeleteFrequency depends on the main loop. In order to change the frequancy you have to code it out using a Timer.
DeleteDelay function should be work for frequency I want 2 khz frequency
DeleteYou have to setup a 2Khz timer, and output a value from the sine256 hash table.
DeleteSir 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 ?
ReplyDeleteGreat! 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
DeleteThis project work for atmega32?
ReplyDeleteHello, yes it should. You just have to edit a few things.
DeleteI2C Address
ReplyDeleteGND = 1100 00 0 (0x60) (DEFAULT)
VCC = 1100 00 1 (0x61)
But sir you address (0*00) of mcp4725?
Hello, I'm using the default address.
DeleteBut sir in the code use 8 bit chip address is 0*00 or I am think wrong.
DeleteThe base address is 0xC0
DeleteSir how to change frequency of sine wave,please explain in detail
ReplyDeleteHello, this is not a DDS example, this is just a DAC example, it just output the sine for test, you should use this as an output of a DDS generator in order to produce a sine wave of a fixed frequency. Anyway you could add a TIMER, the timer can trigger a "emit_sine" boolean variable. You then could emit a step of the sinewave when this variable is true. This way the sine will be emitted accorded to the TIMER frequency. Hope this helps
Delete