PDA

View Full Version : ad5204 digital pot chip help with code please



staffshome
10-22-2009, 03:35 PM
hi all
i am trying to use a ad5204 digi pot chip with spi·to bs2p & im not getting very far with code,can anyone help with some code to start me off.
have attached datasheets, interfacing info on page 15

regards adrian

Mike Green
10-22-2009, 09:48 PM
There are plenty of examples of SPI code in the Nuts and Volts Columns that you can get to off the "Downloads and Press" link when you click on the "Resources" tab on the main Parallax webpage.

Basically, you use the SHIFTOUT statement to transfer the data to the AD5204. Again, look at the examples for other devices and the description of SHIFTOUT in the Stamp Manual or Stamp Editor Help Files.

Mike Green
10-22-2009, 10:02 PM
Typically you'd do something like:

LOW potCS
SHIFTOUT potData, potClk, MSBFIRST, [potNumber\3, potValue]
HIGH potCS

potCS is the chip select pin
potData is the data in pin of the chip
potClk is the clock pin which should be initialized HIGH
potNumber is the number of the pot (0 - 3 or 0 - 5 depending on the chip used)
potValue is the 8-bit setting of the pot

staffshome
10-23-2009, 02:41 AM
Hi Mike,

http://forums.parallax.com/images/smilies/smile.gif thanks for sample code,that's how i thought it should be,similar to max7219 im using already.

as you may have guessed i'm not very good at this programming stuff,1st attempt & probably my·only attempt.

only trying my hand after being let down by two so called professional programmers,but thats another story.

im just a bit confused as to data format for the 11bits.

as far a i can tell from datasheet,i send 1st 3 bits to sellect pot to address & them send 8data bits,does this mean i send· 000 (pot1) / 64 (1/4 pot position or do i need to send 8bits for (64)?

sorry for such basic questions but clueless really.

I have read thestamp app no18 august 96 "need analog output from stamp" app uses· ds1267 digi pot & i think i just confused myself even more !!

regards Adrianhttp://forums.parallax.com/images/smilies/confused.gif

Mike Green
10-23-2009, 03:17 AM
What I wrote will send 3 bits for the pot address (0 for your example) followed by 8 bits for the pot value (64 for your example). The default number of bits for a numeric value would be 8. If you want to be clear, you could write "potNumber\3, potValue\8" or use whatever you want for potNumber and potValue.

staffshome
10-24-2009, 02:19 AM
Hi Mike,

http://forums.parallax.com/images/smilies/smile.gif·I cannot thank you enough,for some reason the penny has now dropped re spi interfacing,must have been your example & explanation.

put pot device code in my app & all works fine,except i forgot that i need 2·pots ramping·simultaneously for 3rd gear, oop's.http://forums.parallax.com/images/smilies/blush.gif . i may be able to get away with 1 @ 100% & the other ramping up, will have to see if it will work on the·test rig !!!



Thanks again for your superb help.