Introduction: Arduino With MCP4131 Digitally Controlled Potentiometer (DCP)

About: Retired Electrical Engineer pursuing my hobby

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:

  1. Step resistance up through its entire range and then step down via the entire range
  2. Based on user input via the serial interface, set the wiper value to a given value
  3. Read in wiper value and output result to the Serial Monitor

Supplies

Arduino

MCP 4131

100 Ohm Resistor

Breadboard and wires

Step 1: 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:

  1. Device is selected by taking CS low.
  2. 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
  3. The wiper moves to the position determined by the value written to the register.
  4. 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.
  5. 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

Step 2: 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

Step 3: 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.

  1. MCP4131 name( intchip_select_pin); – command used to instantiate an object from the class. User can nominate which digital pin is used for chip select.
  2. name.readWiper( ); - returns a byte giving current position of the wiper (0-128)
  3. name.writeWiper(unsigned int wiperValue); - write a value to the MCP4131 to set wiper position
  4. name.decrementWiper( ); - decrement the wiper by one position
  5. name.incrementWiper( ); - increment the wiper by one position

The library needs the inclusion of the SPI library available for the Arduino.

Step 4: Build the Circuit

The schematic of the circuit and a completed breadboard version is shown in the images.

Brief description of the circuit:

  1. The Arduino communicates with the MCP 4131 via the SPI bus
  2. D11 to D13 on the Arduino are configured as the SPI communication bus
  3. D10 is used as a Chip Select signal. This is configurable by the user
  4. Because of pin limitations on the MCP 4131, incoming and outgoing SPI communication is multiplexed via a single pin 3
  5. 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.
  6. Output is set up as a voltage divider and will nominally vary from 0 to 5V.

Step 5: 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.

Step 6: 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.

Step 7: 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.

Step 8: 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.