Difference between revisions of "NU32: Using the MCP42X1 SPI Digital Potentiometer"
Line 46: | Line 46: | ||
LcdInitialize(); |
LcdInitialize(); |
||
LcdClear(); |
LcdClear(); |
||
</pre></code> |
|||
Go to the leftmost side of the screen on the second line and write 'Hello' |
|||
<code><pre> |
|||
gotoXY(0,1); |
|||
LcdString("Hello"); |
|||
</pre></code> |
|||
Write the value of a variable: |
|||
<code><pre> |
|||
char str[5]; |
|||
sprintf(str, "i=%d", i); |
|||
LcdString(str); |
|||
</pre></code> |
|||
Turn on a pixel at (20,35): |
|||
<code><pre> |
|||
setPixel(20,35,1); |
|||
</pre></code> |
</pre></code> |
Revision as of 09:26, 14 July 2012
The MCP42X1 is a 7-bit dual digital potentiometer. It is available in total resistance options of 5, 10, 50 and 100 kOhm. It is controlled using SPI communication and a digital output (chip select).
Overview
A potentiometer is useful in a variety of circumstances when a variable resistance is needed. A digital potentiometer allows provides a variable resistor that can be controlled from a microcontroller. Because the MCP42X1 is a 7-bit device, there are 2^7 = 128 possible resistance "steps". By communicating with the IC over SPI, we can choose what step (and thus, resistance) the potentiometer is set at.
The resistance across the PxB and PxW (the wiper) is governed by where the 5kOhm comes from the total resistance of the pot, depending on the model. The value N is the setting of the pot between 0 and 127.
The pot requires four communication pins from a microcontroller: SPI CLK, SDO, SDI, and one digital output. The pot is powered with 3.3V. This model is a dual pot chip, meaning it has two completely independent potentiometer channels in the same IC, referred to as Pot 0 and Pot 1, respectively.
Details
Example schematic when communicating with the NU32, using SPI channel 1:
- Pot 1-CS -----> F3
- Pot 2-SCK -----> D10
- Pot 3-SDI -----> D0
- Pot 4-VSS -----> GND
- Pot 5-P1B -----> P1+
- Pot 6-P1W -----> P1-
- Pot 7-P1A -----> NC
- Pot 8-P0A -----> NC
- Pot 9-P0W -----> P0-
- Pot 10-P0B -----> P0+
- Pot 11 -WP -----> NC
- Pot 12 - SHDN -----> 3.3v
- Pot 13-SDO -----> C4
- Pot 14-VDD -----> 3.3v
The resistance across PXB and PXW is what changes, labeled above as Px+ and Px-.
Library Functions
MCP42X1.c contains the following functions:
Sample Code
Initialize and clear the LCD:
LcdInitialize();
LcdClear();