[Solved] Problem with sending Two’s Complement values to DAC

I’ve got a 16 bit DAC here, which is called DAC8550 (by TI)… I’ve managed to link it with SPI connection with arduino UNO, But I’m having problem with getting predictable results form it.

This chip expects data to be sent to it in two’s complement format from –32768 to +32767, most significant bit first.
This particular model on power-up voltage is set at midscale.

This DAC requires 3 bytes sent to it. In first byte first 6 bit are ‘do not care’, last two are for sleep and power-down. Other 2 bytes are for the data.
I’ve made a for loop to generate values form –32760 to +32760 to be written to DAC and monitored output of a DAC with a multimeter.
The output of from this DAC was loosely correlated with values sent to it.

In my case midrange is at about 2.45v.
This is what I’ve observed when for loop sent values to DAC:
from -32k to -20k output voltage went up and down about midrange from 2.4 to 2.7
at around -20k voltage jumped to 3.2v
at around -15k voltage dropped to 0
from -15k to about -8k voltage moved up and down between 0 and 0.2v
at around -8k voltage started steadily climbing to midpoint.
from 0 to 7k voltage jumped about midpoint
at around 8k voltage climbed to 3.1v and then dropped back to midpoint
at arouns 16k voltage climbed to 3.6v and then dropped back to midpoint
from around 20k to 32k voltage climbed form midpoint to 4.9v

#include "SPI.h"

int dacCSpin = 10, i;
byte data1 = 0, data2 = 0;


void setup() {
  pinMode(dacCSpin, OUTPUT);
  SPI.begin(); 
}

void loop() {

  i = 1 - 32760;

  for ( i = i; i < 32760; i = i + 10) {
    data1 = highByte(i);
    data2 = lowByte(i);
    
    digitalWrite(dacCSpin, LOW);
    SPI.transfer(0b00000000);
    SPI.transfer(data1);
    SPI.transfer(data2);
    digitalWrite(dacCSpin, HIGH);
    
    Serial.print("sent to DAC: ");
    Serial.print(i);
    Serial.print("     in binary: ");
    Serial.println(i, BIN);
    Serial.println("      ");
  }
  delay (11000);
}

Perhaps I should format values I send to DAC as Two’s Complement somehow? Datasheet specifically mentioned DAC8551 as ‘decimal’ counterpart to DAC8550.

Will be grateful for any advice!

The Arduino uses two's complement numbers so a conversion isn't needed. Try setting the bit order, just in case the default is low-order bit first. After SPI.begin(), add this:

  SPI.setBitOrder(MSBFIRST);

Pete

Thank you for advise, El_supremo!
I’ve added the line as you’ve suggested unfortunately it made no difference.
I’ve also tried to declare variable ‘i’ that hold values that are sent to DAC as int16_t but that made no difference either.

I’ve plotted values that I’ve sent to the DAC against voltages I got back form it… Looks just weird!

graph.png

Along the X is voltage, along Y are DAC values…

Where are you getting the reference voltage from? The output is wrt the ref voltage!

Mark

After setting the bitorder, also try setting the mode:

 SPI.setDataMode(SPI_MODE1);

And, which Arduino are you using? Pete

Hurray!!

Setting the SPI data mode to 1 solved it!!!

Thank you, thank you, thank you El_Supremo!!!

I really felt as if I’m hitting my head against the wall here(((

Thank you again!!

graph2.png

This is what the output of the DAC looks like now!

Excellent :)

Pete