Shop OBEX P1 Docs P2 Docs Learn Events
controlling servos — Parallax Forums

controlling servos

ObiwanObiwan Posts: 36
edited 2005-05-24 19:12 in Robotics
hi, im new at this.· i have a bsII and BOE board and im learning how to control servos.· do you use pulsout pin, variable.· If so , what does the variable mean.·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-23 18:24
    Hello,

    ·· What you should probably do·now is to download and read the "What's A Microcontroller?" text.· It will help you understand how to program the BASIC Stamp, and with some of your other questions.· It is free as a PDF download from our website.· A link has been posted below for your convenience.

    http://www.parallax.com/detail.asp?product_id=28123




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 5/24/2005 5:58:59 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-23 18:27
    The "variable" portion of the PULSOUT statement lets you use a variable value to generate the pulse.· For example, you can cause a servo to swing back and forth with this bit of code:

    pos··· VAR··· Word
    idx··· VAR··· Nib

    Setup:
    · LOW 15

    Main:
    · FOR pos = 500 TO 1000
    ··· FOR idx = 1 TO 5
    ····· PULSOUT 15, pos
    ····· PAUSE 20
    ··· NEXT
    · NEXT

    · FOR pos = 1000 TO·500
    ··· FOR idx = 1 TO 5
    ····· PULSOUT 15, pos
    ····· PAUSE 20
    ··· NEXT
    · NEXT

    · GOTO Main

    The outer loop (pos) sets the position of the servo.· On the BS2 PULSOUT uses units of 2 microseconds, hence a PULSOUT of 500 sends a 1000 microsecond (1 millisecond) pulse.· The inner loop (idx) simply slows the motion a bit -- make that loop bigger to make the servo move slower.

    Don't leave out the setup section; PULSOUT works by inverting the state of the specified pin.· Since the servo wants a high-going pulse we must start with the pin low.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • ObiwanObiwan Posts: 36
    edited 2005-05-24 17:49
    thanks for the help, that code really helped me understand the servos better.· another question i have is can i have two servos holding at their positions at the same time, with two different pins.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-24 18:39
    Yes; just use separate position variables for each and use two PULSOUT statements. Have a look at our Robotics text, it will show you how to control two servos at once.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Tricky NekroTricky Nekro Posts: 218
    edited 2005-05-24 19:12
    Of course If you want to have a faster count down you will have to use the STEP command... For exable:

    For pos = 1000 TO 500 STEP (the number you want)

    If the step number is 2 for exable the countdown time will be reduced to the half...cool.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rule your Destiny-
    --Be Good. Be Bad. Be Provas--
Sign In or Register to comment.