I am using an AD5693 as digital to analog converter with an Arduino Uno. I have connected the SDA andSCL pins of the AD5693 to the I2C pins of the Arduino Uno. I have connected the LDAC active low to gnd. The reset pin is connected to VDD.

I got the example code from GitHub.

The below code works properly:

#include<Wire.h>

void setup()
{

// Initialise I2C communication as Master

Wire.begin();

// Initialise serial communication, set baud rate = 9600

Serial.begin(9600);

delay(300);

}

void loop()

{

unsigned int data = {0x80, 0x00};

// Start I2C transmission

// Select DAC and input register

Wire.write(0x30);

// Write data = 0x8000(32768)

// data msb = 0x80

Wire.write(data);

// data lsb = 0x00

Wire.write(data);

// Stop I2C transmission

Wire.endTransmission();

// Convert the data, Vref = 5 V

float voltage = (((data * 256) + (data)) / 65536.0) * 5.0;

// Output data to serial monitor

Serial.print("Voltage : ");

Serial.print(voltage);

Serial.println(" V");

delay(500);

}

I want to take an input from user which is an analog voltage value and the same value should be the output of the DAC IC.

Do I need to convert the the analog voltage value from the user to hexadecimal? Is there any other way.

• Isn't the number you need just data? Jul 1 '21 at 15:20
• basically if i give user input as 2.1 , i want to get the same voltage at the output of the AD5693.so how will i convert the 2.1 to proportional hex value to store it in data array?@ScottSeidman Jul 1 '21 at 15:23

Hex or not does not matter, but you do have to convert the number from Volts to DAC units. This is because the DAC has no idea about absolute voltages, everything is proportional to its reference voltage (here 5V? But this depends on your circuit. One version of this chip has an internal 2.5V reference, the other has a pin to take an external voltage).

The datasheet gives you the formula on page 19, but it's the wrong way around:

$$\ V = V_{ref} \times Gain \times \frac{code}{65536}\$$

So the first step is to invert this:

$$\ code = 65536 \times \frac{V}{V_{ref} \times Gain}\$$

And make sure the value is of integer type, not greater than 65535 (not 65536!), and not lower than 0.

Now comes the second trick: code is a 16 bit number, and the DAC expects it in two "words" of 8 bits each:

• first the upper 8 bits: msb = (code >> 8) & 0xFF
• then the lower 8 bits: lsb = code & 0xFF

So you must write these two values in succession.

Assume the gain is 1 by default, but this can be changed in the DAC's config.

• thanks you for advice @DamienD Jul 2 '21 at 5:04

A number is a number. You can represent the any number in different ways, it will still be the same number in any representation, either in binary, in hexadecimal, in octal, or decimal.

So no, it does not need to be converted into anything. If you can read a number that the user enters somehow into a variable, it needs no conversion.

• thanks for advice @Justme Jul 2 '21 at 11:34