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 but not digital. There are digital servos and they are different than standard servos. Pulses are electronic, but they are part of our digital world. The abbreviation for microseconds is “us”. The abbreviation for milliseconds is “ms”. See pictures below.

I am using a standard servo as an example.

Servo inputs use pulses measured in 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 called like this: pulsout pin, time. Time is the number of microseconds in each unit that will make up the pulse, not an actual time or angle. See pictures below.

Pulsout can be different on different processors in the same language because it is based on the clock speed of 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.

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.

I make 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.

For reading sensors like the Sharp rangefinders you should not use a servo command that constantly updates the servo position every 20 microseconds or so. Why? Because the sensor needs time to calculate the distance reading and to update its output. The servo needs to be steady to do this. Once you get good data from the sensor then you can move the servo. Try it. Use the pulsout command to move the servo to the next scan point. Then give about 20-50 microseconds pause for the sensor to update its output and then read the sensor. You should get good data this way. Digital and analogue rangefinders use the same method for reading distance and only differ in how you read the device.

See table below.

Project Steps

A servo using a standarc servo as an exampl.

Conclusion

Servos are fun!