1 Introduction The following article is a compilation of information on how to control servo motors using various microcontrollers. The microcontrollers considered include the Parallax Basic Stamps, Marvin Green's BotBoard (Motorola HC11), the Motorola HC12 MCU, and the MIT Handy Board Microcontroller (Motorola HC11). Sample code for each controller is included for reference and testing. Have fun! 2 Servomotor Basics Servomotors, the same used in remoted controlled cars and planes (a good source for these motors is Tower Hobbies), have become a popular choice for hobby robotics enthusiasts in the past few years. Why? Simple. Each motor assembly comes complete with a gear box and control electronics that make interfacing them to microcontrollers a cinch. With the wide variety of available end attachments, it is easy to mount wheels and custom mechanisms to the motor (see Figure 1). In contrast to standard DC motors, a servomotor has three wires, power (usually +5V @200mA and capable of ~1A peak current), ground, and an input which accepts a pulse-width-modulated (PWM) signal controlling the servos position. Thus, a motor driver circuit or chip is not required unlike standard DC motors.
Figure 1. A basic servomotor with a circular end attachment for mounting wheels and mechanisms. Servos are active devices with on-board position feedback electronics allowing them to be commanded to a position, usually between 0 and 180 degrees. Being active, when commanded to a position, they will continuously try to minimize the error between the actual and commanded position. So, if an external disturbance tries to move it from its commanded position, the servo will try to maintain a position of zero error. Servomotors can deliver output torque between 20 to 100+ oz-inches! The PWM input signal that a servo requires is simply a square wave (0-5V) with the high time being variable as shown in Figure 2. One of the important characteristics of the PWM signal is that the repeat rate must be between 20-30mSecs (i.e., 50 times a second), otherwise the on-board electronics will ignore the signal or in some cases cause the motor to exhibit poor performance such as chattering and unpredictable movements. The pulse width, w, determines the command position, which varies from manufacturer to manufacturer, but the neutral position (90 degrees or so) is usually characterized by a 1.5uS pulse width. Thus, any source capable of supplying this PWM signal can control a servo, which means that microcontrollers are the best canidates for controlling servos because they can easily generate PWM signals. In addition, the pulse width can be controlled via software, making servos the ideal actuator to use in robotics in terms of locomotion and mechanism control. ![]() Although servos are easy to use and interface to microcontrollers, their limited range of motion can be useless for locomotion, unless they are used as joints in a legged robot. Wheeled robots require continuous rotation. Servos are not limited to only 180 degrees of travel, but can be modified to rotate continously by removing the position feedback circuit and any internal limits that may exist. After modification, the servo then thinks that its stuck as one position and as a command position is given to the motor, it tries to reach that position, but never making because there is no feedback. The motor then rotates continously until another command is given. The modified servo can rotate in both directions with adequate speed control based on the command position. For information on how to modify a servo motor for continous rotation, click here.Figure 2. Standard servo PWM signal characteristics. The repeat rate for the signal is approximately 20mSecs (i.e., 50 times a second) while the pulse width w can vary between manufacturers, but usually the netural position is approximately 1.5uSecs in width. With the basics of servomotors covered, it's now time to control them using different microcontrollers. The following sections assumes that you have some knowledge of programming and compiling the applicable code. But before I begin with the code hacking process, let's talk a bit about hacking a servomotor for continuous rotation, just in case you are planning on using these motors for robot locomotion, for example. 3 Hacking the Servo Motor for Continuous Rotation Servo motors fresh out of the package are not designed to rotation continuously (i.e., all the way around and around and around). Instead, they are limited to about 180 degrees of rotation. Follow the example in this artice Modifying the Tower Hobbies TS-53 Servomotor for Continuous Rotation if you plan on using the servomotor for locomotion purposes, otherwise keep the motor intact. I would recommend that you read this entire article before modifying anything! With that established, let's start with one of the most basic microcontrollers, the Basic Stamp. 4 Parallax Basic Stamp Microcontroller The Parallax Basic Stamp microcontroller is a small and inexpensive controller based on Microchip's PIC line. Parallax has made building projects and robots easy with their Pbasic programming language designed for the Stamps. Pbasic can be download from Parallax's website (http://www.parallaxinc.com) for free. To control a servo, the Pbasic function to use is pulsout. For example, to generate a repeating 20mSec signal on pin 0 with 1.5us pulse width, the following commands would be used: loop: pulsout 0, 150The function pulsout takes two inputs, the pin number and the number of 10-microsecond time units for generating the pulse. Thus, the output from the Pbasic instructions shown above would result in a PWM signal on pin 0 with a 1.5uSec pulse width. The pause 20 command produces the 20mSec separation between each pulse. Refer to the Parallax Basic Stamp manaul and application notes available at their website for more detail. 5 BotBoard (Motorola HC11) Microcontroller The BotBoard is a Motoral 68HC11 microcontroller based controller design by Marvin Green (refer to Marvin's website for more details about the BotBoard). The board is very simple to operate with four servomotor output jumpers connected to the HC11's timer ports. The assembly program below controls two servomotors connected to PA6 (J2) and PA5 (J3) of the BotBoard. Note, the program is only a slightly modified version of the program listed in Marvin Green's BotBoard Manual V1.03. Click here to download the assembly program or the pre-asssembled .S19 file. Use PCBUG11 to download the .S19 file into the BotBoard microcontroller. * SERVO_01.ASM6 Motorola HC12 Microcontroller The Motorola HC12 microcontroller is the bigger brother of the HC11. With an increased instruction set, more I/O pins, 16-bit data bus, and faster operating clock frequency (16Mhz compared to 8Mhz), the HC12 is a nice controller for robotics and applications alike. The HC12 is available in two models, the A4 and B32 version. The A4 contains 4KB of EEPROM, while the B32 version has 32KB of FLASH EEPROM in addition to some standard EEPROM. One disadvantage about the HC12 is it's only available in a surface mount package. Finding a good PCB to house the chip can be hard, but Kevin Ross of the Seattle Robotics Society has a very neat circuit board designed for both versions. Soldering the chip to Kevin's boards is a snap! The following program was written to test two servomotors connected to PORTT0 and PORTT1. The program was written for the HC12B32 version and can easily be modified to run on the A4 version (refer to the Motorola HC12A4 User's Manual). One thing to note. The program is assembled in the FLASH EEPROM of the B32 model, but can rewritten to be assembled in the EEPROM instead. Refer to the HC12B32 User's Manual. To download the assembly code, click here. You wil have to assemble it yourself. * SERVO_O2.ASM7 MIT Handy Board Microcontroller I don't have this or the bottom sections completed, so bare with me. If you really want to know how to interface a servo motor to the MIT Handy Board microcontroller, then check out its website! 7.1 With the Expansion Board Same as above. 8 Conclusion None yet. I'll finish this article later. 9 References Coming soon. Just you wait! 10 Contributed If you know how to control a servomotor using a microcontroller
NOT mentioned in this article and would like to share the information,
just let me know and I'll include it in this section with appropriate references
of course.
|