PDA

View Full Version : Digital Pot Delema



bennettdan
05-03-2006, 01:02 AM
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.

Chris Savage
05-03-2006, 01:32 AM
Attach the code you have. Perhaps there is a fix in that.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

bennettdan
05-03-2006, 01:40 AM
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!"
' -----[ 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
' -----[ 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
' -----[ 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 Savage
05-03-2006, 01:44 AM
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 (mailto:csavage@parallax.com)

bennettdan
05-03-2006, 01:54 AM
I actaully want to use a manual pot where the photoresistor is and very the AD5220 with it. Sorry about the code paste.

Chris Savage
05-03-2006, 02:01 AM
Is the POT the same value as the Photo Resistor? How do you have it connected?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

bennettdan
05-03-2006, 02:06 AM
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 Savage
05-03-2006, 02:15 AM
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 (mailto:csavage@parallax.com)

bennettdan
05-03-2006, 02:24 AM
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.

bennettdan
05-03-2006, 01:44 PM
Chris the + Threshold made my program not respond at all, any other suggestions to try?

Chris Savage
05-03-2006, 10:10 PM
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 (mailto:csavage@parallax.com)

bennettdan
05-03-2006, 11:05 PM
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 Savage
05-03-2006, 11:07 PM
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 (mailto:csavage@parallax.com)

bennettdan
05-03-2006, 11:44 PM
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 Savage
05-03-2006, 11:56 PM
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 (mailto:csavage@parallax.com)

bennettdan
05-04-2006, 12:12 AM
HTanks again for helping out a new guy micros...

Chris Savage
05-04-2006, 12:48 AM
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 (mailto:csavage@parallax.com)

bennettdan
05-04-2006, 01:10 AM
Hey Chris ..this code must hate me ...I downloaded the code and it does nothing.

bennettdan
05-04-2006, 01:12 AM
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?

bennettdan
05-04-2006, 02:09 PM
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 Savage
05-04-2006, 10:00 PM
Glad you got it working.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)