Shop OBEX P1 Docs P2 Docs Learn Events
What is a Microcontroller: Servo question — Parallax Forums

What is a Microcontroller: Servo question

ToddHToddH Posts: 34
edited 2005-01-08 02:36 in Learn with BlocklyProp
(board of education Rev B - USB)

I'm going through the What is a Microcontroller text and have a question on Servos (chapter 2). The program on page 115 has 3 loops:

for counter = 1 to 150 ' Counter cclockwise 10 oclock
   pulsout 14, 1000
   pause 20
next

for counter = 1 to 150 ' clockwise 2 o'clock
   pulsout 14, 500
   pause 20
next

for counter = 1 to 150 ' center 12 o'clock
   pulsout 14, 750
   pause 20
next





I really don't understand why it moves and pauses the way it does.
1) do the number 1000, 500 and 750 ALWAYS mean 10, 2 and 12 o'clock?
2) the books says that the for..next loops control how long the servo stays in its position. Why doesn't it control how long it travels??
3) do servo's always start out counter clockwise?

If someone could give me a nickle tour on this "easy" concept it would be great!

Thanks much!

Comments

  • edited 2005-01-07 23:50
    1) Yes, so long as you deliver the pulses around 50 times per second. If you were to deliver a pulses with a 625 duration, that's half way between 12 o'clock and 2 o'clock, so you could reasonably expect the servo to hold the 1 o'clock position.

    2) Each time through the FOR...NEXT loop takes about 1/50 of a second. It actually takes a little longer because the PAUSE 20 stops everything for 20 ms, which is 20 thousandths of a second, which is 1/50 of a second. At any rate, if you deliver 50 pulses, that takes just over a second. 150 pulses will cause the servo to hold its position for a little over 3 seconds.

    3) Before the servo has power + pulses applied to it, its horn is wherever it happens to be. As soon as you apply power and the control signal (the series of pulses), that orders it to move to a particular position. If the control pulses are 750 (1.5 ms each), the servo will turn to 12 o'clock regardless of where it started.
  • ToddHToddH Posts: 34
    edited 2005-01-08 00:39
    I think I understand. Let me see if I can repeat it back...

    The duration of the PULSOUT is really like an exact position to go to. Kind of like a station on an analog radio tuner - 1090AM for instance. The loop is there to give the horn time to move to the desired position (or radio station in my example). As long as your loop counter is big enough to give the horn time to move to the desired position, all is well. If your loop is too short (say counter = 1 to 5), it wouldn't give the horn enough time to get to the desired destination and it would stop short of your desired location. If the counter is much larger than what it needs to get to the desired location, it really doesn't matter - the horn stops at the location you told it to move and it won't move again until you change the DURATION value of another PULSOUT command.

    I also guess that the pause of 20 is there to make the PULSOUT command run 50 times a second.

    Did I get it right?

    Thanks for the answer, BTW!
  • edited 2005-01-08 02:23
    You're getting closer. You're right about the PULSOUT command's duration selecting where in the servo's range it should turn to. It's also correct that it only takes a few pulses for the servo's horn to get to any given position.

    The thing about a servo is that it doesn't lock in place if you use a few (4 to 10) pulses just to make it rotate to that place. The servo lets go when those few pulses are done. When you stop sending those 50 pulses per second, you can grab the servo horn and turn it this way and that. If you keep sending the pulses, the servo will hold that position, even if you try to push it to a new position.

    Try this, run that program that makes the servo hold the three different positions for three seconds each. While it's doing its 3 seconds in each position, try to push the horn out of its position. Don't push hard, just nudge on the horn, and you should feel the servo resist. When the program ends, after it's done with 3 seconds at 12 o'clock, push on the servo horn again. You'll find that it turns fairly easily.

    Alright, now why does that matter? Why do we want a servo to turn to and hold a particular position? Consider radio controlled (RC) model airplanes, boats and cars. When you move one of the joysticks on the radio controller and hold it at a certain position, it sends a radio signal to the plane/boat/car, which in turn gets translated into pulses (just like the ones in your program) that make the servo turn to AND HOLD a particular position. The radio controller keeps sending the signal, and the servo keeps receiving pulses. So, it holds its position...until you move the joystick to another position.

    That's how the model airplane executes a turn, the servos have to move the flaps to various positions, and hold them there, for the duration of the turn. If it's a 3 second turn, the servos will receive around 150 pulses (of particular durations) to hold the flaps in the correct turning positions.

    The cool thing about writing a program to do the servo controlling is you can also program your BASIC Stamp to monitor sensors and make decisions during that 20 ms between pulses, and automate your model car, boat, airplane, or a custom robot.
  • ToddHToddH Posts: 34
    edited 2005-01-08 02:36
    Ahhh! (light bulb goes off) - Thanks much - now I understand why the looping structure. The loop isn't just to get the horn in the right position, but to keep it there for a desired amount of time.

    I wasn't thinking about forces trying to move the horn once I got it in the desired location. Your explaination makes perfect sense.

    Thanks again!
Sign In or Register to comment.