I've created a new library for use with the Analog Devices AD5668, an 8-channel, SPI interface Analog to Digital Converter chip, located at GitHub - bobhart/AD5668-Library: An Arduino library for the Analog Devices AD5668 Digital-to-Analog Converter. This library implements all 9 commands for the chip, and has constructors for both hardware and software SPI. I have tested all functions, and everything seems to work well. This is my first library, so of course suggestions and helpful criticisms would be appreciated. (Needless to say, I'm extremely excited about this!)
I created this library because after an exhaustive search, I could only find three projects that used this chip, including a 32 step sequencer by Christer Janson that I've been inspired by, but none of them provided methods for all the commands. Also, after reviewing posts on both the Analog Devices and TI web sites (TI has a compatible part DAC8568), I realized the initialization sequence didn't need to be as complicated as what was previously done. In fact, using the functions this library provides, the user could bypass my init() function and write their own sequence in startup() to set up the chip to some other initial condition.
Thanks Rob, I'm trying out your suggestions now. I've also discovered some minor mistakes in the code that I'm working on correcting, so for those who may have downloaded the library, I'll be updating it with changes in the next couple of days.
Making the changes to the data types, changing how variables b2 and b4 in the writeDAC function are built and consolidating the code in the init function save a total of 40 bytes of program memory and 8 bytes of dynamic memory in my AD5668_SoftLDAC example! Thanks for the suggestions!
Unfortunately, your suggestion for optimizing the line for building variable b3 in the writeDAC function didn't give correct results when writing an output value, so I kept the line as is. I've also cleaned up a few of the other functions where possible and corrected some errors in variables in some of the functions (I forgot to change to the private ones in the call to writeDAC). I've also made corrections to the keywords.txt file, as well as spelling errors in the README.
It's getting rather late for me, so I'll upload the changes hopefully tomorrow.
Actually, it turns out your first suggestion for b3 was correct, I think what I did last night was accidentally reverse the shift operator so it was shifting left instead of right (I was getting pretty tired). I tried it again tonight and every value I threw at it came out correct.
I also found a huge error in the command functions that set individual channel bits (powerDAC_x, setSoftLDAC). In the line that builds the value for chA_D, I was doing 0x0F | _channelsN, when it should have been 0x0F & _channelsN. I think the way I had written the test sketches had masked the error.
I've also had a major re-think on the init function. Due to the fact that the chip can be configured to such a large number of different start-up conditions, I've decided to limit the init function to only initializing the communication pins and clearing the chip. This will both simplify using the function and allow the user to decide which configuration commands suits their needs in their application by placing them in the sketch's setup function. I'm re-writing the examples to work with this change, and hopefully I can think of a few different configurations to show in more examples.
I will try to finish the edits tonight, hopefully I can get them uploaded tomorrow or Friday. Thanks again for all your help.
I have committed the changes to github. This version was bumped to 1.1 due to the major change to the init function. it also implements Rob's suggestions with significant memory savings, and fixes a major bug in all functions that set register bits for individual channels. I have re-written the examples to reflect the changes.
If you previously downloaded the library, you should replace it with the update due to the above-mentioned bugs as those functions in the old code DO NOT WORK. I have verified that values are now correctly written.
I was wondering if you've had a chance to see the changes I had made to the library. I really appreciated your help and would love to know your thoughts.
Thanks for making this library. I've ordered some samples from Analog.
I have the AD5668-1 and AD5668-3.
But for some reason I can't get any output from the DAC. I've tried all
three code samples. I've tested both the hardware and software SPI options.
Also tested with an external Vref and internal ref. With the use of
the internal Vref I don't see any voltage appear on the Vref pin ( 8 ).
Signals on the SLK and Din are nice 0 and 5V levels.
But for some reason it seems both DAC's doesn't initialize.
At the first test I used the -1 version, now the -3 is on my board.
Your code compiles fine without any errors. Is the code which is now
listed 100% working? Anyone else tested this from scratch?
I'm trying to understand what you have here and I have a question. What is the difference between WRITE_INPUT_REGISTER_UPDATE_N and UPDATE_OUTPUT_REGISTER as far as the hardware goes? The datasheet is a little ambiguous with these command values. Thank you for your help