Shop OBEX P1 Docs P2 Docs Learn Events
ad5204 digital pot chip help with code please — Parallax Forums

ad5204 digital pot chip help with code please

staffshomestaffshome Posts: 28
edited 2009-10-23 18:19 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-22 13:48
    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 GreenMike Green Posts: 23,101
    edited 2009-10-22 14:02
    Typically you'd do something like:

    LOW potCS
    SHIFTOUT potData, potClk, MSBFIRST, [noparse][[/noparse]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
  • staffshomestaffshome Posts: 28
    edited 2009-10-22 18:41
    Hi Mike,

    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 Adrianconfused.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-22 19:17
    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.
  • staffshomestaffshome Posts: 28
    edited 2009-10-23 18:19
    Hi Mike,

    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.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.
Sign In or Register to comment.