Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Using Arduino to Send Data to AD5781 DAC Register

Status
Not open for further replies.

napzap

Newbie level 5
Newbie level 5
Joined
Aug 30, 2017
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
107
Hello,

I am using an Arduino to send data to the AD5781 DAC register (I have the AD5781 evaluation board) -- specifically, in the big picture, I want to send data continuously from the Arduino to the DAC so that I can get a desired smooth waveform output from the DAC. However, I cannot seem to get an output from the DAC, and so I assume that there must be something wrong with the way I am interfacing the Arduino and DAC.

In order to help pinpoint the problem, I have drawn a timing diagram (attached) based on what I am trying to do and what I understand should be the proper method to communicate with the DAC register in order to write data to it from the Arduino.

Please let me know if you see any flaws in my logic / timing diagram / implementation.

For reference, here is a link to the AD5781 datasheeet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5781.pdf

Thank you for the help!

Neal
 

Attachments

  • DAC-Arduino Timing Diagram SPOT.pdf
    770 KB · Views: 216

Thanks for catching that! However, it looks like I just made that error in the timing diagram I drew; it is correct in the Arduino code. Are you able to recognize any other mistakes here with my logic? Am I not properly updating the output of the DAC based on the data sent to the DAC register? Am I writing the data correctly to the register?

Also, to double-check, I am using SPI_MODE2 for the Arduino SPI connection to DAC evaluation board. Is this the correct mode to use based on the DAC datasheet? Here is the link to where the Arduino SPI modes are listed: https://www.arduino.cc/en/Reference/SPI

Thanks,
Neal
 

The SDIN timing in your diagram is wrong. The data input has to be setup before the falling SCLK edge, e.g. on the rising clock edge.

- - - Updated - - -

The DAC supports mode 1 and 2. Instead of checking a probably erroneous diagram, we should look at the code.
 
  • Like
Reactions: napzap

    napzap

    Points: 2
    Helpful Answer Positive Rating
Thanks, and okay I am copying my code below:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <SPI.h>
 
// SYNC is called SS here, according to SPI library terminology
 
const int LDAC = 7; // pin 7
const int CLR = 6; // pin 6
const int RESET = 8; // pin 8
 
void setup() {
  pinMode(SS,OUTPUT);
  pinMode(LDAC, OUTPUT);
  pinMode(CLR, OUTPUT);
  pinMode(RESET, OUTPUT);
  digitalWrite(LDAC, LOW);
  digitalWrite(CLR, HIGH);
  digitalWrite(RESET, HIGH);
  SPI.begin();
  SPI.beginTransaction(SPISettings(30000000,MSBFIRST,SPI_MODE2)); 
}
 
void setDACVal() 
{
  digitalWrite(SS,LOW);
  SPI.transfer(B00010111); // first Byte which includes configured bits for DAC register address (writing - 0001)
  SPI.transfer(B11111111); // second Byte (DC signal)
  SPI.transfer(B00000000); // third Byte (more bits of DC signal configuration), so total of 24 bits have been sent
  digitalWrite(SS,HIGH); 
}
 
void loop() {
setDACVal();
}

 
Last edited by a moderator:

Hello,

Just checking in again -- can you see any errors in my code above, based on what I am trying to do here, as described in the former posts in this thread?

Thanks,
Neal
 

I cannot seem to get an output from the DAC,

You did not mention which Arduino board you are using; there are several hardware platforms, so that the pinout can have different functions or restrictions of use in each of them. Specifically speaking, the Arduino pins you are using for LDAC, CLR, and RESET, although they are available on most boards, the numbering you have chosen [7,6,8] suggests that you may have coincidentally chosen similar values to the pinout of AD5781 [6,7,8], so you should make sure you are using the correct I/Os of the board.
 
  • Like
Reactions: napzap

    napzap

    Points: 2
    Helpful Answer Positive Rating
Hello,

Thanks for your reply. I am using the Arduino Uno board. Would my chosen pinout be incorrect in this case? I'm not sure I understand. Also, for reference, I am using the AD5781 evaluation board which has pins that allow for SPI communication.

Neal
 

I'm familiar with AVR but not particular with Arduino. I don't even know which processor pin "Pin 6" etc. refers to. How about shoing the connection between Evalboard and Arduino?
 
  • Like
Reactions: napzap

    napzap

    Points: 2
    Helpful Answer Positive Rating
Just checking in again -- can you see any errors in my code above, based on what I am trying to do here, as described in the former posts in this thread?
If I understand correctly, AD5781 has to be configured before use. From the datasheet, page 25/29:
"After power-on, the AD5781 must be configured to put it into normal operating mode before programming the output. To do this, the control register must be programmed. The DAC is removed from tristate by clearing the DACTRI bit, and the output clamp is removed by clearing the OPGND bit."

You set SPI speed for 30Mhz, but Arduino UNO can do something like 8MHz max. Arduino SPI library uses automatically maximum possible frequency so I assume clock frequency will be 8MHz.
 
  • Like
Reactions: napzap and FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating

    napzap

    Points: 2
    Helpful Answer Positive Rating
You are right, AD5781 must be enabled by a write to the control register. It's missing in the posted code.

SCK frequency shouldn't be a problem, I presume the Arduino libraries are setting the highest possible frequency when specifying 30 MHz. It's however reasonable to check all Arduino signals with an oscilloscope.
 
  • Like
Reactions: napzap

    napzap

    Points: 2
    Helpful Answer Positive Rating
Thank you for catching that! I have updated the code (below) to include the enablement of the AD5781 by writing to the control register. Can you please review the code and let me know if I have done this correctly? Thanks.



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <SPI.h>
 
// SYNC is called SS here, according to SPI library terminology
 
const int LDAC = 7; // pin 7
const int CLR = 6; // pin 6
const int RESET = 8; // pin 8
 
void setup() {
  pinMode(SS,OUTPUT);
  pinMode(LDAC, OUTPUT);
  pinMode(CLR, OUTPUT);
  pinMode(RESET, OUTPUT);
  digitalWrite(LDAC, LOW);
  digitalWrite(CLR, HIGH);
  digitalWrite(RESET, HIGH);
  SPI.begin();
  SPI.beginTransaction(SPISettings(8000000,MSBFIRST,SPI_MODE2)); // 8 MHz operation
  digitalWrite(SS,LOW);
  SPI.transfer(B00100000); // MSB of 0010 means write to control register
  SPI.transfer(B00000000); // all reserved bits are 0
  SPI.transfer(B00000010); // clear the DACTRI and OPGND bits so that DAC is in normal operating mode
  digitalWrite(SS,HIGH);
}
 
void setDACVal() 
{
  digitalWrite(SS,LOW);
  SPI.transfer(B00010111); // first Byte which includes configured bits for DAC register address (writing - 0001)
  SPI.transfer(B11111111); // second Byte (DC signal)
  SPI.transfer(B00000000); // third Byte (more bits of DC signal configuration), so total of 24 bits have been sent
  digitalWrite(SS,HIGH); 
}
 
void loop() {
setDACVal();
}

 
Last edited by a moderator:

Can you please review the code and let me know if I have done this correctly?

If you had read the previous replies carefully you would have remembered to post the schematic of the circuit.
 

Yes, sorry about that - I assumed that it was clear from my comments on the code that pin 7 on the Arduino UNO board is connected to the LDAC pin on the AD5781 EVAL, and so on for the other pins.

Is there something I'm missing here? What schematic are you referring to, otherwise?
 

As an update, I just tested the code I most recently posted here, and I am still not getting any output from the VOUT pin on the AD5781 EVAL board. I've double checked with the datasheet and I'm pretty sure now that I'm initializing the DAC and writing to the DAC register correctly. I've also probed each of the Arduino pins using an oscilloscope to ensure that I'm actually sending the information I mean to send to the DAC. All is as intended. I'm really confused as to how I still am not getting an output. I've followed each step as per the datasheet. The only thing I can think of is that I'm writing to the register but the output is not being updated based on that register value? This could be a timing issue? Or is there a clear flaw in my code that I'm not catching? Please help.

Thanks
 


Yes, I know about the evaluation software, and in fact also have the SDP-B board which is used to operate the evaluation software and control the DAC. However, I did not find it useful for what I'm working on, and therefore went with the more versatile approach of using an Arduino to send data to DAC SPI communication, and thereby control the DAC in this manner.

Given this approach, can you guide me in any other way to solve the current problem I am having, as I'm getting no output from the DAC? Have you reviewed over my code?

Thanks.
 

Hi,

Can you show us a complete schematic...
And the scope pictures...

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top