Digital Potentiometer with Analog to Digital Converter
CraigR
Posts: 12
I am using an AD5220 digital potentiometer and want to display the position of the potentiometer's wiper at a given time (ADC position). I connected the potentiometer to a AD0831 analog to digital converter:
_________________________________________________________________________
counter VAR Word
ADCOutput VAR Word
Volts VAR Word
CS·············PIN···· 0······················ ' chip select
AData·········PIN···· 2······················ ' data pin
Clk············ PIN···· 1······················ ' clock pin
adcRes········VAR···· Byte················ ' ADC result
Setup:
· HIGH CS
Main:
DO
·
· LOW CS
· FOR counter = 0 TO 127
······ PULSOUT 5, 1
······ PAUSE 500
······ SHIFTIN AData, Clk, MSBPOST, [noparse][[/noparse]adcRes\9]
····· ·DEBUG "ADCRes is: ", DEC3 adcRes, CR
· NEXT
· HIGH CS····································
·····························
LOOP
_________________________________
The For loop is used to adjust the potentiometer from one end of its range to the other. When I run the program I get a single value of the wiper position·opposed to multiple values.·Inside the For loop I don't know which variable·associated with the SHIFTIN command·(i.e. AData, Clk, MSBPOST) can be replaced by "counter" to·display the value at each increment of the potentiometer wiper.
_________________________________________________________________________
counter VAR Word
ADCOutput VAR Word
Volts VAR Word
CS·············PIN···· 0······················ ' chip select
AData·········PIN···· 2······················ ' data pin
Clk············ PIN···· 1······················ ' clock pin
adcRes········VAR···· Byte················ ' ADC result
Setup:
· HIGH CS
Main:
DO
·
· LOW CS
· FOR counter = 0 TO 127
······ PULSOUT 5, 1
······ PAUSE 500
······ SHIFTIN AData, Clk, MSBPOST, [noparse][[/noparse]adcRes\9]
····· ·DEBUG "ADCRes is: ", DEC3 adcRes, CR
· NEXT
· HIGH CS····································
·····························
LOOP
_________________________________
The For loop is used to adjust the potentiometer from one end of its range to the other. When I run the program I get a single value of the wiper position·opposed to multiple values.·Inside the For loop I don't know which variable·associated with the SHIFTIN command·(i.e. AData, Clk, MSBPOST) can be replaced by "counter" to·display the value at each increment of the potentiometer wiper.
Comments
So to verify, you want to pull the reading from the ADC that is connected to the pot to get the value in which the ADC is connected to? Or do you want to display the number from 0 - 127 that the AD5220 uses to control the pot?
The value you that you will use·from the SHIFTIN command, is· [noparse][[/noparse] adcRes\9 ]; that is a 9 Byte array that brings in the values from the ADC. You can take that array and use it to display volts or similar values with the proper formatters as needed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com
Since you zero out he AD5220 in the beginning of your program, you could just reference counter as that will be the current location of the ADC that is being used.
For example:
FOR counter = 0 to 127
· PULSOUT PIN, 1
· PAUSE 10
· DEBUG DEC counter
NEXT
In this routine, you can DEBUG counter and it will give you the current location of the ADC. That should give you the location of your digital wiper, and as long as you use counter as your ADC control and increment and decrement accordingly then it should always be accurate positioning of the AD5220.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com