I was working with the 7-bit MCP4231. Everything was going fine, but I eventually found that I needed the finer resolution of the 8-bit MCP4251. I had assumed that the two were essentially pin-for-pin, and that even the code on the MCU didn't need to be changed (the wiper would just move half as far on the 4251). Below is an example practice code I used to get started working with the 4231.

  • ' ' Hardware configuration ' ====================== TRISC=0 ' ' Hardware connection ' =================== CS VAR PORTC.0 CLK VAR PORTC.1 SI VAR PORTC.2 ' ' Variables definition ' =================== Wiper var byte ' ' Constants definition ' ==================== MSBFIRST CON 1 WriteOnPot0 con 000001 WriteOnPot1 con 010001 ' ' Software/Hardware initialisation ' ================================ cs = 1 ' disable MCP PAUSE 100 ' safe settle time Start: for wiper = 0 to 126 cs=0 ' enable shiftout si,clk, MSBFIRST,[WriteOnPot0, WIPER] ' Write to MCP first address shiftout si,clk, MSBFIRST,[WriteOnPot1, WIPER] ' Write to MCP second address cs = 1 ' Disable pause 10 next goto start


when attached to an LED, this program makes an LED get brighter and then stay fully lit. I had assumed that if I simply replace the 4231 with the 4251, that the program would still work, but the LED would only be lit half way, and that if I changed "for wiper = 0 to 255", that it would make the LED go to full brightness, but take twice as long. See page 38 of datasheet.

What am I missing here?