PIC12F675 Tutorial 6 : Driving a standard servo motor with a PIC

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.


servo-motor
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)
1.5ms zero position
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.

Solderless breadboard

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.

Circuit diagram

The servo is only needs a single control line from the 12F675 and an accurate timing source which is provided here by the internal 4MHz clock in the 12F675.

 

Servo Motor Software operation

 

The servo position is changed to different positions at one second intervals in the main routine. Just so you know where you are in the sequence the the zero position (1.5ms output) is held for a full two seconds while all the others are one second updates.

 

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

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter