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.
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.
No comments:
Post a Comment