Sunday, September 1, 2019

Drive an MCP49XX series DAC with an AVR ATmega


digital-to-analog converter (DAC) is a system that converts a digital signal into an analog signal.

The MCP4901, MCP4902, MCP4911, MCP4912, MCP4921, MCP4922 are DAC converters by Microchip.
They have 1 or 2 channel output, 8, 10 or 12 bit buffered voltage output.
The interface used to drive those IC is the SPI.


Driving that IC is pretty simple, expecially if you have a dedicated SPI hardware interface, like many microchip has.
The ATmega8, used in this example has a dedicated SPI Control Register (SPSR) that one can use to setup the SPI interface.

This library can drive more then one MCP49XX of the same series at the same time, this is done just by selecting the chip using a SS channel for each one.

A few functions are available in order to set a raw value for the DAC channel, a selected voltage, to power the IC down or up, and to get the actual raw value.
On compile time you have to set ports to use, and the MCP49XX family.



The sample schematics contains also an output stage build up using a LM358 opamp with a non-inverting configuration.

In non-inverting configuration the Gain is R2/R1 + 1, given R2 the resistor between out and - input, and R1 the resistor beteen - input and GND. The sample gain of 3.2 amplifiy the input signal taken from the DAC by 3.2, of course the output voltage can not exceed the power supply voltage of the opamp. For this reason if you supply the LM358 with a 12V supply, a sample output voltage of 2.4V will became 7.68V output.

The output current is limited to 20mA for a sink load and 40mA for a source load.

By simply adding a power MOSFET you can amply the output current that can be draw.

The example is provided runs a sine wave output or a selected voltage output.

All the setup parameters are included in the mcp49xx.h file.

The library proposed here can be ported to other microcontroller without difficulties.

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz.


Code

Notes
  • read risk disclaimer
  • excuse my bad english