+ Post New Thread
Results 1 to 17 of 17
  1. #1
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Using Arduino to Send Data to AD5781 DAC Register

    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: http://www.analog.com/media/en/techn...ets/AD5781.pdf

    Thank you for the help!

    Neal

    •   Alt14th January 2018, 08:53

      advertising

        
       

  2. #2
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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



  3. #3
    Super Moderator
    Points: 238,838, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,369
    Helped
    12622 / 12622
    Points
    238,838
    Level
    100

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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.


    1 members found this post helpful.

  4. #4
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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 FvM; 14th January 2018 at 10:35. Reason: Added syntax tags



  5. #5
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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



  6. #6
    Super Moderator
    Points: 25,050, Level: 38
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    7,547
    Helped
    933 / 933
    Points
    25,050
    Level
    38
    Blog Entries
    5

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

    •   Alt15th January 2018, 04:54

      advertising

        
       

  7. #7
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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



    •   Alt15th January 2018, 05:51

      advertising

        
       

  8. #8
    Super Moderator
    Points: 238,838, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,369
    Helped
    12622 / 12622
    Points
    238,838
    Level
    100

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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?


    1 members found this post helpful.

  9. #9
    Member level 1
    Points: 614, Level: 5

    Join Date
    Oct 2015
    Location
    Helsinki, Finland
    Posts
    37
    Helped
    10 / 10
    Points
    614
    Level
    5

    Re: Using Arduino to Send Data to AD5781 DAC Register

    Quote Originally Posted by napzap View Post
    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.


    2 members found this post helpful.

  10. #10
    Super Moderator
    Points: 238,838, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,369
    Helped
    12622 / 12622
    Points
    238,838
    Level
    100

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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.


    1 members found this post helpful.

  11. #11
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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 bassa; 16th January 2018 at 08:19. Reason: add code tag



  12. #12
    Super Moderator
    Points: 25,050, Level: 38
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    7,547
    Helped
    933 / 933
    Points
    25,050
    Level
    38
    Blog Entries
    5

    Re: Using Arduino to Send Data to AD5781 DAC Register

    Quote Originally Posted by napzap View Post
    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  13. #13
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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?



  14. #14
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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



  15. #15
    Super Moderator
    Points: 25,050, Level: 38
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    7,547
    Helped
    933 / 933
    Points
    25,050
    Level
    38
    Blog Entries
    5

    Re: Using Arduino to Send Data to AD5781 DAC Register

    Quote Originally Posted by napzap View Post
    Or is there a clear flaw in my code that I'm not catching? Please help.
    Should we ask if you really have considered all the manufacturer information available on the product page ? Taking a look there, one of the first thing we can see is an evaluation software: http://www.analog.com/en/design-cent...ml#eb-overview
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   Alt17th January 2018, 03:45

      advertising

        
       

  16. #16
    Newbie level 5
    Points: 123, Level: 1

    Join Date
    Aug 2017
    Posts
    10
    Helped
    0 / 0
    Points
    123
    Level
    1

    Re: Using Arduino to Send Data to AD5781 DAC Register

    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.



  17. #17
    Super Moderator
    Points: 54,091, Level: 56
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    10,903
    Helped
    2576 / 2576
    Points
    54,091
    Level
    56

    Re: Using Arduino to Send Data to AD5781 DAC Register

    Hi,

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

    Klaus
    Please don´t contact me via PM, because there is no time to response to them. Thank you.



--[[ ]]--