PDA

View Full Version : MCP41xxx Digital pot issue



jmgelba
- 16th February 2016, 18:42
I cant seem to get a MCP41100 single digital pot to work. The wiper is always at mid point. I've tried many different things to get this working but just no luck. Can anyone see what the issue might be? There's data out to the pot and timings seem fine so I have no idea what is going wrong at this point.

On a second look - it seems the SCK pin is going high at the start of data and then low after the 16 bits have been sent. Shouldn't it go high and low for each bit sent?



Define OSC 48
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
Include "modedefs.bas"
SCK var PORTB.1 ' Alias PORTC.3 to SCK (serial data clock)
SDO var PORTA.5 ' Alias PORTC.5 to SDO (serial data out)
CS var PORTB.2 ' Alias PORTC.2 to C_EN (chip enable)
POT0 var byte '
increment var byte
increment = 0

TRISA = %11011111 ' Set PORTA to all input except 5
ADCON1 = %00000000 ' Set PORTA analog and right justify result
ADCON2.7=1
TRISB = %00011001
TRISC = %01000000

HIGH CS 'Chip enable high to start
high sck 'Mode 1,1 SCK idles high

loop1
increment = increment + 1
write 0, increment

pot0 = %00010001

GOSUB write_pots
goto loop1

WRITE_POTS:

low CS ' Make chip active
shiftout sdo,sck,5,[pot0,increment] ' Mode 1,1 / Mode 5 PBP - clock idles high, MSB shift out first
high CS '

return

End

HenrikOlsson
- 16th February 2016, 20:27
Hi,
With MODE 5 the clock should idle high and go low and return high for each bit of data.
You don't say which PIC this is but you have the Clock output on PortA where analog stuff is normally located. Check and double check that analog functions are turned OFF for the pins used as Clock and data.

/Henrik.

jmgelba
- 16th February 2016, 21:27
PIC 18F2550

There is data from each pin so the pins are correctly set to digital outputs. The clock does idle high and goes low for each bit. I'm stumped. I've followed code I've used before that has worked. No idea what is wrong this time.

HenrikOlsson
- 16th February 2016, 21:49
You have ADCON1 = %00000000 which for the 18F2550 means ALL analog inputs enables, that includes PortA.5 where you have your SDO pin - that doesn't look quite right to me. Then, looking at the datasheet for MCP41xxx it's pretty clear that it clocks the data in on the rising edge of the clock so you probably have the wrong polarity selected in the SHIFTOUT command.

/Henrik.

jmgelba
- 17th February 2016, 18:22
The mode is correct but I did miss the analog setting. Thank you.