Thursday 7 July 2011

Basic PIC Servo Motor

PIC Basic - Servo Motor Control Using PIC16F877A   PRO133
In this project we will explain how servo motors work and demonstrate two different types of servo motors in action, a full rotation and a partial rotation servo, using PIC16F877A microcontroller.
A motor, is a commonly used component in many gadgets that involve movement, it is used for linear motion, rotation (full/partial) or to and fro motions. There are different types of motors that are used in gadgets or robots to achieve these types of motions. Servo motor is used for controlled forward and backward motion or clockwise and anticlockwise rotation, particularly so when the torque (load) requirement is high. There are different types of servo motors available in the market; In this project we are only talking about simple servo motors that are used in hobby projects and experiments. Typically these motors can rotate -45 degree to +45 degree or -90 to + 90 degree or make full rotation clockwise or anticlockwise at controlled speeds. These are generally not precision motors, but can be easily programmed to position sensors, move objects forward or backward without depending heavily on feedback mechanism, once it is tuned.
Servo motors, typically comes with three wires. Two wires are designated for power supply and the third wire is for control. A Pulse Width Modulated (PWM) signal controls the position and direction of rotation of the motor spindle. You apply a few pulses of a certain pulse width through the control wire to position the spindle. The actual width of the pulse required is in the range of 1.0 to 2.0 milliseconds (this could vary depending on the brand and make of the motor). It is advised to figure out the exact pulse width range for a servo motor through experimentation (by applying various pulse widths and observing the behavior), if documentation for the motor is not available.
PMB-688 has six terminals, of which two of them are for power supply; as soon as you connect them to a supply (3V -5V) as LED start blinking indicating that it started working. You can interact with GPS using two protocols viz UART and RS232. Using both protocols you can configure the GPS to filter out certain type of messages. If no configuration is done the GPS will start sending out NMEA message in default settings. In this project we are using UART as this protocol and it is supported by 16F877A.

How does a servo motor work?

Partial Rotation Servos
Partial rotation Servos are controlled by sending them a sequence of pulses of different widths. Typically the pulse would repeat every 10-20 milliseconds (ms) and when the pulse width (duty cycle) is around 1.5 ms servo motor will return to the neutral position. The angle is determined by the duration of a pulse (pulse width) that is applied to the control wire. The servo expects to see a pulse every 10-20 ms. The length of the pulse will determine how far the motor turns. For example, a 1.5 ms pulse will make the motor turn to the 0 degree position (neutral position). 1 ms pulse width would move the motor to anti-clockwise direction by 90 degrees. Anything between 1 and 1.5 ms will rotate the motor anticlockwise direction proportionately. 2 ms pulse rotates the motor clockwise by 90 degrees.
When these servos are commanded to move they will move to the position and hold that position. If an external force pushes against the servo while the servo is holding a position, the servo will resist from moving out of that position. The maximum amount of force the servo can exert is the torque rating of the servo. Servos will not hold their position forever though; the position pulse must be repeated to instruct the servo to stay in position.
Full Rotation Servos
Full rotation servos (360 rotation servos) work similar to partial rotation servos. The main difference is it continuously rotates in clockwise or anticlockwise direction as long as the pulses are sent to the control wire. (Where as the partial rotation servo rotates to a certain degree and holds that positions.) If the pulse width is 1.5 ms it will stop rotating if it is less than 1.5 ms it will rotate in anticlockwise direction and more than 1.5 ms rotates in clockwise direction. In some motors the speed of rotation is dependent on the pulse width, i.e. how much more or less it is compared to 1.5 ms. As the pulse width gets closer to 1.5 ms the speed of rotation will be slower.
PIC Pulse Width Modulation (PWM)Or Compare Module?
Most of the commonly available PIC microcontrollers come with built in PWM module which can be easily configured to generate pulse of desired width or duty cycle on the CCPx pin. But these modules are not designed to produce low frequency (10-20 ms pulse length using 8MHz or higher clock) pulses. Hence the best alternative is to use the Compare module, which can be programmed (lightly) to pulses of low frequencies. See the code in the below section.
Schematic
Schematic is very simple as shown in the above diagram, using just one pin from th microcontroller for this demo.
Youtube Demo
Login to see tips, download datasheets and view code
Downloads
  1. Download the datasheet for PIC16F877A to get a good understanding of other details of the microcontroller.
  2. The compiled HEX file. (this can be directly burned into your PIC) click here
TIPS
  1. First step in getting a servo motor working is to ensure that the pulses generted by the PIC are in the range of 1 ms - 2 ms.
  2. Login for More...
Click to view PIC code
The C compiler used for this project is Hi-TECH light


LIST OF PARTS USED IN THE PROJECT
REFPART TYPEPART NAMEVALUECOUNTINFO
 Bat1BATTERYPACKBattery Pack 6V AA--1See Picture
 C1,C2CAPACITORCapacitor 100n100n2See Picture
 C3,C4CAPACITORCapacitor 27pF27pF2See Picture
 C5,C7ELECCAPACITORElectrolytic Capacitor 220uF220uF2See Picture
 C6ELECCAPACITORElectrolytic Capacitor 0.1uF0.1uF1See Picture
 Cr1CRYSTALCrystal 10.0 MHz10MHz1See Picture
 IC1ICPIC16F877APIC16877A1See Picture
 IC2ICIC LM78057805IC1See Picture
 PCBPCBPCB Gen Purpose DD 4x34x3inch1See Picture
 R1RESISTORResistor 10K10K1See Picture
 SMMOTORServo Motor 360360SM1See Picture

Approximate cost for building this project is Rs 1271.00

Note: In addition to the above components you may also require a breadboard and power supply / batteries for building this project.

Post a comment or question
Post Type:
Comment:
 Please login to post a comment or question 
Click here to login or register

No comments:

Post a Comment