I'm trying to get a Chinese 20A DC Motor Speed Controller working with a MCP42100 Digital Potentiometer. The analogue potentiometer supplied was 100kOhm. I have programmed my arduino with the following code:
#define DATAOUT 11
#define DATAIN 12 //not used
#define SPICLOCK 13
#define SLAVESELECT 10
#define NOTEON 9
int potValue = 255;
float potInputValue;
void SPIInitialize()
{
byte clr;
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
pinMode(SLAVESELECT, OUTPUT);
digitalWrite(SLAVESELECT, HIGH); //disable device
SPCR = (1 << SPE) | (1 << MSTR);
clr = SPSR;
clr = SPDR;
delay(10);
}
char SPITransfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1 << SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
//--- MCP42100 code
byte SetPot(int address, int value)
{
// Slave Select set low to allow commands
digitalWrite(SLAVESELECT, LOW);
// 2 byte command
SPITransfer(0x10 + address); // 0x10 = 'set pot' command
SPITransfer(value); // Value to set pot
// Release chip, signal end transfer
digitalWrite(SLAVESELECT, HIGH);
}
//--- Application code
void setup()
{
SPIInitialize(); // Initialize the SPI interface
Serial.begin(9600);
delay(25);
Serial.println("Type a resistance between 0-100 kOhms above.");
}
void loop()
{
if (Serial.available() > 0) {
// read the incoming byte:
potInputValue = Serial.parseInt();
float potValue = (potInputValue / 100.0) * 255;
Serial.print("Value: ");
Serial.print(potValue);
Serial.print(", Resistance: ");
Serial.print(potInputValue);
Serial.println(" kOhms");
SetPot(1, potValue);
}
}
Here is a picture of my setup:
Currently at a resistance of 0 kOhms the motor runs at full speed, as it should do and this is how it reacts with the analogue potentiometer. At a resistance of 100 kOhms, the motor (in this case a computer fan) still has enough juice to spin, until I stop it with my finger, but then it doesn't spin without a little push. With the analogue potentiometer, at 100 kOhms the motor received no juice to spin.
Here is a link to the speed controller: http://www.ebay.co.uk/itm/301366805277?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
The speed controller appears to use a 555 timer.
What am I doing wrong with the digital potentiometer to make it so it doesn't behave the same way as the analogue potentiometer?