Here you see how a Servo motor controls by Microcontroller PIC16f877 and MATLAB GUI? It is well known to us that now a day’s use of servo motor extended in the field of Robotics. Servo motor can rotate with definite angle and we can easily use it in design of robot arm movements. And also it can use extendedly in Remote-car and Helicopters. Now in my project “Servo motor control by Microcontroller PIC16f877 and MATLAB GUI” I will show you how a servo motor is rotate with 15° interval and also control by MATLAB GUI and also show you how it simulate in Proteus with help of MATLAB GUI.

Software required for PROJECT:

1)      Mikro C Pro for PIC  ( For write C Program and generate HEX file)

2)      Proteus ISIS               (For simulate the project)

3)      MATLAB                      ( For making GUI and Controlling the motor rotation)

4)      Virtual Serial Port Emulator. ( to making virtual com port and pairing them)

Servo motor Control: We can control a rotation of Servo motor by PWM (Pulse Width Modulation) technique. Only changing the duty cycle of a pulse signal we can vary the rotation of servo motor with specific angle. Using Mikro C Pro we can easy sets PWM duty ratio for PIC Microcontroller. Parameter duty takes values from 0 to 255, where 0 is 0%, 127 is 50%, and 255 is 100% duty ratio. Other specific values for duty ratio can be calculated as (Percent*255)/100.

In my project setting the specific value of Duty ratio to obtain specific angle in bellow I give you the table of specific Duty ratio Vs. Specific Angle.

Duty ratio Angle in Degree
0 0
21 15
42 30
63 45
83 60
103 75
125 90
145 105
165 120
187 135
207 150
228 165
255 180

 Circuit Diagram in Proteus: See the circuit diagram of Servo motor control by Microcontroller PIC16f877 and MATLAB GUI in bellow and see in figure that we feed input to servo motor from CCP1/Rc2 pin of Pic16f877. This CCP1 pin is used for PWM 1 so we have to take input from that pin only.

Servo motor control by Microcontroller PIC16f877 and MATLAB GUI

How to make MATLAB GUI: It is better to see the video of the process to How to make MATLAB GUI rather written the steps for that. See the bellow video.

 

C code for the project Servo motor control by Microcontroller PIC16f877 and MATLAB GUI:

For Write C code we have to know some command for initializing PWM unit and UART unit because we connect Matlab with proteus through UART port.

To interfacing UART with Pic we have to use some new command those are

UART1_Init (Baudrate): is Initialize UART module at specified baudrate.

 UART1_Data_Ready (): use to check data is receive or not.

 UART1_Write_Text(“Start”): use to write declared text on uart

 UART1_Write(): use for transmit uart data.

 UART1_Read(): use for read the uart data.

To interfacing PWM with Pic we have to use some new command those are

PWM1_Init(500): is Initialize PWM module at specified frequency.

PWM1_Set_Duty(i): use to set duty Ratio of PWM.

 


See the Code

Embedded C Code
// Name : Interfacing GSM module with PIC Microcontroller
// Purpose : STo send SMS from PIC Microcontroller.
// Author : Subham Dutta
// Date : 03-01-14
// Website : www.nbcafe.in

 unsigned int uart_rd;

 main(){

int i;

  PWM1_Init(500);

 UART1_Init(9600);               // Initialize UART module at 9600 bps

  Delay_ms(100);                  // Wait for UART module to stabilize

 while (1) {                     // Endless loop

    if (UART1_Data_Ready()) {     // If data is received,

      uart_rd = UART1_Read();

      UART1_Write(uart_rd);

      }

if (uart_rd == ‘a’){

      i=21;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

      if (uart_rd == ‘b’){

      i=42;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

      if (uart_rd == ‘c’){

      i=63;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

      if (uart_rd == ‘d’){

      i=83;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

      if (uart_rd == ‘e’){

      i=103;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

      if (uart_rd == ‘f’){

      i=125;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

        if (uart_rd == ‘g’){

      i=145;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

        if (uart_rd == ‘h’){

      i=165;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

        if (uart_rd == ‘i’){

      i=187;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

        if (uart_rd == ‘j’){

      i=207;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

        if (uart_rd == ‘k’){

      i=228;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

         if (uart_rd == ‘l’){

      i=255;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

 

      if (uart_rd == ‘m’){

      i=0;

      PWM1_Set_Duty(i);

PWM1_Start();

      }

}

 }

Simulation : To see the simulation of Servo motor control by Microcontroller PIC16f877 and MATLAB GUI must see the bellow video hope it will help you lots.