Shop OBEX P1 Docs P2 Docs Learn Events
Digital Pot Delema — Parallax Forums

Digital Pot Delema

bennettdanbennettdan Posts: 614
edited 2006-05-04 14:00 in BASIC Stamp
I am tring to write code that would sweep a AD5220 digital pot throght its steps with an output on the Basic Stamp that has a manual Pot on an input. I have some code but it drifts the wiper in the AD5220 no matter where I try to position it, say in the middle of the manual pot position the digital pot drifts all the way up and when I turn it very little all the way down I want it to just step a little at a time and then stay their. Any ideas would be great.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-02 17:32
    Attach the code you have.· Perhaps there is a fix in that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-02 17:40
    This is a photoresistor read project out of the WAM book that I am starting with but it drifts all the time.

    ' What's a Microcontroller - Ch9Prj01_PhotoControlledDigitalPot.bs2
    ' Update digital pot's tap based on photoresistor reading
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DEBUG "Program Running!"
    '
    [noparse][[/noparse] Declarations and Initialization]
    UdPin CON 5 ' Set values of I/O pins
    ClkPin CON 6 ' connected to CLK and U/D.
    PhotoPin CON 2 ' Photoresistor on pin P2
    DelayPulses CON 10 ' Delay to observe LED fade.
    DelayReader CON 2000
    counter VAR Byte ' Counter for FOR...NEXT.
    oldTapSetting VAR Byte ' Previous tap setting.
    newTapSetting VAR Byte ' New tap setting.
    lightReading VAR Word ' reading from photoresistor
    oldTapSetting = 0 ' Initialize new and old
    newTapSetting = 0 ' tap settings to zero.
    LOW UdPin ' Set U/D pin for Down.
    FOR counter = 0 TO 128 ' Set tap to lowest position.
    PULSOUT 6,5
    PAUSE 1
    NEXT
    '
    [noparse][[/noparse] Main Routine ]
    DO
    GOSUB Read_Photoresistor
    newTapSetting = lightReading
    GOSUB Set_Ud_Pin ' Set U/D pin for up/down.
    GOSUB Pulse_Clk_pin ' Deliver pulses.
    LOOP
    '
    [noparse][[/noparse] Subroutines ]
    Set_Ud_Pin: ' Examine old and new
    HIGH UdPin
    IF newTapSetting > oldTapSetting THEN ' tap values to decide
    ELSEIF newTapSetting < oldTapSetting THEN ' value of UdPin. Notify
    LOW UdPin ' user if values are
    ENDIF ' equal.
    RETURN
    Pulse_Clk_pin: ' Deliver pulses
    FOR counter = oldTapSetting TO newTapSetting ' from old to new
    PULSOUT ClkPin, 1 ' values.
    PAUSE DelayPulses
    NEXT
    oldTapSetting = newTapSetting ' Keep track of new and old
    RETURN ' tapSetting values.
    Read_Photoresistor:
    HIGH PhotoPin
    PAUSE 100
    RCTIME PhotoPin, 1, lightReading
    RETURN
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-02 17:44
    You should attach large blocks of code in the future...Pasting them like that makes it hard to do anything with and loses the formatting.· In any event that code is designed to read a photocell and adjust the brightness of an LED...Is that what you're trying to do?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-02 17:54
    I actaully want to use a manual pot where the photoresistor is and very the AD5220 with it. Sorry about the code paste.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-02 18:01
    Is the POT the same value as the Photo Resistor?· How do you have it connected?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-02 18:06
    Yes its a 10K pot connected the same way. The code works but it never lets me set the digital pot say in the middle it drifts one way or the other.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-02 18:15
    That's due to the way this code is written...It is incrementing the value for a high value and decrementing it for a lower value.· This is intentional.· There is also some drift in the readings from the RCTIME command due to component tolerances.· What you need to do is establish a threshold and have the two conditionals only bump the value when it exceeds the threshold.· For example...
    IF newTapSetting > oldTapSetting + threshold THEN ' tap values to decide
    
    ELSEIF newTapSetting < oldTapSetting - threshold THEN ' value of UdPin. Notify
    

    This will give you a dead-band where nothing will happen.· Call it a software-hysteresis.· The threshold value could be a constant, and should be small...Probably 1 or 2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-02 18:24
    Thanks for you help Chris, I have ran out of time to play today and I will try it out tonight when I get back in.
  • bennettdanbennettdan Posts: 614
    edited 2006-05-03 05:44
    Chris the + Threshold made my program not respond at all, any other suggestions to try?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-03 14:10
    That was a suggestion on how to alter the conditional...But in the code you posted above no action is being taken for either conditional...In the original code the values were altered at this poing and later the pulse routine was called.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-03 15:05
    With my scope it is pulsing the ClkPin all the time no mater how little I turn the manual pot. I have played with it to death trying to make it work but no luck. Is their a way to scale down what value I get with the manual pot and compare it to make a descision?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-03 15:07
    Perhaps you should attach the complete code you are using.· You didn't mention if you had the lines removed from the code you posted before, so I don't even know what your code looks like.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-03 15:44
    Here is the complete code but I think I would like to start over with something simpler. would a lookup table take up to much mempory to work for this application? I just want to be able to step throught the digital pots steps a pulse at a time. thanks for the help Chris.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-03 15:56
    It's as I suspected, you're missing parts of the code.· For example, in the conditional statements you're not incrementing or decrementing the oldTapSetting values so they're never changing.· It looks like something else may be missing so I will connect the circuit up and try it myself.· I will post back afterward.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-03 16:12
    HTanks again for helping out a new guy micros...
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-03 16:48
    ·· Okay, first of all here is what I am going to do...I looked over the code and realized there was a couple of lines missing from our printed code.· An errata sheet should be posted shortly on the web page for the WAM book.· In the meantime I am going to attach the corrected code.· This is the original code meant for the photoresistor.· Please try this, and I apologize for saying your were missing information since I was looking at the previous example in the book which had that.· Let me know if this works for you.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-05-03 17:10
    Hey Chris ..this code must hate me ...I downloaded the code and it does nothing.
  • bennettdanbennettdan Posts: 614
    edited 2006-05-03 17:12
    Hey I got it to work with a different cap but it only has a small change of light intensity should I try differnt caps or is their a way to scale this results?
  • bennettdanbennettdan Posts: 614
    edited 2006-05-04 06:09
    I have the code running with a 10k pot and .1uf cap it works good now but I had a problem it got to 127 steps very quickly so I scaled the lightReading to my Pot so I now have full range of my manual pot. I now want to be able to ramp up slow and ramp down fast so I will play with the code some more.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-04 14:00
    Glad you got it working.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.