Digital Potentiometer U/D pin.
Keith Hilton
Posts: 150
in BASIC Stamp
I have always wanted to use digital potentiometers, but incorporating them into a design has always been limited by the high low movement of the U/D pin. Push a volume button on the television and it gets louder, push another button on the television and there is less volume. What if there was no buttons? What if you were trying to control the volume of a guitar with a foot pedal? Two push buttons would not work on a guitar volume pedal. There has to be a way to make the U/D pin of a digital potentiometer analog. I brought this issue up a few years ago and everyone immediately came up with many reasons why the Basic Stamp could not accomplish making the movement of the wiper analog. That may be true by simply trying to run code. I am wondering how something mechanical could be made to move two buttons in an analog way. Another thought is hooking the U/D pin to a 5 volt off on device that can operate in a analog way. I am not wanting to eliminate the basic stamp in the digital potentiometer, I am just wanting analog control of the U/D pin. There has to be a way?
Comments
I would imagine that foot pedals are still analog in which case there should be a potentiometer that you can tap into.
You can measure it's value using a capacitor and RCTIME.
Look at the WAM experiment on Controlling a Servo with a Potentiometer to see how to convert a value using Scale and Offset.
I suggest using the Directive version since Constants are easier to change than the lines of code later in the program.
You will need to experiment with the capacitor, Scale, and Offset values that give you the performance that you want.
Two ways to do this. The first way is to add a quadrature encoder to the foot pedal so the basic stamp can read the pulses and adjust the volume accordingly.
The second method is to use the basic stamp rctime command to measure the position of the potentiometer in the foot pedal and use that to set the volume.
There's the big difference between digital and analog, so you need some sort of interface between the two. As for having "no simple way", it could be as simple as having a sub $1.00 microcontroller with a built in ADC and a bit of code to do the interfacing.
Why use a digital pot at all? It sounds like you want analog input so why not use a normal pot?
As kwinn points out, the alternative is to use a microcontroller to monitor the analog input and control the digital pot appropriately.
Another type of "digital pot" is a light dependent resistor (LDR). A LDR can be used with a microcontroller controlled LED to act as a sort of digital pot. Here's a YouTube example of this sort of interface.
Yes, of course. You're right. I have the same trouble with pots inside servos. They also wear out.
Good luck on your project.
There are lots of different values for photoresistors. It's possible the circuit or code needs to be altered to work with your photoresistor.
Duane, the range of the photoresistor seems to be from around 15K to 100 ohm with bright light.
I know the first part of the circuit without the photocell circuit is correct. The test on this part of the circuit worked. Don't know if the RCTime part is working--this is the photocell part. Also not sure if the code is working even though it shows no errors. The example in the book calls for a .01uf capacitor.
Did some testing with my digital logic probe and I am getting pulses to the photo resistor part of the circuit.
Pin #1 CLK of the digital potentiometer is getting pulses. The U/D pin 2 of the digital potentiometer is low meaning it is off.
' {$PBASIC 2.5}
'What's a Microcontroller - Ch9Prj01_PhotoControlledDigitalPot.bs2
'Update digital pot's tap based on photoresistor reading
DEBUG "Program Running!"
'
[Declarations and Initializations]
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
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
You don't do anything after the first THEN statement. It should be:
This is the "C" Tom was referring to.
I you press the "Quote" button in any of the replies with formatted code, you'll see the code tags.
You can either type of code tags manually or use the "C" icon to add the code tags automatically.
Here is a link to version 3.0 of that same book. On page 300, there is a similar program.
At least on iMac, the formatting bar is always available whenever you are entering text. Duane indicated which is the code button.
Edit: If the full range of what the phototransistor returns is 85 and there are 128 positions on the pot, you are going to have to do some scaling to get the full range on the pot. Hint: Take a look at the Multiply High and Multiply Middle operators. EndEdit
Your current RCTIME range is 1 to 85 using a 0.01 uF capacitor, correct?
Using a 0.1 uF capacitor should increase the range to about 850, since a 0.1 uF is 10X bigger than a 0.1 uF.
A 1 uF capacitor, which is 10X bigger than a 0.1 uF and 100X bigger than a 0.01 uF, should give you 8000 something.
The biggest value the BS2 can produce with RCTIME is 65535, so a 10 uF is too big.
There's also 2.2 uF, 3.3 uF, 4.7 uF, and 6.8 uF (50000 range), which are common sizes and should be easy to find.
Just beware that starting with 1 uF, you will find Aluminum Electrolytic capacitors are commonly used because of their cost, but remember that they are polarized and can explode if plugged in backwards.
Look for the "can" shape and double-check that the striped or Negative side ALWAYS goes to the Ground or lower voltage side of the circuit.
Might this do the trick?
http://www.jameco.com/z/27805-Parallax-Incremental-Rotary-Encoder_2123531.html
250K, 1024-Position, SPI
http://www.mouser.com/ProductDetail/Analog-Devices/AD5235BRUZ250/?qs=sGAEpiMZZMuD/7PTYBwKqdeb0s0H1yW0QECeB2bj3ik=
http://www.digikey.com/product-search/en?keywords=AD5235BRUZ250-ND
200K, 256-Position, Dual
http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?search_type=jamecoall&catalogId=10001&freeText=1778367&langId=-1&productId=1778367&storeId=10001&ddkey=http:StoreCatalogDrillDownView
http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?search_type=jamecoall&catalogId=10001&freeText=1778383&langId=-1&productId=1778383&storeId=10001&ddkey=http:StoreCatalogDrillDownView
100K, SPI, +/- 20%, Microchip
http://www.newark.com/microchip/mcp4141-104e-p/digital-potentiometer-100kohm/dp/77M2630
http://www.newark.com/microchip/mcp4161-104e-p/digital-potentiometer-100kohm/dp/77M2742
100K, I2C, +/- 1%, Analog Devices
http://www.newark.com/analog-devices/ad5272brmz-100/digital-potentiometer-100kohm/dp/76R7602
http://www.newark.com/analog-devices/ad5292bruz-100/digital-potentiometer-100kohm/dp/52R8118
RCTIME measures the time it takes for a capacitor to charge or discharge and reach the I/O pin threshold voltage, or the point where the input value will flip it's value.
This text has very good explanations of how RCTIME works.
http://www.digikey.com/en/pdf/p/parallax/applied-sensors-guide