| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

MCP4902 DAC

Page history last edited by Luis Troncoso 9 years, 7 months ago

MCP4902 E/P DAC (Digital to Analog Converter)

GENERAL SPECIFICATIONS:

  • 8-bit Resolution
  • Dual Channel Voltage Output
  • 2.7V to 5.5V Operation
  • Operating Current 350µA (typ)
  • External Voltage Reference Pin
  • INL ±0.125 LSB (typ)
  • DNL ±0.5 LSB (max)
  • Output Settling Time 4.5 µs
  • SPI Interface
  • 14-pin PDIP, SOIC, and TSSOP packagesli>
  • Temperature Range -40°C to +125°C

 

 

 

Use the following formula to find the output voltage of the DAC:

 

 

The MCP4902 is a dual DAC. Below is a block diagram showing the internal dual circuits that can be used:

 

 

More details can be found here: http://ww1.microchip.com/downloads/en/DeviceDoc/22250A.pdf

 

ARDUINO CONNECTIONS:

  • 5v/Ground from arduino to breadboard red/blue rails
  • digital 7 to pin 8 on DAC
    • LDAC in this case because of #define LDAC_PIN 7 
  • digital 10 to pin 3 on DAC
    • SlaveSelect(SS)/ChipSelect(CS) in this case because of #define SS_PIN 10
  • digital 11 to pin 5 on DAC
    • Digital 11 is the MOSI pin for arduino uno to communicate with DAC
  • digital 13 to pin 4 on DAC
    • Serial Clock [SCK] from the arduino to sync with Serial Clock Input [SCK] on DAC

 

DAC CONNECTIONS: 

  • Pin 1 to Power(5v rail made by ARDUINO)
    • Supply voltage input the same as arduino (5V)
  • Pin 2 NC(No Connection)
  • Pin 6 NC
  • Pin 7 NC
  • Pin 9 to Power
    • Active low shutdown pin needs 5V to shutdown the chip if overloaded with current 
  • Pin 10 measured VB
  • Pin 11 to Power
    • VrefB needs a voltage between VDD to VSS but easiest to set it equal to VDD 
  • Pin 12 GND(Ground made by ARDUINO)
    • VSS is the general ground pin for all devices connected 
  • Pin 13 to Power
    • VrefA needs a voltage between VDD to VSS but easiest to set it equal to VDD  
  • Pin 14 measured VA 
  •  

NOTE: The .cpp file used for the library has a lot of useful information about connections with arduino, connecting multiple DACs and how to modify the code to fit the specific MCP49xx chip being used, 

     

Arduino uses SPI to talk to other devices. To learn about this setup and MOSI (Master Out Slave In) vs MISO(Master In Slave Out), use the following links:

http://arduino.cc/en/Reference/SPI 

 

Below is a link that offers more info about SPI and how to connect multiple DACs:

http://tronixstuff.com/2011/05/13/tutorial-arduino-and-the-spi-bus/

 

PROGRAMMING:

To  program the DAC using Arduino, you first have to download and install the libraries found here: https://github.com/exscape/electronics/tree/master/Arduino/Libraries/DAC_MCP49xx

  • Save the .h and the .cpp files into an appropriately named folder within the libraries folder designated by the arduino software, usually found in Documents->arduino->libraries or Program Files->ardiuno->libraries 
  • There are two versions of the example code shown below. Choose the one that says MCP49x2_dual_demo

 


EXAMPLE CODE 1: To control output for one DAC

The following is a demo code used to program any voltage from VDD to Vss (in this case 0 to 5V)

 

//

// Example for the MCP49x2 *dual* DACs

// For the single MCP49x1 series, see the other bundled example sketch.

//

#include <SPI.h>         // Remember this line!

#include <DAC_MCP49xx.h>

 

// The Arduino pin used for the slave select / chip select

#define SS_PIN 10

 

// The Arduino pin used for the LDAC (output synchronization) feature

#define LDAC_PIN 7

 

// Set up the DAC. 

// First argument: DAC model (MCP4902, MCP4912, MCP4922)

// Second argument: SS pin (10 is preferred)

// (The third argument, the LDAC pin, can be left out if not used)

DAC_MCP49xx dac(DAC_MCP49xx::MCP4902, SS_PIN, LDAC_PIN);     //the first argument was changed from MCP49x2(original code) to MCP4902 to apply to this DAC

 

void setup() {

  // Set the SPI frequency to 1 MHz (on 16 MHz Arduinos), to be safe.

  // DIV2 = 8 MHz works for me, though, even on a breadboard.

  // This is not strictly required, as there is a default setting.

  dac.setSPIDivider(SPI_CLOCK_DIV16);

 

  // Use "port writes", see the manual page. In short, if you use pin 10 for

  // SS (and pin 7 for LDAC, if used), this is much faster.

  // Also not strictly required (no setup() code is needed at all).

  dac.setPortWrite(true);

 

  // Pull the LDAC pin low automatically, to synchronize output

  // This is true by default, however.

  dac.setAutomaticallyLatchDual(true);

}

 

// Output something slow enough that a multimeter can pick it up.

// For MCP4902, use values below (but including) 255.

// For MCP4912, use values below (but including) 1023.

// For MCP4922, use values below (but including) 4095.

void loop() {

    // Or, to update one channel at a time:

  dac.outputA(255); //Change these values to get desired voltage

  dac.outputB(168); //255(5v) to 0(0v)

  //dac.latch(); // To synchonize the two outputs

}

 


EXAMPLE CODE 2: To control output for two DAC

This code is basically the same as the first except it allows for two DACs. Modified code is in red.

 

//

// Example for the MCP49x2 *dual* DACs

// For the single MCP49x1 series, see the other bundled example sketch.

//

#include <SPI.h>         // Remember this line!

#include <DAC_MCP49xx.h>

 

// The Arduino pin used for the slave select / chip select

#define SS_PINA 10

#define SS_PINB 9

 

// The Arduino pin used for the LDAC (output synchronization) feature

#define LDAC_PIN 7

5

// Set up the DAC. 

// First argument: DAC model (MCP4902, MCP4912, MCP4922)

// Second argument: SS pin (10 is preferred)

// (The third argument, the LDAC pin, can be left out if not used)

DAC_MCP49xx dac(DAC_MCP49xx::MCP4902, SS_PINA, LDAC_PIN);

DAC_MCP49xx dac2(DAC_MCP49xx::MCP4902, SS_PINB, LDAC_PIN);

 

void setup() {

  // Set the SPI frequency to 1 MHz (on 16 MHz Arduinos), to be safe.

  // DIV2 = 8 MHz works for me, though, even on a breadboard.

  // This is not strictly required, as there is a default setting.

  dac.setSPIDivider(SPI_CLOCK_DIV16);

 

  // Use "port writes", see the manual page. In short, if you use pin 10 for

  // SS (and pin 7 for LDAC, if used), this is much faster.

  // Also not strictly required (no setup() code is needed at all).

  dac.setPortWrite(true);

 

  // Pull the LDAC pin low automatically, to synchronize output

  // This is true by default, however.

  dac.setAutomaticallyLatchDual(true);

}

 

// Output something slow enough that a multimeter can pick it up.

// For MCP4902, use values below (but including) 255.

// For MCP4912, use values below (but including) 1023.

// For MCP4922, use values below (but including) 4095.

void loop() 

{

    // Or, to update one channel at a time:

  dac.outputA(255);

  dac.outputB(128);

  dac2.outputA(0);

  dac2.outputB(64);

  //dac.latch(); // To synchonize the two outputs

}  

 


NOTE: To make the DAC react to the code above the button on the Arduino needs to be pressed after every manipulation. You most likely won't see the changes in voltage after simply uploading the code. 

 

APPLICATIONS:

  • This chip was used in the Color Changing LED Lamp project. It takes the binary information from the Arduino Uno and converts it to an analog output in volts to control the color of the LED.
    • It can't be used to power the LED as is because the voltages needed are up to 12V but it can only produce up to 5.5V. A transistor/resistor combination was implemented to boost the voltage 

Comments (0)

You don't have permission to comment on this page.