i am trying to control AD5290 using arduino using below attached code, here iam getting the value of pot as 7k ohms. even though i am changing the values of resistance from 0-255. can any one help to fix this problem
#include <SPI.h>
const int CS_PIN = 9;
const int SDI_PIN = 10;
const int SDO_PIN = 11;
const int SCLK_PIN = 13;
// Set initial resistance value (0-255, where 0 is minimum resistance and 255 is maximum)
setResistance(50); // Example: set the resistance to halfway
}
void loop() {
// Your main code logic goes here
// You can change the resistance value using the setResistance() function
}
void setResistance(byte resistanceValue) {
digitalWrite(CS_PIN, LOW); // Set CS low to enable communication with the AD5290
SPI.transfer(resistanceValue); // Send the command to set the resistance value
digitalWrite(CS_PIN, HIGH); // Set CS high to end communication
}
1. Check that you have connected your pot with UNO as per Fig-1.
Figure-1:
2. Upload the following sketch (your one with slight modification).
#include <SPI.h>
const int CS_PIN = 10;//9;
const int SDI_PIN = 12;//10;
const int SDO_PIN = 11;
const int SCLK_PIN = 13;
void setup()
{
// Set pin modes
/* pinMode(CS_PIN, OUTPUT);
pinMode(SDI_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
pinMode(SCLK_PIN, OUTPUT);*/
// Initialize SPI
SPI.begin();
// SPI.setDataMode(SPI_MODE2);
// SPI.setBitOrder(MSBFIRST);
// Set initial resistance value (0-255, where 0 is minimum resistance and 255 is maximum)
// setResistance(50); // Example: set the resistance to halfway
}
void loop()
{
}
void setResistance(byte resistanceValue)
{
digitalWrite(CS_PIN, LOW); // Set CS low to enable communication with the AD5290
SPI.transfer(resistanceValue); // Send the command to set the resistance value
digitalWrite(CS_PIN, HIGH); // Set CS high to end communication
}
3. Connect DVM between across W and GND. Check that DVM reads about 1V.
I had changed the resistance values from 0-255 in that code, but the value of the digipot is showing the same 7k ohm resistance between wiper and VA pins, I need different values of resistance ranging from 0 to 10k ohms. can you help me.
I have did the same thing what you have said, and connections are made as per block diagram mentioned by you.
but I am getting 4.9v between W and Ground. what should I do now.
Arduino --> AD5290
MOSI (pin 11) --> SDI
SCK (pin 13) --> CLK
SS (pin 10) --> CS
Use this code:
#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();
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
}
void loop()
{
// change the resistance from min to max:
for (int level = 0; level < 255; level++)
{
digitalPotWrite(level);
delay(100);
}
}
void digitalPotWrite(byte value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin, LOW);
delay(5);
// send value via SPI:
SPI.transfer(value);
delay(5);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin, HIGH);
}
#include <SPI.h>
//const int CS_PIN = 10;//9; if using UNO, then no need
//const int SDI_PIN = 12;//10;
//const int SDO_PIN = 11;
//const int SCLK_PIN = 13;
void setup()
{
// Set pin modes
/* pinMode(CS_PIN, OUTPUT);
pinMode(SDI_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
pinMode(SCLK_PIN, OUTPUT);*/
// Initialize SPI
SPI.begin();
// SPI.setDataMode(SPI_MODE2);
// SPI.setBitOrder(MSBFIRST);
// Set initial resistance value (0-255, where 0 is minimum resistance and 255 is maximum)
digitalWrite(SS, HIGH);
setResistance(50); // Example: set the resistance to halfway
}
void loop()
{
}
void setResistance(byte resistanceValue)
{
digitalWrite(SS, LOW); // Set CS low to enable communication with the AD5290
delay(10);
byte y = SPI.transfer(resistanceValue); // Send command to set resistance value
delayMicroseconds (10);
digitalWrite(SS, HIGH); // Set CS high to end communication and to latch data
}
Thank u for this code, can u help me with the code which can keep the resistance of digipot at a constant position, actually this is incrementing the digipot. I want to set it at 2k ohms can u help me with that.