When you need to convert an analog voltage to a digital value you could use an analog to digital converter. But what do you do when you need to convert a digital value into an analog voltage? In this tutorial, I will be guiding you through exactly that.
Digital to Analog ConverterFor this, I will be using Aptinex 4-Channel DAC module (DA4C010BI). This module uses the popular MCP4728 DAC IC with integrated EEPROM. It interfaces to your micro-controller with I2C communication bus up-to 3.4Mbps. It has both I/O and power range of 3.3V-5V and output range is 0-12V. Additionally, output has been buffered and offset corrected so you can achieve true 0V level at the output. It has an integrated voltage boost stage so you can power it from the 3.3V-5V power supply and get an output of 12V. Now we shall look at how to connect everything together.
Hookup GuideThe module features a dual row header. This is useful if you want to daisy chain more modules or use the I2C bus for other devices. You can use either 3.3V or 5V to power the module. The I/O voltage is also compatible with both 3.3V and 5V. Following is how you could hook up to an Arduino Uno.
I will be using Arduino IDE with Aptinex DAC Arduino library. To test the module, you can simply use the given example below.
//Basic demo for configuring the APTINEX 4-Channel 12-bit I2C DAC Module
#include <Aptinex_DAC.h>
#include <Wire.h>
Aptinex_4CH_DAC DAC;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("APTINEX 4CH DAC test!");
// Try to initialize!
if (!DAC.begin()) {
Serial.println("Failed to find 4CH DAC Module");
while (1) {
delay(10);
}
}
Serial.println("4CH DAC Module Found!");
/*
* @param channel The channel to update
* @param new_value The new value to assign
* @param new_vref Optional vref setting - Defaults to `MCP4728_VREF_VDD`
* @param new_gain Optional gain setting - Defaults to `MCP4728_GAIN_1X`
* @param new_pd_mode Optional power down mode setting - Defaults to
* `MCP4728_PD_MOOE_NORMAL`
* @param udac Optional UDAC setting - Defaults to `false`, latching (nearly).
* Set to `true` to latch when the UDAC pin is pulled low
*
*/
// Vref = MCP_VREF_VDD, value = 0, 0V
DAC.setChannelValue(MCP4728_CHANNEL_A, 0);
// value is vref/2, with 2.048V internal Vref and 1X gain
// = 2.048/2 = 1.024V
DAC.setChannelValue(MCP4728_CHANNEL_B, 2048, MCP4728_VREF_INTERNAL, MCP4728_GAIN_1X);
// value is vref/2, with 2.048V internal vref and *2X gain*
// = 4.096/2 = 2.048V
DAC.setChannelValue(MCP4728_CHANNEL_C, 2048, MCP4728_VREF_INTERNAL, MCP4728_GAIN_2X);
// value is vref/2, Vref is MCP4728_VREF_VDD(default), the power supply
// voltage (usually 3.3V or 5V) For Vdd/Vref = 5V, voltage = 2.5V For 3.3V,
// voltage = 1.65V Values will vary depending on the actual Vref/Vdd
DAC.setChannelValue(MCP4728_CHANNEL_D, 2048);
DAC.saveToEEPROM();
}
void loop() { delay(1000); }
To Calibrate this module you have to set each channel to its maximum value. This module is a 12-bit module. Therefore, the maximum value is 4096. And then you have adjusted the potentiometer to until you are getting your desired maximum output voltage. In the MCP4728 DAC IC, there is two voltage references and two gain values. You can use any configuration but you have adjusted the potentiometer of each channel.
Comments
Please log in or sign up to comment.