Digipot updates very slowly
hvguy
Posts: 18
So I have a need for a bunch of digipots and decided to go with the AD5206. I had no problem getting it working, until I tried to change the pot value faster than once a second. Here's some code from what I'm working on:
HIGH 13
LOW 12
potvalue=0
potaddr=0
ZeroPots:
FOR potaddr = 0 TO 5
SHIFTOUT 14, 13, MSBFIRST, [potaddr\3, 0\8]
PULSOUT 12, 10
NEXT
This works fine and sets everything to zero. Now, I use this piece of code to change the pot value every time a button is pressed:
DO
IF IN1=1 AND potvalue<250 THEN
potvalue=potvalue + 10
SHIFTOUT 14, 13, MSBFIRST, [0\3, potvalue\8]
PULSOUT 12, 10
PAUSE 900
ENDIF
LOOP
Obviously every time the button is pressed the pot should increment by 10. So here's the strange part; with the PAUSE set to 900 the pot updates fine with every button press. If I set the PAUSE to be any smaller it will update two or three times then stop. I have verified that the BS2 is sending out the correct serial data every time with a scope, but it does not update the wiper position.
To put it another way, here is an example:
PAUSE is set to 200
button is pressed once, value increases by one step.
button is pressed again, it increases again.
button is held so that the code loops and value advances as predicted (watching scope and DEBUG) but real world pot value ceases to change after a few pulses.
If I wait about 5 seconds then press the button again. Now the value updates to whatever it should be after missing however many steps and continues to change for another few steps before doing the same thing again. If I set the PAUSE to 900 or higher the pot advances 10 steps per serial output pulse ever time the code loops. So why does it work fine slowed down so much but not at a reasonable speed? BTW, the DS says this pot has a setup time of something like 5ns, so I don't think I'm sending data too fast... plus this is a basic stamp, they aren't exactly fast devices :-)
I'm really stumped here anything would help, thanks!
HIGH 13
LOW 12
potvalue=0
potaddr=0
ZeroPots:
FOR potaddr = 0 TO 5
SHIFTOUT 14, 13, MSBFIRST, [potaddr\3, 0\8]
PULSOUT 12, 10
NEXT
This works fine and sets everything to zero. Now, I use this piece of code to change the pot value every time a button is pressed:
DO
IF IN1=1 AND potvalue<250 THEN
potvalue=potvalue + 10
SHIFTOUT 14, 13, MSBFIRST, [0\3, potvalue\8]
PULSOUT 12, 10
PAUSE 900
ENDIF
LOOP
Obviously every time the button is pressed the pot should increment by 10. So here's the strange part; with the PAUSE set to 900 the pot updates fine with every button press. If I set the PAUSE to be any smaller it will update two or three times then stop. I have verified that the BS2 is sending out the correct serial data every time with a scope, but it does not update the wiper position.
To put it another way, here is an example:
PAUSE is set to 200
button is pressed once, value increases by one step.
button is pressed again, it increases again.
button is held so that the code loops and value advances as predicted (watching scope and DEBUG) but real world pot value ceases to change after a few pulses.
If I wait about 5 seconds then press the button again. Now the value updates to whatever it should be after missing however many steps and continues to change for another few steps before doing the same thing again. If I set the PAUSE to 900 or higher the pot advances 10 steps per serial output pulse ever time the code loops. So why does it work fine slowed down so much but not at a reasonable speed? BTW, the DS says this pot has a setup time of something like 5ns, so I don't think I'm sending data too fast... plus this is a basic stamp, they aren't exactly fast devices :-)
I'm really stumped here anything would help, thanks!
Comments
The AD5206 has a "Chip Select" signal that must be brought LOW just be before shifting in the data, then must be brought HIGH to latch in the data.
Try changing your code to
LOW 12
SHIFTOUT 14, 13, MSBFIRST, [0\3, potvalue\8]
HIGH 12
And see if that helps.
Bean
@hvguy: What value resistor did you use on the SDO pin, and did you just connect the GND pin to VSS?
I tried the code as you recommended:
DO
IF IN1=1 AND potvalue<250 THEN
potvalue=potvalue + 10
LOW 12
SHIFTOUT 14, 13, MSBFIRST, [0\3, potvalue\8]
HIGH 12
PAUSE 100
ENDIF
LOOP
It still functions the same as before. Any other ideas?
velociostrich,
I tied Vss and GND. The AD5206 does not have the SDO pin, but I have the AD5204 as well and did use a 1K pull-up. You could use something much lager (100K) if you wanted to run high impedance logic...
How about this with debounce?
How about this on the 'scope, which should scan up and down rapidly:
First, this code works fine:
potnumber VAR nib
potvalue VAR byte
LOW 12
potnumber=0
potvalue=0
SHIFTOUT 14, 13, MSBFIRST, [potnumber\3, potvalue\8]
PULSOUT 12,1
pin 12 is pin 8 or CLK on the AD5206 and must be initialized LOW
pin 13 is pin 5 or CS on the AD5206
pin 14 is pin 7 or SDI on the AD5206
potnumber is 0-5 to address pots 1-6
potvalue is 0-255 for wiper position
The \8 is not technically necessary since the default number of bits is 8, but I left it there for the purpose of clarity. Another pot that uses more or less bits would need to have the number of bits defined by the \X.
Second, the pot does work with the GND pin floating, but only sometimes, so make sure all your jumpers are good :-)
Another interesting thing to note, especially for anyone referencing this after reading NV18 about the DS126x series pots, is that the AD520x loads data while CS is LOW. The DS126x series does it while RST is HIGH, even though both datasheets pinouts show the pin as active low.
Thanks for the feedback!