|
Servo Motor |
Servo motors are very popular in the field of robotics .In this tutorial
i will show how to interface servo motor with microcontroller and i
will use pic18f2550 microcontroller .Basically servo motor works on
PWM(Pulse Width Modulation) signal .Basically PWM has a great uses to
create analog signal through microcontroller .
Look at the picture given below. We have to send PWM signal from 1millisecond to 2 millisecond to control the servo motor .
Listen here , carefully please .
* If we use less or equal to 1millisecond , the motor rotates 0 degree
* If we use 1.5millisecond or (1500 us) , the motor rotates to 90 degree
* If we use equal to 2millisecond , the motor rotates 180 degree
So if we like to rotate x degree , the solution becomes
=[{(1500-1000)/90}*x] us .I used this and it worked successfully . Now
look at the picture given below .
|
Servo Motor Rotation Controlling |
Now let's create a project on Proteus .If you are an expert you don't need to follow instructions.But beginner can follow these .
Proteus Circuit:
|
Create new project in proteus 8 |
|
How to find parts from Proteus |
|
How to find parts from Proteus Library |
Now complete the circuit as i have given below.
|
Servo Motor Interfacing With PIC Microcontroller ( PIC18F2550 ) in Proteus [step by step] |
Now look carefully at the picture given below.
|
Servo Motor Interfacing With PIC Microcontroller ( PIC18F2550 ) in Proteus [step by step] |
We have completed the circuit .Now let's create a Project in MikroC because we need a program to operate the microcontroller .
MikroC Code :
#Source Code :
1:
2: void main() {
3: int i=0;
4: CMCON = 0x07; // To turn off comparators
5: ADCON1 = 0x0F;
6: Trisc=0x00;
7: delay_ms(1000);
8: while(1){
9: /////// rotate to 0 degree
10: for(i=0;i<49;i++){
11: PORTC.F0=1;
12: delay_us(900);
13: PORTC.F0=0;
14: delay_us(1000);
15: }
16: delay_ms(4000); //delay for 4 sec
17: /////// rotate to 45 degree
18: for(i=0;i<49;i++)
19: PORTC.F0=1;
20: delay_us(1250);
21: PORTC.F0=0;
22: delay_us(1000);
23: }
24: delay_ms(4000);
25: /////// rotate to 90 degree
26: for(i=0;i<49;i++){
27: PORTC.F0=1;
28: delay_us(1500);
29: PORTC.F0=0;
30: delay_us(1000);
31: }
32: delay_ms(4000); //delay for 4 sec
33: /////// rotate to 1350 degree
34: for(i=0;i<49;i++)
35: {
36: PORTC.F0=1;
37: delay_us(1750);
38: PORTC.F0=0;
39: delay_us(1000);
40: }
41: delay_ms(4000); //delay for 4 sec
42: /////// rotate to 180 degree
43: for(i=0;i<49;i++)
44: {
45: PORTC.F0=1;
46: delay_us(2000);
47: PORTC.F0=0;
48: delay_us(900);
49: }
50: delay_ms(4000); //delay for 4 sec
51: }
52: }
Now run the MikroC project.
|
How to Create Hex file in mikroC |
Now go to the proteus circuit and load the .hex file to your microcontroller .If you don't know how , follow the instructions .
|
How to load source hex on microcontroller in proteus |
Now just run the project.
Result :
|
Servo Motor Interfacing With PIC Microcontroller Proteus Simulation
Just Click on '' SKIP ADD '' and You will get the download link
Thank You!
|