AD5764 DAC library for Due project

Hi I have a 16bit DAC (AD5764rbsuz) I’m not able to find the proper library for it (I want the .cpp & .h) as I am trying to run other things off the Due like a TFT & SD card & blue tooth and communications to a second Due that is running Repetier on a Radds shield.

so I would like to create .cpp and .h files so I can run a main program and have all of these devices working together.

the only DAC lib files I can find are for AD57X4

not shure if these are any good for my dac ??? as they only go up to the AD5754 model

DAC57X4_V1.0.3.zip (7.53 KB)

Why do you need a library for this?

You very rarely need a library and you don’t need one in any shape or form for this chip? The use of a library has nothing to do with things working together.

Any library for a device starts with the datasheet. Do you have a link?

here is the data sheet

AD5764R-278558.pdf (551 KB)

thanks for spinning my brain out Grumpy_Mike I thought a library was needed to let the Arduino Due know what your intentions are ? … basic instructions on how the chip works ? so you can tell it how to operate

What I am intending to do is tell the DAC I want to go to a position (send it and instruction like channel a 100% or 52% or 0%… channel b 83% etc ) this should be communicated over the SPI so I can link the DAC channel up to a name like
Xaxis = channel b …0%= 0mm /50%=200mm/ 100% = 400mm
Yaxis = channel a…0%= 0mm /50%=200mm/ 100% = 400mm
Laser 1 = channel c… …100%=laser off / 50%= laser on half power /0% laser =full power
laser 2 =channel d… …100%=laser off / 50%= laser on half power /0% laser =full power

so the Dac needs live communications with my Computer or SD card or TFT
so I can press a button set up on the TFT and get a voltage that I want on the channel I want from the DAC

I thought using a library for the DAC one for the TFT one for the SD card

so I would have separate tabs for each part of the functions

main program called something like …

Dac_Sheld (void setup LasersBabby::setup(); & void loop)

LasersBabby.h (tft buttons do “this” and “Send this” to the dac…etc)

comms.cpp
comms.h (communications needed like i2c/SPI between the dac,the second arduino and the Bluetooth etc)

DAC.cpp
DAC.h

TFT.cpp
TFT.h<<<< I understand I could just use a… #include …if the library is on the my computer

Sd_Card.cpp
Sd_Card.h (sdcard 1 for sending bit maps to the TFT for each page in the menu) (sdcard 2 for moves)

Pins.h (pin selections)

Dose this show inside my brain

There is nothing stopping you from having functions in other tabs if you want to keep them separate, and then they are just as easily reusable as any library. These would just be .ino files. You only need to play with .cpp and optionally .h files if you want to write functions in C++, but plane C functions work just as well and in my opinion a bit better because you are not hiding what you are doing.

What I am intending to do is tell the DAC I want to go to a position (send it and instruction like channel a 100% or 52% or 0%... channel b 83% etc )

Yes you can do that with a function call although you are throwing away a lot of the resolution on your 16 bit D/A by restricting it to numbers between 0 and 100. In effect you are making your 16 bit converter into a 7 bit one.

so the Dac needs live communications with my Computer or SD card or TFT

No your DAC can only have live communication with your controller, any communication with anything else has to be through the controller. That applies if you are using a library or not.

Having had a quick look at the data sheet all you have is an SPI interface so you would be using the normal SPI interface lines plus a unique enable line. On the software side you send it just three bytes, a control byte and two data bytes as outlined in page 24 of the data sheet. The least significant three bits of the control byte determine which one of the four channels you are sending the data to, and there is an option to send the data to all four channels at once. the next three bits determine what register you are writing to. And the most significant bit determines if you have a read or write operation. It is a bit pointless having a read option as your code should know what you have written to it anyway.

A library ( a good one ) would have to cope with all the possible permutations and the documentation would have to reproduce what the data sheet says. If you write your own code then you decide how you want it to operate and you don't have to bother with modes you are not interested in. This makes the code smaller and faster than it could ever be with a library.

I would like to use the 16bit res so I can break up the 400mm at 100% to give a res of 0.006mm positions 100% = 65535 = 400mm so position 65534 gives a position of 399.004mm etc

I get that I need to send a bit to select read/write msb

DB23= 0 = write (chip select (sync)low)

second bit ? not shore what this dose

DB22= 0/1

next three bits for what mode the dac is doing

DB21= 0
DB20= 0
DB19= 0 = function register (if I’m correct would use to send my positions I want)

next three bits to select the dac channel

DB18 = 0
DB17 = 0
DB16 = 1 = dac channel (B) for example. For my Xaxis

next 16bits to give that channel the voltage output or in my case the laser power / X,Yaxis positions

DB15 = 1
DB14 = 0
DB13 = 0
DB12 = 0
DB11 = 1
DB10 = 0
DB9 = 0
DB8 = 1
DB7 = 1 Each of these bits should give me a res of 0.006mm if 400mm =100% 65535
DB6 = 0
DB5 = 1
DB4 = 0
DB3 = 1
DB2 = 0
DB1 = 1
DB0 = 1 = would give me position 35243= Xaxis over 400mm = position 215.1062mm

then pull the chip select (sync) high

so I need to add a function in one of the tabs (lasersBabby.h…?)to say my
Xaxis is 400mm = full power of dac (65535)
Xaxis is 0mm = negative end of dac (0)

each bit is worth 0.006mm

Xaxis = dac channel B // =001
Yaxis = dac channel A // =000

laser ttl 5v = 0% off
laser ttl 0v = 100% on (at brightest)

laser_1= dac channel C //=010
laser_2= dac channel D //=011

set all dac channels // =100// shouldn’t need this function

not decided which is the master and slave yet

Arduino Due number 1 with Radds shield attached to control my steppers temp sensors and end stops all works fine using repetier firmware (without being attached to second Due.. not yet mastered)

linked up to

Arduino Due number 2 with my AD5764 DAC shield that I have made. working on the firmware for this (with your help xxx) this controls ...

a 16bit DAC (AD5764rbsuz)...for laser X/Yaxis on a galvo system and laser #1/2 power control qvt320-240 TFT (display of temperature sensors positions of x/y/z, options modes and controls) Sdcard 1 (for internal the TFT only) Sdcard 2 (for externaly implementing Gcoad) Bluetooth (to connect instead of usb if desired)

once I can prove the DAC shield works and get the DAC to run as desired I would be happy to share gerbers / or make these shields

can I convert the 24bit number into a hex number and send that down the spi instead of sending 3x 8 bit lines ?

second bit ? not shore what this dose

DB22= 0/1

It does nothing it has t o be 0

DB19= 0 = function register (if I'm correct would use to send my positions I want)

No this is not what you want. This is what you want

Table 13. Programming the Data Register

can I convert the 24bit number into a hex number and send that down the spi instead of sending 3x 8 bit lines ?

Read this:- https://www.arduino.cc/en/Reference/DueExtendedSPI

that's a really helpful link thanks

(010) so its the data register that I need to identify to set my dac voltages

coarse gain & fine gain registers to trim up my voltages if I'm not happy with them

offset register (as far as I can grasp to do a non linier voltage sweep to adjust for my mirrors & galvos) i.e. from a strait voltage line to a bent one

so do we use the (000) function register for anything? is it used to activate the d1 & d0 pins for daisy chaining to a second dac I can't work it out

Well started the new year with a bang as my heads just gone pop looking at this data sheet hope your having a good start to the year

and another thing the clock divider

if I divide the 84MHz due clock by 4 I should get 21Mhz well under the 30MHz of the dac im running the other due at a baud rate of 115200 would giving the dac a baud rate of the same 115200 be like the clock divider function if so I would think this may help with communications if everything runs at the same speed..

or is setting the baud rate a different thing altogether (dose it affect clock cycles?)