Shop OBEX P1 Docs P2 Docs Learn Events
Servo to Pot problem — Parallax Forums

Servo to Pot problem

AImanAIman Posts: 531
edited 2007-02-02 14:03 in BASIC Stamp
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
DO
  HIGH 7
  PAUSE 10
  RCTIME 7, 1, time
  time = time */ 185
  time = time + 500
  DEBUG ? time
  PULSOUT 14, time
LOOP

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

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-31 18:37
    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.
  • FranklinFranklin Posts: 4,747
    edited 2007-01-31 22:22
    What does the debug display? Is it consistent with the pot position and stable?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2007-01-31 23:47
    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.

    Edit:

    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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 2/1/2007 7:22:01 AM GMT
    485 x 255 - 37K
    RC.JPG 36.5K
  • AImanAIman Posts: 531
    edited 2007-02-01 05:01
    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.



    Beau,

    I will give it a shot, right now the servo moves about 20% of the available movment.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-02 02:56
    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?

    Thanks,

    Carlos Ferguson
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2007-02-02 04:37
    jcferguson,

    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

    IC Layout Engineer
    Parallax, Inc.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-02 06:21
    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,

    Carlos
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2007-02-02 06:52
    jcferguson,

    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

    IC Layout Engineer
    Parallax, Inc.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-02 14:03
    thanks Beau, I really appreciate the help

    Carlos
Sign In or Register to comment.