loading
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 for this 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

Arduino 
               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
I just updated the text a little. I had to update my main picture to give some of the missing numbers and where they came from.
Thanks to other geeks I fixed things and added a bit more information,

About This Instructable

6,061views

26favorites

License:

Bio: I have always been a geek and I see things differently than most people. I am healthy too and I love biology. Programming has always ... More »
More by Geek07Boy:Fun Led Checker Tester Flying a toy QuadCopter Servo Math 
Add instructable to: