AD5761 not working

Hi.  I am trying  to get 0 to 10V out of AD5761. I have Vdd= 12V; Vref = 2.5V and DVcc = 5V with Alert!, Clear! and Reset! all left floating. I have the following arduino code that's supposed to program the chip, but for some reason it is not working.  Can somebody please tell me what I'm doing wrong here?

Thank you!!

#include <SPI.h> //include SPI library

const int syncPin = 10;
const int LDACPin = 9;

void setup() {
  Serial.begin(9600);

  pinMode(syncPin, OUTPUT);
  pinMode(LDACPin, OUTPUT);

  digitalWrite(syncPin, HIGH);
  digitalWrite(LDACPin, LOW);

  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  SPI.setDataMode(SPI_MODE0);

  digitalWrite(syncPin, LOW);
 
  SPI.transfer(0x07);                        //software reset
  SPI.transfer16(0x0000);
  digitalWrite(syncPin, HIGH);

  digitalWrite(syncPin, LOW);
  SPI.transfer(0x04);                      //write to control register              
  SPI.transfer16(0x00A1);              //0000000010100001;
 

  digitalWrite(syncPin, HIGH);

}

void loop() {




  digitalWrite(syncPin, LOW);
  int data = 0x2222;                                                           //some random value
  byte highByte = (data & 0xFF00)>>8;                             //high byte of data
  byte lowByte = (data  & 0x00FF)<<0;                             //low byte of data
 

//Now send it

  SPI.transfer(0x03);
  SPI.transfer(highByte);
  SPI.transfer(lowByte);
  digitalWrite(syncPin, HIGH);

}



corrected typo
[edited by: asymptote_99 at 3:40 AM (GMT -4) on 22 Sep 2021]
  • 0
    •  Analog Employees 
    •  Super User 
    on Sep 21, 2021 3:50 AM

    Hi,

    I believe you should be using SPI Mode 1, the AD5761 samples data on the falling edge, so data should be output by the controller on the rising edge and stable at the falling edge. 

    Best regards,

    Ian

  • 0
    •  Analog Employees 
    •  Super User 
    on Sep 22, 2021 1:45 AM in reply to iandal

    Hi, 

    1, make sure that your Arduino digital outputs are set to 5V in line with your DVcc. 

    2, in this section, you did two 24-bit data transactions in a single sync pulse. The device will see it as 48-bits and will only read the last 24-bit word. and will output the first 24-bit out on the SDO. You will see it if you probe the digital pins. This shouldn't be your intention right? what you need to do is write a single 24-bit word for every sync pin cycle H-L-H. 

    digitalWrite(syncPin, LOW);
     
      SPI.transfer(0x07);                        //software reset
      SPI.transfer16(0x0000);
      delay(100);
     
      SPI.transfer(0x04);                      //write to control register              
      SPI.transfer16(0x00A1);              //0000000010100001;
     

      digitalWrite(syncPin, HIGH);

    3, during start-up it is best to use the Software full reset (0x0F) instead of the software data reset only (0x07)

    4, what we're you intending to write on the control register? (0x00A1) this set bit 1 to 1 for 0-10V range, bit 5 to 1 which is a don't care and bit 7 to 1 B2C on the 2's complement.

  • okay, that was a typo in the code I pasted it here, corrected it. And I got it working now, the problems was that I had not properly grounded the negative supply pin here as I was trying to use it as a unipolar DAC. Really appreciate you looking into this tho. Thank you!