SHIFTOUT with MCP42
gemeyer
Posts: 7
Has anyone been succesful using SHIFTOUT to control a MCP42 digital potentiometer? Reading the specs makes me think it should work but it is not recognizing any commands. The MCP42 is from Microchip and I ordered it from Jameco.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
You don't state any specific problem you're having, so the following is just a thought or two. Whether you're using the MCP41XX or the MCP42XX you are still required to output all 16 bit (two bytes) to the device. Addiditonally, if your problem involves SHUTDOWN and you are using a Revison A part, you might do well to head for the Microchip web site and retrieve the errata document, which discusses known problems with that aspect of the chip.
All I can think of in addition to that is to use MSBFIRST, and /16 after your variable name in the SHIFTOUT instruction to ensure that all of the 16 bits necessary are indeed sent out. Since this an SPI device, I'm not sure whether I2COUT can be made to work with it or not, but SHIFTOUT certainly can and will work with it.
Regards,
Bruce Bates
The data sheet is at http://www.jameco.com/wcsstore/Jameco/Products/ProdDS/241752MCH.pdf
I could only print it, sorry.
My program is....
'{$STAMP BS2p}
' demo program for digital potentiometer MCP42
MCPword VAR Word
MCPcmd VAR MCPword.HIGHBYTE
MCPvalue VAR MCPword.LOWBYTE
i VAR Byte
MCPcmd = $11 'send data to pot 1
MCPvalue = 1
DEBUG BIN MCPcmd,":"
HIGH 14 ' hard shutdown disabled
' LOW 11
' PAUSE 2000
HIGH 11
PAUSE 100
FOR i = 50 TO 250 STEP 25
MCPvalue = i
LOW 11
SHIFTOUT 13,12,MSBFIRST,[noparse][[/noparse]MCPword\16]
HIGH 11
DEBUG "i=",DEC i," ",BIN MCPword
PAUSE 5000
NEXT
MCPcmd = $ff
DEBUG "shutdown ",BIN MCPword," "
LOW 11
' PAUSE 50
SHIFTOUT 13,12,MSBFIRST,[noparse][[/noparse]MCPword\16]
' PAUSE 50
HIGH 11
PAUSE 2000
DEBUG " HARD DOWN "
LOW 14
DEBUG "end "
STOP
The first SHIFOUT leaves the wiper in the default power on configuration. The soft shutdown SHIFTOUT has no effect either. The HARD DOWN shutdown does shut the chip down.
Thanks for any help you can offer. My project really depends on a digital potentiometer and this 2 channel version is very appealing.
I suspect you want at least the first initialization of MCPcmd to look more like this:
MCPcmd = $00010011 or in datasheet notation XXC1C0XXP1P0 with C1C0 indicating the WRITE DATA function. As it stands now I suspect it's just a NOP (no operation).
Again, if the chip that you have reflects that it's Revision A you need to look at the errata datasheet on the Microchip web site. If you can't find it, send me a note, and I'll send it along to you. All of the problems described therein have to do with SHUTDOWN. If this is not the case, let me know and I'll look further into your program.
Regards,
Bruce Bates
bvbates @ usamailbox.com (remove spaces)
Bruce
So far we've only really spoken about the command byte. You ARE changing the data byte as appropriate, and setting the proper device designation (P1P0) in that command byte, aren't you?
Also, make sure that the device you have specified is the one you're checking on the ouput pins. Ergo, if you have specified device P0, make sure you are checking the P0 outputs. In fact, check both just to see if that's a problem. Is the PAUSE 5000 long enough on a BS2p for you to see the electrically changing output? Are the potentiometer output pins tied into a circuit, or are they floating?
Does the DEBUG output appear the way you expect it to look?
The data byte, although it may not reflect what you want it to, can't be "wrong" as all 256 bit combinations are valid (0-255).
I only wish I had one of these chips here so I could work along with you, but I don't.
Regards,
Bruce Bates