Whats a Servo Motor?
A servo is a small device that has an output shaft. This shaft can be positioned to specific angular positions by sending the servo code signal (PWM ). As a long as the coded signal exists on the input line, the servo will maintain the angular position of the practice, servos are used in radio controlled airplanes to position control surfaces like the elevators and rudders. The are also used in radio controlled cars, puppets and of course, robots.
So, how does a servo Work?
The servo motor has some control circuits and potentiometer (a variable resistor) that is connected to the output shaft. This potentiometer allows the control circuitry to monitor the current angle of the servo motor. If the angle is not correct, it will turn the motor the correct direction until the angle is correrct. The output shaft of the servo is capable of travelling somewhere around 180 degrees. Usually, its somewhere in the 210 degrees range, but it varies by manufacturer. A normal servo is used to control an angular motion of between 0 and 180 degrees. A normal servo is mechanically not capable of turning any farther due to a mechanical stop built on the main output gear.
The amout of power applied to the motor is proportional to the distance it needs to travel.So, if the shaft needs to turn a large distance, the motor will run at full speed. If it needs to turn only a small amount, the motor will run at a slower speed.This is called proportional control.
In the following e picture, the duration of the pulse dictates the angle of the output shaft (shown as the green circle with the arrow). Note that the times here are illustrative, and the actual timings depend on the motor manufacturer. The principle, however, is the same
Basically this project was made for the beginners , know how to control a servo motor with a PIC 16 familly.
For the project I use:
1) ISIS PROTEUS
2) microC PRO
3) PIC 16F887
4) SERVO MOTOR
1) Here you can see how the Hardware is connected, in the following picture.
2) Code in microC PRO
Here you can see the code. With this code, you can control the position in real time of the servo motor.The circuit has two push-Button, one for increment and other for decrement.
Now, you ask for yourself why i do not use the library available in microC PRo...Well because this library does not work at a low frequencies, and if you want control the servo motor you need generate low frequencies, frequencies around 50 Hz.So, how do this?.Simple, step by step.Take attention and try to comprehend the code:
CODE:
//function that generates a PWM pulse with a 20MHZ crystal
void Pwm_Sevo( float ang )
{
unsigned int n, max;
max = 1.61*ang;
PORTB.F0 = 1; //output high
delay_ms(1); //initial angle position
for( n=0; n<max; n++ ) //make time.With this cycle you make time and control the delay
delay_us(1);
PORTB.F0=0; //output low
delay_ms(15); // T=1/f <-> f=1/0.015=66Hz
}
void main( void )
{
float ANG=90; //Init angle
TRISB.F0 = 0; //output port0
OPTION_REG=0; // enable the pull-up resistor
while(1) //infinite loop
{
Pwm_Sevo(ANG); //goes to the function Pwm_Sevo( float ang ) and create the pwm pulse
//
//
if( PORTB.F6==0 ) //if you push the button F6
{
ANG-=10.0; //decrement angle.
if( ANG<0.0 )
ANG=0.0;
while( Button(&PORTB,6,5,0) );
}
if( PORTB.F7==0 )
{
ANG+=10.0;
if( ANG>180.0 )
ANG=180.0;
while( Button(&PORTB,7,5,0) );
}
}
}
So, now is easy create a small experience with servo motors and begin to think in build a robot , like a robot arm.


Man it works on proteus but it doesn't work on the pic.
ResponderExcluir