Table of Contents
Now DC servomotors are made to be simple to drive. They are meant to be a device that can just be dropped in. Unlike a normal DC motor which needs extra circuitry. They are made up of a DC motor with built in h bridges and even some feedback loops. This allows for them to be an easily run dc motor if it is continuous or a positional motor that can move to a desired angle. The nice thing about simple servomotors is that They usually come with three wires. One goes to power, one to ground, and the third one is the signal. The signal which controls the angle or direction and speed is run of a simple pwm signal. This makes them a quick and easy motor to get started with.
The first thing to look at with the servomotor is the datasheet. Now some will have more data than others, but the biggest thing you should see is the info on the pwm signal. The PWM signal of most servomotors are around a 21.5 ms period and about a 7% duty cycle. Which means it is on for about 1.5 ms and off for 20 ms. This is usually position 90 degrees or stop on a servomotor. Increasing the on time above 1.5 will move the servo closer to 180 degrees or move clockwise. The opposite direction moves to 0 degrees or counterclockwise. The extremes are usually around 2.25 ms and 0.75 ms. This will change depending on the servomotor. The other big thing is after writing your code, you will need to test for how accurate it is to the ms and may have to adjust it to get a correct zero.
Most microcontrollers have some timer that is setup to be able to create a pwm signal. If you are using an Arduino it is fairly easy to create the necessary signal using their IDE as shown here. Arduino has a built in servo library and a couple of example programs to get you started. Most microcontrollers don’t have that super of an easy setup, but in general a pwm signal is super short and easy code.
The LPC 812, for getting started with the LPC 812 go here, uses an SCTimer for its counter and pwm signal. This timer is a little more than most given that you are able to use different states. The other nice thing with this one is that you can use either a 32 bit timer or two 16 bit timers. It uses matches and events to curtail the signal. This allows you to easily make whatever signal you want and have preset changes based upon inputs. As seen in the code the big thing is setting up events and matches, once that is done it is easy to use. The big thing to make sure you do if you want to change one of the match values, is to use the reload variable. You can see the the output of the desired pwm signal on the oscilloscope picture below.
Another common one to find is a TMR timer for the pwm signal. This is a basic timer. To create the pwm signal you usually set a period and duty cycle more on this style of pwm can be found here the relevant code is shown below. For this example the parts that would need to be changed would be your period and duty cycle.
You can make a dummy one using a gpio pin and timing yourself. Now this is a brute force way, that is not very precise and has a lot of drawbacks. Since the signal isn’t running separately from the rest of the code any other function calls or code within will change the timer. This means that either you have to account for all that, or this can be the only thing the code does, which is not very useful. You can see on the oscilloscope output that you can make the pwm signal, but it takes a little bit of work to make it a correct one.
Servomotors are pretty easy to get going. They are probably the easiest electric motor to run. All that is necessary is a pwm signal. PWM signal generating is pretty common on most microcontrollers. This C code while not universal should be a good starting point atleast for your microcontroller. Driving servomotors is not rocket science, they are designed to be the easy to use.
By Ben R