Saturday, March 29, 2014

How to Configure a Digital Potentiometer (eg : MCP41100) as Rheostat or Potentiometer.

Digital Potentiometers are used for two purposes : One is as Rheostat mode and other one is Potentiometer mode. Lets see the pins of MCP41100 :



Here the potentiometer communicates with Arduino using SPI Protocol. By default, Arduino D10 is SS (CS bar), D11 is MOSI (SI) , D12 is MOSO, and  D13 is SCK. So connect the potentiometer pins to Arduino as mentioned mapping. Further :

Vss - GND
Vdd - Supply Voltage (2.7V to 5.5V)
PW0 - Output is taken
PA0 - To GND
PB0 - To Vdd ( For using as potentiometer) or To PW0 ( For using as Rheostat)

Now Circuit is ready. Time to move to programming.

Program : 
#include <SPI.h>  //Include SPI library

void setup()
{
  SPI.begin();  //Initialize SPI
  Serial.begin(9600);
  pinMode(ss, OUTPUT);  //Set Pin Direction ,Other SPI pins are     //configured automatically
}

void loop()
{
    for (int i=0; i<=255; i=i+1)  // This is because 8 bit Range
    {
      SetPot(0x11,i);
      delay(200);
    }
    delay(200);
    for (int i=255; i>=0; i=i-1)
    {
      SetPot(0x11,i);
      delay(200);
    }
  }

//Function to Set the Potentiometer
void SetPot(int regVal, int levelVal)
{
  digitalWrite(ss,LOW);
  SPI.transfer(reg);
  SPI.transfer(level);
  //Serial.print(level);
  digitalWrite(ss,HIGH);
}

Done.

Note 1 : If you have picked D10 as Slave Select you cannot name it as SS because by default it is named as SS. But you can select any pin for SS. You only need to set the declare and configure its pin mode.

Node 2 : If you want control voltage, You do not need a Digital Potentiometer because you can do it using Arduino only but if you need to get varying resistance use Digital Potentiometer.


No comments: