MCP4231 vs. MCP4251?


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default MCP4231 vs. MCP4251?

    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?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: MCP4231 vs. MCP4251?

    Sorry. I didn't post the code correctly last time. Here it is again. Basically what I want to know is why does this work just fine on the MCP4231, but not on the MCP4251?

    Code:
        '
        '    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 255
            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

  3. #3
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: MCP4231 vs. MCP4251?

    The way I read the datasheet it doesn't look like the first byte you're sending is correct (WriteOnPot0/WriteOnPot1).

    The first 8-bits of the 16-bit command are: AD3 AD2 AD1 AD0 C1 C0 D9 D8
    where D9 and D8 are the upper parts of the 10-bit wiper data, followed by the lower 8-bits of data D7-D0 in the second byte

    The 7-bit part wiper settings are from 000H to 080H (full-scale), with 081H to 3ffH reserved
    The 8-bit part wiper settings are from 000H to 100H (full-scale), with 101H to 3ffH reserved

    I'm assuming you meant to use the binary constants
    Code:
        WriteOnPot0 con %000001
        WriteOnPot1 con %010001
    If so, you're always setting data bits D9 and D8 to '01' which means the wiper data is always from 100H to 1ffH


    Try these instead
    Code:
        WriteOnPot0 con %00000000
        WriteOnPot1 con %00010000

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: MCP4231 vs. MCP4251?

    Quote Originally Posted by tumbleweed View Post
    The way I read the datasheet it doesn't look like the first byte you're sending is correct (WriteOnPot0/WriteOnPot1).

    The first 8-bits of the 16-bit command are: AD3 AD2 AD1 AD0 C1 C0 D9 D8
    where D9 and D8 are the upper parts of the 10-bit wiper data, followed by the lower 8-bits of data D7-D0 in the second byte

    The 7-bit part wiper settings are from 000H to 080H (full-scale), with 081H to 3ffH reserved
    The 8-bit part wiper settings are from 000H to 100H (full-scale), with 101H to 3ffH reserved

    I'm assuming you meant to use the binary constants
    Code:
        WriteOnPot0 con %000001
        WriteOnPot1 con %010001
    If so, you're always setting data bits D9 and D8 to '01' which means the wiper data is always from 100H to 1ffH


    Try these instead
    Code:
        WriteOnPot0 con %00000000
        WriteOnPot1 con %00010000
    Thanks! That fixed it! I don't know why that previous code worked just fine for the 7-bit version, but it did. The 8 bit version didn't like it at all.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts