Daisy Chaining AD5204 Digital Potentiometers
I’m using an Arduino to control two (maybe more – I haven’t tried yet) AD5204 digital potentiometers. Here’s some info about adapting the digital pot Arduino example to work with daisy chaining.
These 4-channel digital potentiometers are controlled via SPI. If you look in the Arduino SPI examples, you’ll see one that works with the 6-channel version of these chips (AD5206). It’s easy to adapt that example to the AD5204 – just change the 6 to a 4 in the loop that cycles through the channels. You should also know that the 4-channel version has some different hookup requirements. You’ll need to make sure that the /PR and /SHDN pins are held high or it will freak out.
Once you’ve got one AD5204 working, using that example sketch as a starting point, you can try daisy chaining two of them together. The AD5204 has a serial data output pin (SDO) that passes data from the first chip on to the second one in the daisy chain. This pin needs a pull-up resistor, by the way. 10K ohms works fine. Once you’ve got them wired together properly, it’s time to look at the code again.
From looking at the datasheet, you can see that one chip alone is expecting this kind of message from the microcontroller via SPI:
The first 3 bits are the address of the channel that you’re trying to change. The rest is the step that you want that channel to switch to (it’s an 8-bit number, so the steps are from 0 to 255)
If you look back at the sample Arduino code, you’ll see that they aren’t actually sending that to the chip – mainly because the SPI library only allows you to send 8 bits (aka 1 byte) at a time.. not 11. So the sample code ends up looking like this:
Not ideal, since it’s 16 bits instead of 11. The chip seems to be okay with this though.
When you’re trying to daisy chain the chips together, you’re supposed to hold the chip select (CS) pin low while you send TWO 11 bit messages over:
Now the question is, if we’re only able to send 8 bit messages at a time with the SPI.transfer() function, what do we do now that the chip is asking for two 11 bit messages back to back? Answer:
Modify the original digital pot Arduino example to do the above, between the lines that select and deselect the chip (where it writes slaveSelectPin LOW, then HIGH), and you’re done. (Sorry for the long-winded explanation, when that picture would probably have been enough for most people who are looking for this information) :)
Good luck
If this post is interesting to you, subscribe to this site.
Posted: May 10th, 2011 under electronica.
Comments: 3
Comments
Comment from Jenny
Time: December 1, 2011, 11:49 pm
We have a question regarding daisy chaining multiple AD5204 together. The way we were doing is concatenating 22 bits and sending that to two AD5204s. The clock SPI mode was set to mode2. Only one CS line was used and is initially set to low until all the data are send to the AD5204. The ship work with out daisy chaining but when daisy chained with another ship, we seem to get the wrong output. We used arduino to control it. Bellow is our code snippet:
#include
const int slaveSelectPin = 10;
const int SDIPin = 11;
const int CLKPin = 13;
void setup() {
pinMode(slaveSelectPin, OUTPUT);
//pinMode(SDIPin, OUTPUT);
//pinMode(CLKPin, OUTPUT);
SPI.setDataMode(SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV128);
SPI.setBitOrder(MSBFIRST);
SPI.begin();
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(7);
SPI.transfer(248);
SPI.transfer(255);
digitalWrite(slaveSelectPin,HIGH);
}
void loop() {
}
could you please suggest what is wrong with the code?
Thanks in advance
Comment from Ali GUNEYLI
Time: August 14, 2012, 2:49 pm
You do not need to do them because ad5204..06 work with two bytes data (16 bits). That means you have to send the chip XXXXX011 00000000 to set 4. pot to 0.
i have tried and it worked great. I’d wasted so many time because of untested theoritical information like this.
Regards,
A.G.
Comment from rob duarte
Time: August 14, 2012, 5:44 pm
I’ll have to take your word for it, Ali. I did this a while ago. I can tell you that it wasn’t untested theoretical information, though – I was trying to get it to work by reading the datasheet and it did work. Hopefully it’s the way you described, though – it sounds much easier.




Write a comment