I have implemented this code and have used it to set a voltage for an LED, but what I am having issues with is that not all the potentiometers are working. It seems only pot 0 is recieving commands.
What is the relation between "channel" and address? What is the relation between "level" and value? I do not understand how the arduino is registering which "channel" to change considering there is nothing like:
channel = address
Can someone please explain this further?
/*
Digital Pot Control
This example controls an Analog Devices AD5206 digital potentiometer.
The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
A - connect this to voltage
W - this is the pot's wiper, which changes when you set it
B - connect this to ground.
The AD5206 is SPI-compatible,and to command it, you send two bytes,
one with the channel number (0 - 5) and one with the resistance value for the
channel (0 - 255).
The circuit:
* All A pins of AD5206 connected to +5V
* All B pins of AD5206 connected to ground
* An LED and a 220-ohm resisor in series connected from each W pin to ground
* CS - to digital pin 10 (SS pin)
* SDI - to digital pin 11 (MOSI pin)
* CLK - to digital pin 13 (SCK pin)
created 10 Aug 2010
by Tom Igoe
Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
*/
// inslude the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
void setup() {
// set the slaveSelectPin as an output:
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}
void loop() {
// go through the six channels of the digital pot:
for (int channel = 0; channel < 6; channel++) {
// change the resistance on this channel from min to max:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, level);
delay(10);
}
// wait a second at the top:
delay(100);
// change the resistance on this channel from max to min:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, 255 - level);
delay(10);
}
}
}
void digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin, LOW);
// send in the address and value via SPI:
SPI.transfer(address);
SPI.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin, HIGH);
}
Using digipots to change brightness of LEDs is a horrible way to do it - there are all sorts of issues. Most of the range of the digipot is wasted regardless, since the resistance of digipots is way too high for LED ballast resistors, yet if you put it close to the high end, the resistance from supply to the LED could be small enough to exceed both the LED's and digipot's absolute maximum ratings, potentially destroying the LED and/or digipot. Could you have burned out channel 0 trying to get the led brighter? It's certainly possible if you have it wired the way I fear you do.
You haven't told us how you have it wired.
Why not use PWM/analogWrite() to dim the LED, or one of the many multi-channel LED dimmer chips if you need more dimmed LEDs?
spycatcher2k:
Exactly what digital pot do you have?
Im using a AD5206BRZ10
DrAzzy:
Comments say it's a AD5206.
Using digipots to change brightness of LEDs is a horrible way to do it - there are all sorts of issues. Most of the range of the digipot is wasted regardless, since the resistance of digipots is way too high for LED ballast resistors, yet if you put it close to the high end, the resistance from supply to the LED could be small enough to exceed both the LED's and digipot's absolute maximum ratings, potentially destroying the LED and/or digipot. Could you have burned out channel 0 trying to get the led brighter? It's certainly possible if you have it wired the way I fear you do.
You haven't told us how you have it wired.
Why not use PWM/analogWrite() to dim the LED, or one of the many multi-channel LED dimmer chips if you need more dimmed LEDs?
I have 220 ohm resistors in series with each A pin of the potentiometer. I assure you no damage was done to the LED or the potentiometer. It is wired as shown here: Digital Pot Control
I can see how my example is a bit misleading. Controlling LED brightness is not my end goal. I am just using the example to indicate that I can control each channel individually. The end goal will be controlling audio parameters with recall and preset configurations.
Is there something that I am missing? From what I understand the potentiometer takes 2 bits at a time, the address and the value.
How does the program understand that value = level, address = channel ?
The SPI timing diagram shows the clock polarity (CPOL) normally low, so CPOL=0.
The datasheet mentions that the clock loads data into the serial register on each positive clock edge, so with CPHA=0 the data is sampled on the leading (first) clock edge.
For Arduino, this relates to SPI_MODE0, so you'll need to use this in your setup SPI.setDataMode(SPI_MODE0);
What is the relation between "channel" and address? What is the relation between "level" and value? I do not understand how the Arduino is registering which "channel" to change considering there is nothing like: channel = address
Its all done in one 11-bit word where B0-B7 is the data and B8-B10 is the address. "The format of this data-word is three address bits, MSB first, followed by eight data bits, MSB first."
You should use this in your setup SPI.setBitOrder(MSBFIRST);
I would try creating 2 bytes, where the first byte would have the address in B2, B1 and B0.
B7-B3 would end up being shifted out and are redundant. The second byte could have the remaining 8 bits of data in B7-B0. The SS pin needs to be held low between the 2 byte transaction.
SPI byte 1 (send first):
B7 B6 B5 B4 B3 B2 B1 B0
X X X X X A2 A1 A0
SPI byte 2 (send last):
B7 B6 B5 B4 B3 B2 B1 B0
D7 D6 D5 D4 D3 D2 D1 D0
(just my theory on how it could work, I don't have the hardware)