Electronics > Beginners

SPI interfacing with AD5791 DAC via Raspberry Pi?

(1/4) > >>

imisaac:
The SPI pins on the AD5791 evaluation board is connected to a Raspberry Pi 3 Model B. In order to set some DAC output voltages, I tried to follow the guide here: https://wiki.analog.com/resources/quick-start/ad5791

In that guide, the DAC is supposed to output a midrange voltage (0V? I used +/-10V voltage references) after issuing the following string of binary bits to the DAC (0001 1000 0000 0000 0000 0000).

However, nothing happened....

Does the ordering of the bit stream need to be reversed (i.e. MSB first) in order to set the DAC register or I am missing another step in setting the /LDAC or /Clr bits? Or Raspberry Pi is not suitable for SPI with AD5791 for more subtle reasons?

As a complementary info, I used a loop-back test (i.e. connecting MOSI to MOSO) to confirm that I am indeed outputing something already.

Any tips would be extremely useful and thanks in advance!

LateLesley:
I think we need more information to be able to help you. You've told us that the reference voltages are +/-10V, but we don't know how the rest of it is connected.

First, supply voltages. What are you feeding in to :-
Vdd
Vss
Vcc
IOVcc

I think we can assume that VREFPS and VREFPF are at +10V, and that VREFNS and VREFNF are at -10V ??

when sending data, what are you setting the control pins to? (/LDAC, /CLR, /RESET)

These pins will need set for it to work, as these set the output from the register values.

You may be loading the value into the register, but you then need to set the control pins to set the output to the DAC register value.

EDIT : Just noticed, you can set the LDAC, CLR, RESET with data sent to the device, it's further down the datasheet, under "Writing to the Software Control Register". So try writing the DAC register, then sending to the software control register afterwards to latch the data in to the output.

Dave:
You need to write to the control register first and disable the output tristate mode.
All of this is described in the guide you linked to in your post.

imisaac:
Thanks all. I have not got the Pi set up working with AD5791 yet, but here is what I have tried.

To make sure the AD5791 evaluation board was functional, I connected a SDP board (also from AD) to it. Then, I ran the evaluation software on a Windows PC. In this set up, the DAC output could be manipulated. This implied that the DAC hardware was fine.

The evaluation board was powered by a single power supply of 4 V. There was no need to have a separate voltage reference. Nevertheless, I checked the Vref pins directly on AD5791 and got +/-10 volts from them.

On the software side, I was using Matlab to talk to Pi. Here is the code I was testing.

--- Code: ---clear rpi; clear spidevice;
rpi = raspi('192.168.178.49','xx','xxxx');
enableSPI(rpi);
spidevice = spidev(rpi,'CE0',2);
wdata = ['110011001100110011001100'];
writeAD5791(spidevice,wdata);

function [readdata] = writeAD5791(spidevice,wdata)
    wdata = flip(wdata);
    readdata = writeRead(spidevice,[bin2dec(wdata(1:8)) bin2dec(wdata(9:16)) bin2dec(wdata(17:end))],'uint8');
    pause(1);
end

--- End code ---


To make sure that the code was spitting out the bits, I connected the SPI outputs on the Pi to a ADALM20000 based logic analyser. The result from the first SPI write is attached. The guide to use SCOPY software to debug SPI is given here:
https://ez.analog.com/university-program/b/blogs/posts/adalm2000-spi-debug

It looks like the output bit stream is different from the one I intended. In the SPI write function I created, the intended bit stream was flipped in the order such that the MSB is spit out first. Looking at the logic analyser plot, however, the second bit counting from the left turns out to be wrong!

Does anyone know why this is happening? I guess this could be one of the reasons that the AD5791 was not responding...

Thanks in advance.

imisaac:
This is a short follow-up. It seems that the wrong bit stream was due to the logic analyser configuration in SCOPY. If the transition edges of each of the four SPI pins were meeting some "condition", the right bit stream could be observed.

I am not sure why it worked though....In particular, for each of the SPI pin, how do I know it is rising edge or falling edge detection?

The present edge detection characteristics are attached in case someone knows the reason.

Update:
In the Matlab program attached in the previous message, I used "mode 2" for the SPI communication. According to the wiki page of SPI,

https://en.wikipedia.org/wiki/Serial_Peripheral_Interface

mode 2 means that CPOL=1 and CPHA=0. That is, the SPI clock is 1 when idle. The data bits are spit out on the leading edge of the clock pulses. Therefore, in the logic analyser, I should set the MOSI an MISO pins for the rising edge detections as well.

Attached is the timing diagram for AD5791. The confusing part is that it is unclear the CPOL is 1 or 0 when idle for AD5791. Anyone knows the SPI mode for AD5791?

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod