sabato 28 febbraio 2015

How to control a digital potentiometer using Arduino UNO


A potentiometer is a 3-terminal device used as a variable resistor. It has a rotating contact used as a voltage divider (see on Wikipedia).


 
A classical potentiometer


 
The symbol of the potentiometer






A voltage divider is a simple circuit where the output voltage is a fraction of the input voltage. You can use two fixed resistor or a potentiometer.

A simple example of voltage divider with a potentiometer


These examples are about mechanical potentiometers but there are types of potentiometers which are completely electronic and adjustable using proper input signals, they are called digital potentiometers

Today I want to test one of them, a MPC41010, which is a single potentiometer. Its max value is 10kohm (min value is not exactly 0 ohm but 100ohm).




A MCP41010 chip



A pinout diagram of a MCP41010



The name of the chip depends on the max value of the potentiometer and the number of them inside the chip:
MPC41010: single potentiometer, 10 khom
MPC41050: single potentiometer, 50 khom
MPC41100: single potentiometer, 100 khom
MCP42010: two independent potentiometers, 10 khom
MCP42050: two independent potentiometers, 50 khom
MCP42100: two independent potentiometers, 100 khom

To drive it I use an Arduino UNO board and its SPI port.
If you read their datasheet,you see that to program these chips you have first to send a "command byte" (to tell the chip what to do) and a "data byte" (to tell the chip which value of resistance to set, from 0 to 255). For example, to set a resistance value at 10kohm, you have to set the data byte to 11111111 (255), to set the value at 5kohm, you have to set the data byte to 10000000 (128).From the datasheet: "Executing any command is accomplished by setting CS low and then clocking-in a command byte followed by a data byte into the 16-bit shift register. The command is executed when CS is raised."

Connect your test circuit as showed in the picture below:

Circuit schematic (Fritzing)









and load the sketch in your Arduino UNO (download from github https://github.com/rickit69/techrm/tree/master/test_potenziometro_digitale_1)

In the sketch, there are two loops: the first one gradually increase the resistance on the LED, the second one gradually decrease the resistance on the LED. The result is that the LED glows (as you can see in the video below).




See also:
1 - http://nicksen782.blogspot.it/2010/06/digital-potentiometers-mcp42010.html

2 -  http://www.frankensteingarage.it/blog/2012/07/04/potenziometri-digitali/ (in Italian)