Professional Documents
Culture Documents
Components:
Breadboard
LED
Resistors kit.
Capacitors Kit.
Jumper Wires Pack.
LM7805 Voltage Regulator (5v).
Crystal Oscillator.
PICkit2 or 3 Programmer.
9v Battery or DC Power Supply
Software:
MPLABX IDE
Proteus
Introduction:
. Servo Motor .
A servomotor is a rotary actuator or linear actuator that allows for precise control of
angular or linear position, velocity and acceleration. It consists of a suitable motor
coupled to a sensor for position feedback. It also requires a relatively sophisticated
controller, often a dedicated module designed specifically for use with servomotors.
Servomotors are not a specific class of motor, although the term servomotor is often used
to refer to a motor suitable for use in a closed-loop control system.
2. AC Servo Motor:
This motor includes encoder which is used with controllers for giving closed loop control and
also feedback. This motor can be employed to high accuracy and also controlled exactly as
required for the applications. Often these motors have advanced designs of easiness or better
bearings and some simple designs also use higher voltages in order to achieve greater torque.
AC motor applications, mainly involve in robotics, automation, CNC machinery, etc.
An exclusive design of this motor is suggested in controlling applications like the robotics.
Basically, they are used to change the speed control at high torques and correct positioning.
The required parts for this motor are highly developed controller and motor position
sensor.These motors can be classified according the motor controlled by servomechanism.
Which in turn changes the reference voltage and the control circuitry steers the motor in the right
direction until it reaches the exact required angle position and it keeps holding it while the PWM
signal is not changing. The range for the PWM pulse width for my servo motors (MG90S) is
0.6ms to 2.4ms for angular motion from 0° to 180°. And that’s what we’ll be using.
Note That:
0.6ms of 20ms period is a 3% duty cycle (0deg position)
1.4ms of 20ms period is a 7% duty cycle (90deg position)
2.4ms of 20ms period is a 12% duty cycle (180deg position)
50 = 48000000 / 4 x 4 x (65536-TMR1)
Now, it’s time to figure out how to get the desired duty cycle as well. The duty cycle in order to
be in the range of 3% up to 12% for a full range rotation (0° up to 180°), we need to write the
convenient data to the CCPR1 register pair.
By simple calculations & mapping, it turns out that the CCPR1 values which correspond to duty
cycle ranging from 3% up to 12% falls within the range (7335 for 3% DC up to 12735 for 12%
DC). And any value in between can be easily found by mapping.
Code:
#include <xc.h>
#include "config.h"
#include <stdint.h>
#include "Servo.h"
uint16_t AD_RES;
void ADC_Init();
void main(void) {
ADC_Init();
Servo_Init();
while(1)
{
}
return;
if(TMR1IF)
{
AD_RES = (ADRESH<<2)+(ADRESL>>6);
CCP1CON = 0x00;
PWM1 = 1;
CCP1CON = 0x09;
TMR1IF = 0;
GO_nDONE = 1;
}
void ADC_Init()
ADRESH=0;
ADRESL=0;
__delay_us(30);
GO_nDONE = 1;
Hardware:
Conclusion:
The purpose of this lab is to learn about the angle of a servo motor with pic16f877a, To control
the working of a servo motor when interfaced with PIC16F877A microcontroller. It has a very
simple circuit diagram. The control wire of the servo motor is directly connected to the RB0 pin
of the microcontroller. This pin will provide the required angular displacement of the motor. A
microcontroller generates a PWM signal using a timer, and subsequent configurations can be
modified to rotate the arm of a servo, a specific class of motor often used to create closed-loop
control systems in industrial robots, CNC machinery, and automated manufacturing, We
successfully implemented our code onto MP-lab for the for angle control of servomotor.
.END.