Arduino With MCP4131 Digitally Controlled Potentiometer (DCP)
by kevinjpower in Circuits > Arduino
2872 Views, 5 Favorites, 0 Comments
Arduino With MCP4131 Digitally Controlled Potentiometer (DCP)
This project shows how to use the Arduino with a MCP4131 digitally controlled potentiometer. This allows for a digitally controlled variable resistor which will have multiple applications (variable frequency filters, changing volume on an amplifier)
Three demos are included:
- Step resistance up through its entire range and then step down via the entire range
- Based on user input via the serial interface, set the wiper value to a given value
- Read in wiper value and output result to the Serial Monitor
Supplies
Arduino
MCP 4131
100 Ohm Resistor
Breadboard and wires
MCP 4131 Digitally Controlled Potentiometer
The MCP family of integrated circuits are manufactured by Microchip and represent a range of digitally controlled potentiometers. The family of devices support 7-bit and 8-bit resistor networks using an SPI interface to control resistance.
A block diagram from the MCP data sheet is shown above.
The device can be used as two terminal variable resistor or a three terminal potentiomenter.
Control of the wiper position and hence the resistance is determined by the three digital inputs:
- Device is selected by taking CS low.
- Using a SPI serial interface (10 MHz, modes 0,0 & 1,1), high-speed Read/Writes are written to potentiometer registers. SCK synchronizes the clock between devices
- The wiper moves to the position determined by the value written to the register.
- The wiper has 128 (in the case of MCP4131) possible positions (0 – 128), allowing for incremental steps of about 0.8% of the total resistance.
- The current wiper position can be read from the MCP4131 via the SPI interface
Complete specifications for the MCP4131 can be found at the Microchip website.
https://www.microchip.com/en-us/product/MCP4131
https://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf
The specific device used in this project was a single Potentiometer with 7 bit resistor network (0 to 127) and had a total resistance of 10 kOhm
Downloads
SPI Interface
There are multiple articles on the internet regarding the SPI interface. There is a standard library available for the Arduino to communicate via the SPI protocol.
The Arduino pin assignments for this project shown in Image
MCP4131 Library
There is a standard library available for the Arduino that allows control of the MCP4131. Use the Tools→Manage Libraries… command to bring up the library manager window.
Search for MCP4131 and install the library to your IDE environment.
- MCP4131 name( int chip_select_pin); – command used to instantiate an object from the class. User can nominate which digital pin is used for chip select.
- name.readWiper( ); - returns a byte giving current position of the wiper (0-128)
- name.writeWiper(unsigned int wiperValue); - write a value to the MCP4131 to set wiper position
- name.decrementWiper( ); - decrement the wiper by one position
- name.incrementWiper( ); - increment the wiper by one position
The library needs the inclusion of the SPI library available for the Arduino.
Build the Circuit
The schematic of the circuit and a completed breadboard version is shown in the images.
Brief description of the circuit:
- The Arduino communicates with the MCP 4131 via the SPI bus
- D11 to D13 on the Arduino are configured as the SPI communication bus
- D10 is used as a Chip Select signal. This is configurable by the user
- Because of pin limitations on the MCP 4131, incoming and outgoing SPI communication is multiplexed via a single pin 3
- Resistor R1 is required in case of volt difference between the Arduino and MCP 4131. Because the Arduino and MCP are both working on 5V, 100 Ω is sufficient.
- Output is set up as a voltage divider and will nominally vary from 0 to 5V.
Step Up and Down Range
The code for this demonstration given below. The Arduino initializes the MCP4131 to 0 and then executes a loop that increments the MCP4131 wiper position from 0 to 128. After a pause, another loop decrements the wiper position from 128 to 0.
A voltmeter connected to the output will indicate a rising voltage fro 0 to 5V, pause and then show a falling voltage from 5 V to 0.
See the code for more details.
Downloads
User Input Sets Wiper
The code for this demonstration given below. After initialization, the Arduino awaits input from the user via the serial monitor. The user inputs a number between 0 and 127 and the wiper is set to that position.
A voltmeter connected to the output will measure a voltage between 0 and 5V depending on the user input. For example, an input of 64 (50% of range) will give a reading of approx 2.5V
See the code for more details.
Downloads
Read Wiper Value
The code for this demonstration given below. After initialization, the Arduino awaits input from the user via the serial monitor. The user inputs a number between 0 and 128 and the wiper is set to that position. The program then increments the wiper position by 2 steps. The wiper value is rerad back from the program and printed out to the Serial Monitor.
See the code for more details.
Downloads
What Next
Resistance and voltage values for various wiper positions were taken across the range.
Of course, there are inherent limitations to this circuit. The major limitation is the step nature of the potentiometer. The best resolution 0.8% of the total resistance. In this case, the 10KΩ total resistance gives a best case resolution of approximately 80 Ω
Potential applications of a MCP4131 include a variable cutoff frequency filter, variable gain amplifier and variable power supply. Microchip website contains several application notes that cover design of these circuits.