Red Light Racing

  • Increase font size
  • Default font size
  • Decrease font size

AD5306 Digital to Analog Converter Using Arduino

E-mail Print PDF

Here's the code to control an AD5306 Digital to Analog Converter (DAC) using an Arduino Duemilanove. We'll use this four channel DAC to send appropriate voltage signals to the Honda ECU and VW ECU as required. 

// I2C Digital to Analog Converter (DAC)

// by Jake Staub

// Controls one AD5306 4 channel 8 bit DAC via I2C/TWI

//

// Device address 00011(AD1)(AD0) from data sheet

// AD1  AD0  Device Addressed

// 0    0    U1

// 0    1    U2

// 1    0    U3

// 1    1    U4

// Pointer Byte or DAC address 0000(DACD)(DACC)(DACB)(DACA)

// 0    0    0    1    DACA

// 0    0    1    0    DACB

// 0    1    0    0    DACC

// 1    0    0    0    DACD

// Data Byte

// Most Significant Data Byte 0111(D7)(D6)(D5)(D4) = 0x70

//   DAC set at 0V to Vref, Ref input for DAC buffered, Normal ops, Normal ops

// Most Significant Data Byte 1111(D7)(D6)(D5)(D4) = 0xf0

//   DAC set at 0V to 2Vref, Ref input for DAC buffered, Normal ops, Normal ops

// Least Significnat Data Byte (D3)(D2)(D1)(D0)0000

 

// Created 1 March 2009

// Arduino analog input 4 - I2C SDA

// Arduino analog input 5 - I2C SCL

#include Wire.h  Note: need carrets around Wire.h to pull Wire library in.

void setup()

{

  Wire.begin(); // join i2c bus (address optional for master)

}

byte val = 0;

byte msb = 0x70;

void loop()

{

  Wire.beginTransmission(0x0c); // transmit to device U1 (0x0c or hex for 0001100)  

                                 // device address is specified in datasheet,

                                // up to three more devices could be used; U2, U3, U4 (addresses above)

  Wire.send(0x01);              // sends pointer byte to DACA (0x01 or hex for 00000001)

  Wire.send(val >> 4 | msb);    // shifts val right 4 bits and uses the "OR" operator with msb

                                 //   to send Most Significant Data Byte

  Wire.send(val << 4);          // shifts val left 4 bits and uses the "OR" operator with 0x00

                                 //   to send Least Significant Data Byte  

  Wire.endTransmission();       // stop transmitting

  Wire.beginTransmission(0x0c);

  Wire.send(0x02);             // sends pointer byte to DACB (0x02 or hex for 00000010)

  Wire.send(val >> 4 | msb);

  Wire.send(val << 4);

  Wire.endTransmission();

  Wire.beginTransmission(0x0c);

  Wire.send(0x04);             // sends pointer byte to DACC (0x04 or hex for 00000100)

  Wire.send(val >> 4 | msb);

  Wire.send(val << 4);

  Wire.endTransmission();

  Wire.beginTransmission(0x0c);

  Wire.send(0x08);             // sends pointer byte to DACD (0x08 or hex for 00001000)

  Wire.send(val >> 4 | msb);

  Wire.send(val << 4);

  Wire.endTransmission();

 

  val++;        // increment value

  if(val == 255) // if reached 256th position (max)

  {

    val = 0;    // start over from lowest value

  }

  delay(5000);  // time delay to see resistance values change via multimeter

}

 

 

Donate

Help us shake things up!

Powered by easy paypal donation

User Login

Countdown to Bonneville

 
 Auto X-Prize Contender