# Servos Unscrambled

A new way to play with servos
AttachmentSize
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

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

## Comment viewing options

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

My article is about pulsout using a standard servo as a model.  Servos and their functions would require an encyclopedia to explain them. Pulsout is hard enough to use. The more people know the more fun they will have.

When you have an idea the article is the hardest part to write.

Thanks for the article. Take people's feedback as constructive critism.

I was busy writing my article and I did not think about all of the auto-formatting that I use in Word. My text file was a mess. Sorry. A good way of checking how your text file looks to others is to bring it up in notepad.

Your post keeps popping up as an update time and time again and I’m not able to see what has changed. Could you please mark the changes as –update—so it’s easy to find?

I updated a few words and typos’. I gave more information in the microseconds per degree calculation. I fixed some equations to make things connect like I use 5us in all of the examples. Please see if you see anything that is not right. Articles are tough.

I give you a brief idea on how I get good data out of my Sharp range finder. Pulse it yourself when you need to move your servo.

one little thing that i didn't find anywhere while trying to figure out why my servo only moved in one direction is the fact that the servo and the MC needs to have common ground.