A servomotor is an electronic positioning system that can rotate a shaft over a fixed angle, typically in the range of 0 to 270 degrees, and then actively hold it there. Servomotors are used when a system needs to accurately position a mechanical assembly and hold it in place, even when external forces are trying to force the assembly out of position. “Hobby” servos, costing $10 or less, are standard systems used in many low-end applications, like steering motors for RC cars, control surface actuators for RC aircraft, and open/close or on/off operators for toys. At the other end of the spectrum, industrial servos can be very large, accurate and expensive, and are often used to control assembly line processes.
Several views of a hobby are shown below. Hobby servos include a rotating motor, a gearbox, and a closed-loop controller circuit packaged inside a small plastic housing. The gearbox increases torque and decreases rotational speed, and the controller rotates the motor to a fixed angle and holds it there. Servomotor position is set by a single PWM signal with particular characteristics: every 20ms, a 1ms-2ms pulse is sent to the servo to set the rotation angle.
A 1ms pulse drives the servo fully clockwise (typically 90+ degrees from center), a 2ms pulse drives the servo fully counterclockwise (typically 90+ degrees from center), and a 1.5ms pulse centers the servo. To change the servo position by 1 degree requires a PWM step size of 1ms/180, or about 5.5us. Thus, a PWM circuit that can generate pulses that vary in duration by about 5.5us can rotate the servo by N degrees, where N is the number of 5.5us incremental durations added to the PWM signal. Note that different servos may use slightly different pulse times, and may have slightly different maximum rotation angles.
A servo control signals uses a 2ms “pulse window” every 20ms so that multiple servos (up to 10) can be controlled using a single signal and time-division multiplexing.
The controller circuit inside the servo measures the pulse width, and then rotates the servo shaft accordingly and holds it there. A shaft encoder measures the shaft rotation angle, and feeds that back to the controller. If an external force tries to rotate the servo shaft from its assigned position, the controller adds current as needed to keep the servo at its assigned location.
A block diagram for a simple servo controller is shown below. A 180KHz clock has a period of 5.55us, (adequate to construct a PWM signal that will offer about 1 degree of rotational control), and that clock drives a counter. One comparator resets the counter every 20ms (a count value of 3600 equals 20ms) and sets the PWM pulse high, and a second comparator drives the pulse low when the input pulse data length is reached.