lundi 12 février 2018

Controlling Servo Motor

controlling Servo Motor



hello again my friends 
today's topic is about controlling a servo moteur using a microprocessor.
as we all know the  microcontroller  PIC,  that's why we gonna make a code that show us how we can control a servo using  PIC
for that every one who wanna try it must have Proteus and mikroc pro for PIC (download link in the end of  article)



first what's a servo ? and how it works ?


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 controlsystem.


Servomotors are used in applications such as robotics, CNC machinery or automated manufacturing.(wikipedia)


code

void servoRotate0() //0 Degree
{
  unsigned int i;
  for(i=0;i<50;i++)
  {
    PORTB.F0 = 1;
    Delay_us(800);
    PORTB.F0 = 0;
    Delay_us(19200);
  }
}

void servoRotate90() //90 Degree
{
  unsigned int i;
  for(i=0;i<50;i++)
  {
    PORTB.F0 = 1;
    Delay_us(1500);
    PORTB.F0 = 0;
    Delay_us(18500);
  }
}

void servoRotate180() //180 Degree
{
  unsigned int i;
  for(i=0;i<50;i++)
  {
    PORTB.F0 = 1;
    Delay_us(2200);
    PORTB.F0 = 0;
    Delay_us(17800);
  }
}

void main()
{
  TRISB = 0; // PORTB as Ouput Port
  do
  {

    servoRotate90(); //90 Degree
    Delay_ms(2000);
    servoRotate0(); //0 Degree
    delay_ms(2000);
    servoRotate180(); //180 Degree
    Delay_ms(2000);
    servoRotate0(); //0 Degree
    delay_ms(2000);


  }while(1);
}


simulation 












Aucun commentaire:

Enregistrer un commentaire