Let's Make Robots!

Servos Unscrambled

A new way to play with servos
Aservo_9.jpg131.91 KB
Servos_Unscrambled_12.txt4.17 KB
ServosUnscrambled_31.jpg133.65 KB

Servos bring life to our ideas. Servos can be mysterious, but in fact they are very simple. Servos use a simple electronic pulse to tell them what angle you want them to go to. It is electronic not digital, but there are digital servos and they are different than standard servos. Pulses are electronic, but they are part of our digital world. Microseconds is us. Milliseconds is ms.

I am using a standard servo as an example.

A Servo                 1000us( 0 degrees)  ---- 1500us( 90 degrees) ---  2000us( 180 degrees)

                Range   Low ------------------------- 1000 ------------------------ High

Continuous Rotation Servos

                                Full Reverse                  Halt(90)                          Full Forward


                        Range = High – Low = 2000 – 1000 = 1000us

                        Range divided by servo max angle =

1000 / 180 = 5.5555 microseconds per degree(Mpd)

Servo Angle = (angle x Mpd) + Low

                                    (78 x 5.56) + 1000 = 1433.68us is close enough

                        Time = Servo Angle in us divided by Pulsout Unit

                                     time = 1434 / 5 = 287 (pulsout unit is 5)

                                          pulsout pin, 287 = 78 degrees on a servo


Servos use Microseconds(us) so that you have fine control over the angle you want the servo to go to. Microseconds are part of the language of microprocessors not people. Functions that deal with microseconds do so in the way they were programmed.

People get scrambled up because functions like pulsout do not work the way they think they should. Remember they are made for the system they are running on. Read your manual. Most pulsout functions are like this ‘pulsout pin, time’. Time is the number of microsecond in each unit that will make up the pulse not an actual time or angle.

Servos from their Radio Control heritage need a stream of pulses about every 20 milliseconds or so for about ten times of the same pulse to get them to recognize that it is the angle you want them to go to. In your program just set up a loop to send a train of pulses to the servo when you first set it to each new angle. After that you only need to re-fresh you servo about every 30-50 milliseconds or as needed by your servo.

Pulsout can be different on different processors in the same language because it is based on the Clock Speed of the processor and/or the processor. Also it can be different in different versions of the same language. Read your manual.

I think we should tell the companies to standardize functions like pulsout. It would make servos much more fun.

I keep a constant of my time value like 28x2_TIME = 5. I state the maker, processor, speed and language version in a comment just so I know what I am using. This can be a nasty bug in a program to find.

          unit = 5us

          Pulsout pin, 90 is acutely 5 x 90 = 450 NOT 90 degrees to a servo

          Time = unit divided into the servo angle in microseconds.

          Time = 1500 / unit = 300 is 300 hundred pulses of 5us each

          Pulsout pin, 300 equals a pulse of 1500 microseconds to the pin.

              A servo to 90 degrees.

You keep a servo at an angle by refreshing it. That is sending the same command to the servo up to every 20ms. The larger the load the more times per second you need to refresh the servo. For continuous rotation servos the speed is controlled by the refresh rate and the angle. Closer to 180 is faster forward. Closer to 0 is faster backwards. 90 degrees is halt. This is a very simple way to move a robot. Look at the BOE and Sumo Bots from Parallax.com. Servos move our ideas. Make something fun.

I am using a standard servo as an example.


Pulsout examples


       digitalWrite(outPin, HIGH); // sets the pin on

       delayMicroseconds( 1500 ); // pauses for 1500 microseconds (unsigned int)

       digitalWrite(outPin, LOW); // sets the pin off

      or Servo Library


      myservo.write(pos); //pos is 0-180 as an angle


Picaxe pulsout pin, time(0-65535)unsigned int

Clock Speed:        us per unit          0         90          180

     4MHz              10us                 100      150         200

    8MHz               5us X2 parts      200      300         400

    16MHz             2.5us                400       600        800

    32MHz             1.25us              800       1200      1600

     64MHz            0.625us            1600      2400      3200

Basic Stamps pulsout pin, time(0-65535) unsigned int

      Processor                    us per unit           0           90         180

      Basic Stamp One         10us                  100        150        200

      Basic Stamp Two          2us                   500         750      1000


BasicAtom pulsout pin, time(word)

Processor        us per unit           0           90           180

     BA             5us                     200       300          400

     BAN           12us                   84         125         167

     BAP           3us                    334        500          667

     BAP40        2.5us                  400       600         800

Pololu AVR Library Command Reference

              ::setServoTarget(unsigned char servoNum, unsigned int pos_us)

                  pos_us 400 – 2450 Servo angle in microseconds. 1500 = 90 degrees.

Remember to read your manual on your servos and the function you use to control them. I commend those who got walking robots walking using servos.

By Steven R. Cypherd

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This is just about standard servos where I know people have problems.

In your post you say that 1000uS is 0 degrees, 1500uS is 90 degrees and 2000uS is 180 degrees but that depends on the brand and make of the servo.

The servos I currently use work from 600uS to 2400uS which is convenient as this gives a resolution of 100uS for 10 degrees. The direction of rotation can change with different brands.

Why would you use the pulsout command with Picaxe when it has a servo command?

You say a servo's rate of refresh should be changed with load but not all servos will accept a variable refresh rate.


I've used the Pulsout command myself on the occasion that I am out of servo pins and need to hook up another servo. Pulsout seems to work on any output pins, where servo & servopos only work on certain ones.

Example taken from one of my working subroutines (servo is turning an IR rangefinder):

for b0 = 1 to 10
pulsout a.0, 240    ; 45 degrees to left of robot's center
                           ; (maximum = pulsout a.0,500  ; this is a 2.50ms pulse at 8 MHz. / high end-o-travel for this 9g servo)
pause 20
next b0                ; for-next loop give servo plenty of time to reach proper angle.


Note that I have the servo tied to pin A.0, which is normally used as an analog pin, but was free at the time.

Hey Dan:

When you say...

"Pulsout seems to work on any output pins, where servo & servopos only work on certain ones."

...Is this what you mean? "(Quote from Manual 2) On M2 and X2 parts the servo commands only function on portB (B.0 to B.7)" ...Or is it something else you have stumbled upon?



I answered this and it came up as a separate post, above. -Sorry.