Shop OBEX P1 Docs P2 Docs Learn Events
Digital Potentiometer U/D pin. — Parallax Forums

Digital Potentiometer U/D pin.

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

  • Hi Keith,

    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.
  • kwinnkwinn Posts: 8,697
    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?

    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.
  • Genetix and Kwinn I appreciate both your ideas, and thanks for presenting them. The traditional guitar volume pedal has a potentiometer. If a potentiometer is used with RCTime, or if a quadrature encoder is used, we are simply back to turning something in a circle. Seems to me we would be back to the same mechanics of a traditional potentiometer guitar volume pedal, only making it more complex in doing the exact same task. Maybe there isn't a simple way to get the U/D pin of a digital potentiometer to be controlled in a analog way.
  • kwinnkwinn Posts: 8,697
    Genetix and Kwinn I appreciate both your ideas, and thanks for presenting them. The traditional guitar volume pedal has a potentiometer. If a potentiometer is used with RCTime, or if a quadrature encoder is used, we are simply back to turning something in a circle. Seems to me we would be back to the same mechanics of a traditional potentiometer guitar volume pedal, only making it more complex in doing the exact same task. Maybe there isn't a simple way to get the U/D pin of a digital potentiometer to be controlled in a analog way.

    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.
  • I second what kwinn said.

    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.
  • Interesting ideas kwinn, and Deuane. I think I have something totally different figured out. The main reason to not use a traditional potentiometer in audio is the quality of postentiometers today. They don't last, and start sounding scratchy in audio. You could use a voltage controlled amplifier to replace the potentiometer. To do it with a basic stamp, I may have found the solution. Look on page 277 of the "What's A Microcontroller"student guide version 2.2. There is code for operating a digital pot with a photoresistor. Yes, back to RCTime. If a LED light was shined on the photoresistor, and a gradient film strip--with a log taper--was put between the LED light and photoresistor---You would have a analog operation of a digital pot. Don't know if the number of taps in the digital pot 128 is enough to run an audio signal smooth enough. There are other questions, but I think I will try to bread board the project and see what happens.
  • The main reason to not use a traditional potentiometer in audio is the quality of postentiometers today. They don't last, and start sounding scratchy in audio.

    Yes, of course. You're right. I have the same trouble with pots inside servos. They also wear out.

    Good luck on your project.

  • I wrote the code example from pages 277,278 of the "What's A Microcontroller"student guide version 2.2. I built the circuit as pictured on 277. I ran the code, and it ran without any errors coming up. Nothing happened to the LED on the breadboard as I darkened the photo cell, or shined bright light on it. The LED is supposed to turn on or off in relation to light on the photo control cell. I got no LED light of any kind. To check for code mistakes I went over the code with a fine tooth comb, and everything was as written in the book. Plus I get "NO" error messages. To check for circuit mistakes, I ran the circuit, "without the photo resistor part of the circuit", using the code on pages 269-270. This code operated the sweep of the digital pot perfectly and made the LED bright to dim repeatedly. This meant the wiring on the main part of my bread board is correct. I then checked the photo resistor part of the circuit hooked to pin 2 of the microcontroller. The photo resistor part of the circuit was wired correctly. Ran everything again---shined light on the photo resistor---then dark on the photo resistor---the LED light on the bread board stayed dark. This means it is "NOT" working, or the LED light would work in relation to the photo resistor control. What can I do to make this work?
  • This is the place where we ask you to post the actual code and a clear photo of your circuit. Also, add a debug statement so you can see what the photocell is returning.
  • What's range of the resistance of the photoresistor? How many ohms when it's in the dark and how many ohms when there is light shining on it?

    There are lots of different values for photoresistors. It's possible the circuit or code needs to be altered to work with your photoresistor.
  • Tomcrawford where on Windows 10 do I click to transport my code file to here? I recently installed Windows 10 and everything is different.
    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.
  • I installed a 10K potentiometer in place of the photoresistor and it did not help. From everything I am seeing I think it is in the code.
  • Click on the "C" in the bar above, then copy and paste.
    
    I'm thinking the problem is with the photocell. You can prove it one way or the other by using debug to display what the photocell is returning.
  • Tomcrawford,thanks for trying to help. What "C", and what bar above what? I am going to run a debug program on the photocell separated. Meaning and RCTime code and see what I get.
  • Tomcrawford I ran a separate test on the RCTime part of the circuit and it worked in the debug display. The capacitor was a .01uf and the CDS photo resistor was 15K dark. The debug display after running the code was 00085 photo resistor dark, and 00001 real bright light on the photo resistor. As the bright light moved away I got all numbers in between. So the photo cell is working.
  • ' {$STAMP BS2}
    ' {$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
  • All parts of the circuit have been tested, so it has to be in the code, or it is not reading the values of RCTime. RCTime is working, and the numbers are from 00085 to 00001.
  • It appears there is a problem with this section of code:
    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
    

    You don't do anything after the first THEN statement. It should be:
    HIGH UdPin
    
  • Tomcrawford,thanks for trying to help. What "C", and what bar above what?

    This is the "C" Tom was referring to.

    CodeIcon.PNG

    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.
    269 x 176 - 13K
  • Sapphire your "nailed" it. The addition of the code you suggested made it work. It is not as accurate as it could be, because of ambient lighting issues, but it does work. The size of the capacitor also plays a role. I am wondering if a different type of sensor would make it work more reliably. Of course with RCTime there would have to be a variable resistance involved with any sensor, otherwise there wouldn't be a RCTime factor with the capacitor. I am wondering if a infrared photo transistor, or a Hall effect sensor might work somehow with RCTime. What if the sensor measured voltage change and that was put in the code where RCTime is now? Do you think that would work better? Ambient light is a problem with CDS photo resistors, because it often alters results.
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2016-07-10 16:46
    Sapphire nailed it. I'm surprised that compiled and more surprised to see a bug in Parallax sample code.

    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
  • tomcrawford. Yes, I looked and the version 3.0 book has the correct code. I guess the code mistake was in the old 2.2 version book I have. Don't forget that the digital potentiometer in this test was 10K, and that is about as large as they get. When you talk about scaling, the total resistance is extremely important. A guitar volume pedal normally has either a 250K or 500K potentiometer. So this circuit alone would not work as a guitar volume circuit.
  • Keith,

    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.
  • Genetix, the real issue with using digital potentiometers is designing around the largest ohm value you can get in them. 10K is the largest I have seen. I like what you said about the different capacitor values for RCTime that helps my thinking.
  • Genetix, wonderful information. These must have come out since I was hot working on digital pots back around 2004. Genetix, I have a thought provoking question. The above project involved using RCTime to get a analog change in the wiper of the digital pot. The resistance used in this example was variable because we use a Cds photo resistor. The change in resistance changed the time it took the capacitor to discharge. That was the basis of RCTime. In this situation as the resistance varied, so did the voltage. A change in voltage will change the rate a capacitor discharges, just like a change in resistance will. I do not understand why a different kind of sensor, besides a Cds cell could not be used. A infrared photo transistor will change the voltage depending on the infrared light shined on it. A Hall Effect sensor will change the voltage depending on the magnetic field's nearness. A capacitor's discharge depends on the voltage. Likewise a capacitor's discharge depends on resistance. So I can not understand why a variable voltage would not work for RCTime? I posed this question to one of the "support" people at Parallax, and he told me it would not work in RCTime, it had to be a resistor. I can not understand this, because the variable resistor changes voltage. I think the "support" person is wrong. What do you think Genetix. Might try it and see if it works for me, as you seem to know tricks with RCTime. Keith Hilton
  • Keith,

    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
Sign In or Register to comment.