PDA

View Full Version : Microchip MCP41xxx Digital Potentiometer Code Trouble



CocaColaKid
- 31st August 2005, 14:37
Can someone possibly explain to me why this code would not work? When I run it the digital pot does nothing.



si var portb.2
sclk var portb.1
cs var portb.0

pot_value var byte
data_word var word

low sclk ' Set clock pin low
high cs ' Set chip select low

clear

start:
pot_value = pot_value + 1
data_word.byte0 = %00010001 ' Set write instruction to potentiometer 0
data_word.byte1 = pot_value ' Set potentiometer value to be written
gosub shout
goto start

shout:
low cs
shiftout si,sclk,1,[data_word\16] ' Shift 16 bits out starting at bit0
high cs
return

Damir
- 31st August 2005, 15:57
Hello.
Maybe you must first shiftout write command and after that shiftout value.

Regards,
Damir

CocaColaKid
- 31st August 2005, 16:19
I thought I orginally tried that way and it didn't work however it does now so I can only assume I had something missed. Anyways though, what I want to do is to daisy chain three of these together. According to the data sheets when a command comes in a NOP is sent out the serial output line which loads the 2nd chip with all 0's. Now if I issue this command now and add a NOP after it should it not push it into the 2nd chip?

CocaColaKid
- 31st August 2005, 18:21
I figured out the source to all my problems. I originally had the SPI lines on porte which didn't work so I moved them over to portb and then everything worked fine. The reason I had so my problems is because I forgot to sent porte to digital instead of analog, oops.