Shop OBEX P1 Docs P2 Docs Learn Events
Servo horn + pulsout command — Parallax Forums

Servo horn + pulsout command

shmee.againshmee.again Posts: 5
edited 2007-01-10 01:37 in Learn with BlocklyProp
What's a Microcontroller? (pg 115+116)

the command is
(Pg. 115)

FOR counter = 1 TO 150
PULSOUT 14, 1000
PAUSE 20
NEXT

1.it says:
"the FOR...NEXT loop deliver 150 pulses each of which last 2.0 ms"

wouldnt this mean 150 * 2ms = 300 ms for all 150 pulses?

2.later in the gray box it says:
"PULSOUT 14, 1000 sends a pulse that lasts 1000 * 2 μs. Thats 2000 μs or 2 ms."

if each one lasts 2.0 ms like it says above you would multiply by 2 ms not 2 μs...

is it 1 or 2???

the book doesnt explain why you multiply it by 2 microseconds...why do you multiply it by 2 μs?

someone please just explain this whole thing to me...so lost...

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-11-07 05:14
    PULSOUT 14, 1 would send a pulse lasting 2uS. This is the shortest duration that they could achieve with the BASIC Stamp.

    So each PULSOUT value is 2uS

    PULSOUT 14, 1000

    would send a pulse lasting 1000 * 2uS = 2mS

    The FOR-NEXT loop sends that pulse 150 times. The servo wants a 20mS pause between each pulse, so there is a PAUSE 20 in there.

    So, total time would be roughly (2mS + 20mS) x 150, with a little added for prcoessing time.

    This help?

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    StampPlot - Graphical Data Acquisition and Control
    AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
  • Russ FergusonRuss Ferguson Posts: 206
    edited 2006-11-07 05:37
    It may be that a few comments about the PULSOUT command will help.

    In the example, the PULSOUT command will make PIN 14 go HIGH and then go back to LOW. The time that PIN 14 is HIGH is determined by the second number which is called the DURATION parameter. The DURATION parameter for the BS2 has a unit of 2 uS (not 1uS, and not 1mS).

    A PULSOUT DURATION value of 1000 will last for 1000 units of 2 uS.

    After the PULSOUT is performed by the BS2, PIN 14 will be LOW. It will be LOW while the BS2 performs the PAUSE 20. The unit of the PAUSE parameter is 1 mS, so the pause will last for 20 units of 1 mS.

    The LOOP will be repeated 150 times, causing a train of 150 separate pulses to be generated by the BS2.
  • shmee.againshmee.again Posts: 5
    edited 2006-11-08 03:25
    Thanks, martin that helps a bit but still some questions

    PULSOUT 14, 1 would send a pulse lasting 2uS. This is the shortest duration that they could achieve with the BASIC Stamp.
    So each PULSOUT value is 2uS
    PULSOUT 14, 1000
    would send a pulse lasting 1000 * 2uS = 2mS
    The FOR-NEXT loop sends that pulse 150 times. The servo wants a 20mS pause between each pulse, so there is a PAUSE 20 in there.
    So, total time would be roughly (2mS + 20mS) x 150, with a little added for prcoessing time.
    This help?
    -Martin


    OKAY. so each pulse is lasts (2uS*1000=) 2ms and is divided by 20ms, so for the counter, this occurs over and over 150 times...OKAY

    SOOOOOO:
    Why does the Servo prefer we use pulsout why cant we just use high and low commands instead??
    so what exactly is the PULSOUT value??
    if each pulse has a duration of 2000uS or 2mS then why dont we simply write PULSOUT 14, 2000,
    WHY do we multiply by 2 to get the pulsout duration??

    OFF TOPIC: whats the difference between Vdd Vin and Vss, dont think the book explains that...?? why do we use like a resistor instead of jumper wires, and that sort of thing, cause it would short out?
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-11-08 04:40
    The Servo "Control Signal" is a high-going pulse(low-high-low), from 1 mSec to 2 mSec wide, repeated every 20 mSec to 50 mSec. The Servo has internal electronics, which generates a pulse internally based on a variable resistor, which is connected to the output shaft. The servo activates the motor to turn it in a direction which eventually will cause the internal pulse to match the commanded pulse.

    So, each time the servo 'sees' the commanded pulse, it 'moves' the output shaft a little in the commanded direction. So it takes multiple 'views' of that signal to finish the move. And even after the servo gets to the commanded position, it still has to recieve that signal every 20 mSec if it's going to 'hold' that position.

    Now, a 'modified' servo (which is used for wheels) has disconnected the variable resistor from the output shaft, and the variable resistor is set at its 'center' position. Thus a 1.5 mSec pulse 'matches' the internal pulse, and the servo stops. More than 1.5 mSec spins one way, less than 1.5 mSec spins the other.

    Okay, so the input voltages. Vin is the 6 to 20 volt 'battery' or 'unregulated' voltage input. Vdd is the 'regulated' +5 volts -- output from either the 7805 Linear Regulator, the 3240-5 regulator, or the regulator on the BS2 module itself. Vss is 'ground', to which all the 'plus' voltages are referenced.

    We use the PULSOUT signal, because it's very accurate and has a 2 uSec resolution. Also, the smallest pulse you can generate with LOW-HIGH-LOW keywords is about 1 mSec and it's NOT very accurate. A LOW-HIGH-HIGH-LOW sequence would be about 2 mSec.
  • AImanAIman Posts: 531
    edited 2006-11-09 18:41
    Let me put a different light on this topic.

    When using pulse out with a servo you can increase and decrease the speed at which a servo moves. By using a shorter pause time you can actually get hobby servos to strip gears (not suggested). To decrease speed on the servo·increase· your pause time.

    DO NOT go less then 5 for pause time - even at 5 servos can strip out.

    Unless you need to move really fast, the times in the book are more then adaquate for most projects.

    Post Edited (AIman) : 11/9/2006 6:45:58 PM GMT
  • shmee.againshmee.again Posts: 5
    edited 2006-11-10 03:20
    ...Okay. understand now, thanks.

    to clear my mind up on this part:

    Vdd is 0-5 volts
    Vin is 6-20 volts
    Vss is 20+ volts?

    more (hehe):

    Resistors restrict the amount of electricity/signal going through the wire?
    Jumper cables sends the max volts the voltage inputs can put out?

    GRACIAS AS WE SAY IN L.A.!!
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-11-10 14:47
    In order to make a complete electrical circuit, the current travels out of the positive terminal of a voltage SOURCE, through the circuit, and into the GROUND lead, which is then tied to the negative terminal of a voltage source.

    In BS2 parlance, "Vss" IS the "Ground". So, technically (by definition) it's ALWAYS at zero volts, unless something very bad has happened.

    The 'resistor' equation is Ohms Law -- V == I * R, or I == V / R, or "The current (in Amps) through a Resistor (in Ohms) is equal to the Voltage Applied (in Volts) divided by the Resistor Value (in Ohms)". In typical electronics, the independent value is the Voltage, the Resistance is fixed (each resistor has its own resistance) and the Current changes as you change the Voltage.
  • shmee.againshmee.again Posts: 5
    edited 2006-11-10 17:34
    ooookayyy.
    so i understand vss and vdd, so what exactly is Vin or did i get that right as 6-20volts?
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-11-10 19:36
    "Vin" is a voltage input to a linear regulator. Yes, it is 6 to 20 volts -- the linear regulator takes that as input, and produces 5 volts on Vdd on the linear regulator's output. It turns out this is a Very Nice Thing To Do, as otherwise you'd always have to have an external 5-volt linear regulator device (like a 7805 or a 2830-5) in your circuit.

    With the on-module linear regulator, you can connect a 9-volt battery directly across the Vin (positive 9 volts) and Vss (the 'ground' wire) and have a running micro-controller.
  • shmee.againshmee.again Posts: 5
    edited 2006-11-11 03:05
    okay!

    i think thats all i can think of to ask for now, thanks a lot!
  • bgthreebgthree Posts: 14
    edited 2007-01-09 22:21
    I am resurrecting this thread because I have a related question.

    Here is the example program on page 115 of What's a Microcontroller:


    counter VAR Word

    DEBUG "counterclockwise 10 oclock", CR

    FOR counter = 1 TO 150
    PULSOUT 14, 1000
    PAUSE 20
    NEXT

    DEBUG "clockwise 2 oclock", CR

    FOR counter = 1 TO 150
    PULSOUT 14, 500
    PAUSE 20
    NEXT

    DEBUG "center 12 oclock", CR

    FOR counter = 1 TO 150
    PULSOUT 14, 750
    PAUSE 20
    NEXT

    DEBUG "all done"

    END

    What makes the Servo turn clockwise versus counterclockwise? I see no difference in the commands for the three movements except for the duration of the PULSOUT????

    Also, does this program actually make the servo horn move to the various clock positions? Or is it just making the Servo horn rotate through a given number of degrees, without regard to where the horn is "pointing"????

    Thanks for your help... I bought this book to learn about this stuff on my own, so I have no one to ask!
  • PARPAR Posts: 285
    edited 2007-01-09 23:10
    bgthree said...
    I am resurrecting this thread because I have a related question.
    Here is the example program on page 115 of What's a Microcontroller:


    counter VAR Word

    DEBUG "counterclockwise 10 oclock", CR

    FOR counter = 1 TO 150
    PULSOUT 14, 1000
    PAUSE 20
    NEXT

    DEBUG "clockwise 2 oclock", CR

    FOR counter = 1 TO 150
    PULSOUT 14, 500
    PAUSE 20
    NEXT

    DEBUG "center 12 oclock", CR

    FOR counter = 1 TO 150
    PULSOUT 14, 750
    PAUSE 20
    NEXT

    DEBUG "all done"

    END

    What makes the Servo turn clockwise versus counterclockwise? I see no difference in the commands for the three movements except for the duration of the PULSOUT????

    Also, does this program actually make the servo horn move to the various clock positions? Or is it just making the Servo horn rotate through a given number of degrees, without regard to where the horn is "pointing"????
    ...
    In brief, assume that "750" is the pulse length which "centers" the servo.

    Assume that shorter pulse lengths (<750)·cause the servo to turn clockwise, to some particular position.

    Assume that longer pulse lengths (>750)·cause the servo to turn counterclockwise, to some particular position.

    Assume that when the servo is positioned at "750", it is at its "12 o'clock" position.

    Then, setting the servo·with a specific shorter pulse value will cause the servo to position itself at that specific "clock" position. Ditto for a specific longer pulse value.

    The above refers to "standard" type servos, not to the modified "continuous rotation" type.

    For more detailed descriptions of how these servos are controlled by pulse lengths, you might look at Chapter 2· (ver 1.0) of Understanding Signals, http://www.parallax.com/dl/docs/prod/sic/Signals.pdf, and/or Chapter 2 (ver. 2.2) Robotics with the BOE-Bot, http://www.parallax.com/dl/docs/books/edu/Roboticsv2_2.pdf, esp. Activities #4 and #6.

    PAR
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-01-09 23:14
    Remember that since the servo horn can be taken off the shaft and repositioned almost any way the position of the horn is not relevant. What matters is the relative position of the shaft within its range of motion (slightly greater than 180 degrees). The difference you noted is exactly what moves the servo. The pulse width determines the position. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • bgthreebgthree Posts: 14
    edited 2007-01-09 23:28
    Thanks... I didn't realize that pulse duration corresponded to a fixed position. I was thinking "bigger duration = faster movement" but now I understand. Thanks!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-01-09 23:31
    Well, to a degree that is somewhat true on a continuous rotation (modified) servo. Values above and below 1.5mS will make the servo turn faster until it reaches its maximum speed. The curve is not linear and ramps up very quickly which means max speed is reached early in the curve. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • edited 2007-01-10 01:37
    Here is some Chapter 4, Activity #1 draft material for the next revision of What's a Microcontroller.·

    More about Standard Servo Control with the BASIC Stamp 2

    Please check it out, and post any questions you might have there so that we can make sure the subject is well covered.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
Sign In or Register to comment.