Digital Pot Delema
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 Savage
Parallax Tech Support
csavage@parallax.com
' 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 Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com