DAC SPI help sending correct signals...

Status
Not open for further replies.

zumdar

Member
Hiya,

Im having problems getting my AD5390 DAC to get to work. Right now I just want to send it a simple sequence to see if it is working, but it is not. Here is the datasheet for the SPI output order:

pqwXNc4.png
one thing i dont understand is the BUSY, LDAC, and the second clock pulse with '24' at the top.
... what do those // mean before it? im assuming its like 'just continue' which in that case would mean just do nothing.

how do you send a single clock pulse??
also i fudged the BUSY and LDAC below.. but how are you supposed to do that?

and here is how the data bytes are supposed to formated:
Vu3TpTf.png

and here is a scope screen caps: (i dont have access to a logic analyzer...)
channel 1 : SCK
channel 2 : DATA
channel 3: SYNC
channel 4: Output 1 of the dac

this one is just those 3,
Tek004.jpg

this is me trying to implement the busy, ldac, and then another clock signal to (kinda) match the datasheet:
channel 1-3 : same as above,
channel 4: busy
channel 5: LDAC
channel 6: DAC output
Tek005.jpg

and here is the code:

Code:
#include <SPI.h>

const int slaveSelectPin = 10;
byte header = 0b01000000; // first two 4 bits are 0100 -- disable toggle mode, enable write , then two blank
byte address;   // this is just 4 bits but we will OR it with header
word regi = 0b1100000000000000; // need the first 2 bits of the data word to be 11 to select the input data register
word value; // this will be a 14 bit number, go up to 16384.
byte valueHighByte;
byte valueLowByte;
const int busyPin = 2;
const int ldac = 3;


void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  pinMode (busyPin, OUTPUT);
  pinMode (ldac, OUTPUT);
  digitalWrite (slaveSelectPin, HIGH);
  // initialize SPI:
  SPI.begin();
}

void loop() {
  address = 0;
  for (value = 0; value < 16383; value++) {
    Serial.print("value going up is :");
    Serial.println(value, BIN);
    dacWrite(address, value);
    delay(1);
  }
  delay(100);
  for (value = 16383; value > 0; value--) {
    Serial.print("value going down is :");
    Serial.println(value, BIN);
    dacWrite(address, value);
    delay(1);
  }
}

void dacWrite(byte address, word value) {
  // gain control of the SPI port
  // and configure settings
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
  // take the SS pin low to select the chip:
  //  send in the address and value via SPI:
  byte beginning = (header | address);
  word data = (regi | value);
  beginning = beginning >> 0;
  valueHighByte = highByte(data);
  valueLowByte = lowByte(data);
    Serial.print("header byte is: ");
    Serial.println(beginning, BIN);
    Serial.print("data word is: ");
    Serial.println(data, BIN);
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(beginning);
  SPI.transfer(valueHighByte);
  SPI.transfer(valueLowByte);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin, HIGH);
  digitalWrite(busyPin, LOW); 
  digitalWrite(ldac, LOW);
  delayMicroseconds(1); // just wait a second to match the data sheet
  digitalWrite(ldac, HIGH); // ldac goes high first just like the datasheet
  delayMicroseconds(1);
  digitalWrite(busyPin, HIGH); // then busy pin goes high
  SPI.transfer(HIGH); // idk... to get a clock signal for it to go??
  // release control of the SPI port
  SPI.endTransaction();
}

THANK YOU for any insight !! I am obviously very new to this, but do have good experience and background with electronics and programming.
 

Attachments

  • On-Paste-20210318-160107.png
    On-Paste-20210318-160107.png
    61.4 KB · Views: 45
Double squiglies are tear marks showing that boring stuff has been omitted. 24 is bit 24.
I'd advise three read-throughs of the relavent part of the datasheet - often things only make sense once
you have an overview, and misconceptions tend not to survive three readings of a document...
 
ok soooo the clock is still supposed to be clocking and then on the 24th pulse the data will latch into the dac and and there will be an output voltage?

is there a way to get SPI to send clock without doing a data transfer?
 
also does that mean that every voltage level for DAC out needs 48 clock cycles to be sent, 24 for data and then 24 for good measure at the end? sorry if these questions are rudimentary. the datasheet kinda presumes you know this, but I dont...
 
Haven't used that chip, haven't got one, you've got the datasheet and chip there, you're the one able to test out
such theories if the details aren't clear (its not unusual for things to be rather obscure for complete datasheets).
 
well i got it working and of course it was something simple. just posting it here in case someone might come across this one day down the line and be stumped.

The 2nd bit, first byte, needs to be low. that puts it in 'write' mode.

also the busy signal is an output signal, not input.

also the LDAC signal doesnt need to be sent either if you are just using it in standalone mode.

attached is a nicer version of the working timing diagram.
channel 1: SCK
2: DIN (MOSI)
3: SYNC
4: busy (from the dac)

also, cycling through all 16,384 possible voltage levels can take a while if you arent optimizing your code to continuously be sending data. turns out my code was taking like 10 seconds to cycle through all the values so i could barely tell the voltage level was moving. I was continuously opening and closing the spi transaction each time i sent out data. I'd like to eventually try to send multichannel audio through this dac, but at this point, even at 100MHZ, im not sure it will be fast enough. Right now, even at 100MHz, i've measured it takes 1.7uS for signal to send and there is 4.85uS of silence between signals. if i were to send signal to all 16 outputs that would take 104.8 uS. That'll give me a sample rate of 9542 Hz. thats a little better then the typical 8KHz telephone sample rate. oh well i just felt like figuring that out! hopefully i can get it to be quicker. im also going to be using this to send out control voltage to a polyphonic analog synthesizer, so it is plenty fast for that.


Pasted-image-20210324195118.png
 
Status
Not open for further replies.
Back
Top