Servo motor driver tutorial. This tutorial uses the 12F675 microcontroller to drive a servo.
The microcontroller generates the signals to control a standard servo using Timer 0 interrupts (I used a Futaba servo). It does not do anything clever just sets the servo position to predefined positions at one second intervals.
A Timer 0 interrupt creates the 20ms timebase for servo updates using the internal clock and prescaler to accurately set the interrupt repeat rate.
Surprisingly servos are absolutely simple to control all the hard work is done for you (in the internals of the servo itself). All you need to do is generate a pulse signal repeated at every 20ms (approx).
You need to generate a pulse of the correct time as this determines the servo’s position. A pulse high signal of duration of 1.5ms sets the servo motor position to the center or zero degrees.
|Pulse width||Servo motor position|
|1.0ms||+45° (clockwise rotation)|
|2.0ms||-45° (anti clockwise)|
Note: These are the normal settings acceptable to most servo motors and the software is capable of going outside these ranges but you have to check that your servo is capable of doing this. If the servo hits the end stop then it is not capable and larger current will be drawn and the servo will eventually damage itself.
The circuit uses the same plugblock as before but most of the components are not used – all you really need is the ICSP connection and the servo connection, power supply and decoupling capacitors. The LM35DZ, LED and MAX232CPC are not used. If you have them already then leave them on as they can be used later.
Servo Motor Software operation
Servo Motor : Timer 0 interrupt
To get the 20ms repeat rate Timer 0 generates an interrupt at regular intervals. Timer 0 is driven (in this case) from the internal oscillator. This is further divided, inside the PIC, by 4 (Fosc/4). So the basic clock that Timer 0 (and prescaler) gets is 1MHz.
For more detail: PIC12F675 Tutorial 6 : Driving a standard servo motor with a PIC