View Full Version : Servo to Pot problem

02-01-2007, 01:25 AM
Hey all,

I am working on a code that requires a pot to control a servo, so I went back to whats a microcontroller and started toying with the program on page 152. Here is my exact code

' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word
RCTIME 7, 1, time
time = time */ 185
time = time + 500
DEBUG ? time
PULSOUT 14, time

However, the servo goes back and forth without anything happening. I tried adujusting the time values on both ends and didn't get anywhere - after much toying I got the servo to move a little and then it started simply staying stationary once again and going back and forth in place.

Since this is modular to a bigger program I set up the schematics exactly as shown in WAM as a thought it would remove problems, however the same results occurred. (See pages 147 and 110 for schematics)

All connections have been checked and rechecked. The pot location has been checked several times (meaning the knob location has been repeatedly changed) and the pot itself was removed and reinserted. The servo connection is tight, the power is from a wall adapter and nothing is connected but an LED and the servo.

This started after checking the pot was double checked for connection.

Any ideas?

Post Edited (AIman) : 1/31/2007 6:30:12 PM GMT

02-01-2007, 01:37 AM
I'm not sure how 'repeatable' the RCTime command is. You might want to put in some code to average the last three readings to get a more stable value.

One other thing -- the Servo PULSOUT does need to be repeated every 20 mSecs -- I don't know if that is guaranteed by your current approach.

02-01-2007, 05:22 AM
What does the debug display? Is it consistent with the pot position and stable?

- Stephen

Beau Schwabe
02-01-2007, 06:47 AM
To get more 'repeatability' you can still use RC time, but modify your circuit to read BOTH sides of the POT. Take these values to create a percentage.

% = Value#1 * 100 / (Value#1 + Value#2)

Now that you have a·percent value that can be used as a common·denominator, you can apply the PULSOUT command

PulseWidth = ( (% from above) * 10 ) + 1000

This method will also compensate for any temperature drift.


With the attached image, Set I/O #2 to an·OUTPUT LOW and set I/O #3 to an INPUT.· Read the value of "R" using RCTIME (State Mode = 1) from I/O #1.
Next, Set I/O #2 to an·INPUT and set I/O #3 to an OUTPUT LOW.· Read the value of "R" using RCTIME (State Mode = 1) from I/O #1.· Use the two returned
values in the formula above.

Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 2/1/2007 7:22:01 AM GMT

02-01-2007, 12:01 PM
OK, I have rewritten, rewired, changed pins...

The times the problem occurs is ONLY when the values from WAM are adjusted to get the servo to move in a bigger arc. Once different values are entered to problem comes up again.


I will give it a shot, right now the servo moves about 20% of the available movment.

02-02-2007, 09:56 AM
Hi Beau,

I wonder if you could explain the difference between your three pin reading of a pot to control a servo and the two pin version in "stampworks" experiment 26 - page 146? What is the advantage of your technique?


Carlos Ferguson

Beau Schwabe
02-02-2007, 11:37 AM

Good question! Both circuits perform a ratio metric reading of the potentiometer. The main difference is that the above circuit uses only one capacitor. As a result any "would be differences" due to component tolerances and or mismatches are now completely negated. Using one capacitor directs any differences to the sensing element (the potentiometer). This includes any effects that are caused by ambient temperature.

Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

02-02-2007, 01:21 PM
Great, I had been looking for a solution like this to temperature drift! Thanks...

The code used to calculate the servo signal in these two methods is different as well. This is from the Stampworks example:

rcRt = (rcRt */ Scale) MAX 500 ' scale RCTIME to 0-500
rcLf = (rcLf */ Scale) MAX 500
sPos = (rcLf - rcRt) ' position (-500 to 500)
pWidth = (Center + sPos) ' finalize pulse width

Is there an advantage to your percentage approach? It seems like you would be stepping by 10 with your formula -
percentage*10+1000 - is this not a problem because it is a fine gradation?

thanks for your help,


Beau Schwabe
02-02-2007, 01:52 PM

There is nothing wrong with the method used in Stampworks. My use of percentage stems more from a programming style
that I tend to implement more than anything else. I generally take a modular programming approach and like to "encapsulate"
a function when I have something that works. Using a common denominator output such as percentage (0-100) makes
interfacing to another module easier and I don't have to "re-think" as much about what goes on inside the module if I decide
to use the same module for something else down the road.

Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

02-02-2007, 09:03 PM
thanks Beau, I really appreciate the help