Flight Control of a Plane

Click here to download  PROGRAMING , complete PROJECT REPORT + ppt. 


PROJECT REPORT

1. TITLE:
Controlling a servomotor using Pulse Width Modulation.

2. ABSTRACT:
Servo refers to an error sensing feedback control that is used to correct the performance of a system. Servomotor can be controlled using pulse width modulation (PWM). The pulse width determines the servomotor’s drive position.
We have used PIC 16F877A to generate PWM. The controller accepts an input from the keypad and generates the requested pulse. An LCD is used for displaying purpose. Generated PWM is subjected to the motor hence rotating it to the respective angle of that pulse. Rotation of the motor can also be done by entering desired angle.

3. BLOCK DIAGRAM:

4. OPERATION:

BLOCKS IN THE BLOCK DIAGRAM:

Ø  BLOCK A:

Keypad:
The input device is a standard 4x3-matrix keypad. It contains 12 keys, symmetrically arranged in four rows with three keys each. Each column i.e. 1, 2, 3 is receiving continuous pulses from I/O pins b5 b6 b7 of micro-controller respectively (Fig.2) and each row i.e. A, B, C, D is connected to I/O pins b1, b2, b3, b4 respectively of the controller (Fig.2).
            When a key of keypad is pressed, the signal of respective column is sent to the I/O pin of micro-controller attached to the respective row of keypad. When a pin of controller receives a pulse from a particular row, it checks that which column is high at that instant and then picks the respective value. It can be more clear by code (See Appendix.1).
The microcontroller continually scans the keypad. All column inputs have pull-down resistors so that the value of pulse doesn`t remain store in the respective I/O pin of the controller.



Ø  BLOCK B:
Microcontroller:
PIC16F877A is a microcontroller. A microcontroller is a small and low-cost computer built for dealing with specific tasks. This microcontroller is very useful and easy to set up because it doesn’t have any internal clock generator. So external oscillator crystal is used.
This microcontroller has five ports (Port A, B, C, D & E) this is the first advantage of this PIC. It has 40 pins, out of which 33 can be used as I/O. Port D is used for programming the LCD; Port B is used to get key from keypad, Port A and C is used to control RF modules, LEDs and detectors.
Crystal oscillator:
Standard frequency crystals - use these crystals to provide a clock input to your microcontroller. A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a very precise frequency. This frequency is commonly used to keep track of time (as in quartz wristwatches), to provide a stable clock signal for digital integrated circuits crystal.


Ø  BLOCK C:
LCD:
The display used in this design is a 2x16-character LCD with an integrated controller. This LCD (Liquid Crystal Display) Module is used to inform user with characters. In this project, 2 x 16 LCD module is used.
Ø  BLOCK D:
Servomotor:
The brain of the servo motor is the input pulse width. The pulse width determines the servomotor’s drive position. A servomotor only has three wires, usually red, black and white. Red and black are +ve and ground connections and white is the drive connection. Servomotor is used for controlled forward and backward motion or clockwise and anticlockwise rotation, particularly so when the torque (load) requirement is high. Typically, these motors can rotate -45 degree to +45 degree or -90 to + 90 degree or make full rotation clockwise or anticlockwise at controlled speeds. There are different types of servomotors available in the market; In this project, we are only talking about simple servomotors, which are being used in hobby projects and experiments. Servomotors, typically comes with three wires. Two wires are for power supply and the third wire is for control. A Pulse Width Modulated (PWM) signal controls the position and direction of rotation of the motor spindle.
Partial rotation Servos are controlled by sending them a sequence of pulses of different widths. Typically the pulse would repeat every 10-20 milliseconds (ms) and when the pulse width (duty cycle) is around 1.5 ms servomotor will return to the neutral position. The angle is determined by the duration of a pulse (pulse width) that is applied to the control wire. The servo expects to see a pulse every 10-20 ms. The length of the pulse will determine how far the motor turns. For example, a 1.5 ms pulse will make the motor turn to the 0-degree position (neutral position). One ms pulse width would move the motor to anti-clockwise direction by 90 degrees. Anything between 1 and 1.5 ms will rotate the motor anticlockwise direction proportionately. 2 ms pulse rotates the motor clockwise by 90 degrees.
This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width.  

http://www.elektroniksforkids.com/img/PRO133/pro133-photo-003.jpg
The Servo Motors come with three wires or leads. Two of these wires are to provide ground and positive supply to the servo DC motor. The third wire is for the control signal. These wires of a servomotor are color-coded. The red wire is the DC supply lead and must be connected to a DC voltage supply in the range of 4.8 V to 6V. The black wire is to provide ground. The third wire to provide control signal.

5. SIMULATION RESULTS:
Clock pulse circuit:
The servo is only needs a single control line from the controller and an accurate timing source, which is provided here by the internal 4MHz, clock i.e. a crystal oscillator. It is applied on the 13 and 14 pins of the controller.
Reset button:
To reset or to take a start from the mean position the push button is used which is connected to pin 1 i.e. master clear.
Motor Connection:
Motor is to pin 9 of controller, supply and ground.
6. EXPERIMENTAL RESULTS:

7. CONCLUSION:
Microcontrollers offer a simple and inexpensive solution for   controlling servomotors   for   robotics and other electronics projects. Using PWM, the angular position of the servo motor shaft can be conveniently controlled by a microcontroller for a variety of projects. PWM is an easy solution for the control of analog devices in other projects as well .Depending on the features included with the microcontroller you are using, a PWM signal can be generated in a variety of ways.

APPENDIX 1:



#include "C:\Users\Sanee Ahmed\Desktop\1st May, 2012\main.h"
#include <LCD.C>
#include <math.h>
int a,b,c,d;        // To assign values from keypad
int w,x,y;       // To store the value of each no. respectively
int16 k,l,m,n;   // To perform arithmetic operations
char o,p,q,r,s,t,u,v;   //For go to Statements
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   lcd_init();

   printf(lcd_putc,"   Bismillah    ");
delay_ms(1500);

//output_high(pin_b5);
printf(lcd_putc,"\fChoose I/P Style\n1-Pulse (ms)");
delay_ms(2500);
printf(lcd_putc,"\fChoose I/P Style\n2-Angle (Degree)");
delay_ms(2500);
printf(lcd_putc,"\f");
t:
printf(lcd_putc,"Please Enter\nYour Choice Now ");
//Work of Switch Conditions
w=64;
output_high(pin_b5);
   a=input(pin_b1);
   if(a==1)
  {w=1;}
output_low(pin_b5);

output_high(pin_b6);
   a=input(pin_b1);
output_low(pin_b6);
   if(a==1)
  {w=2;}
if (w!=64)
   {
//Work of Switch Statement
switch(w)

{
case 1:
printf(lcd_putc,"\fYou Have Choosed\nto Enter Pulse");
delay_ms(2500);
/////////Work of 1st Variable//////////
s:
{printf(lcd_putc,"\fEnter Desired\nPWM Value in ms");}

p:
w=64;
output_high(pin_b7);
   a=input(pin_b1);
   if(a==1)
  {w=3;}
b=input(pin_b2);
  if (b==1)
  {w=6;}
  c=input(pin_b3);
 if(c==1)
 { w=9;}
output_low(pin_b7);
 output_high(pin_b6);
   a=input(pin_b1);
   if(a==1)
  {w=2;}

b=input(pin_b2);
  if (b==1)
  {w=5;}
  c=input(pin_b3);
 if(c==1)
 { w=8;}
 d=input(pin_b4);
 if(d==1)
 {w=0;}

output_low(pin_b6);
output_high(pin_b5);
   a=input(pin_b1);
   if(a==1)
  {w=1;}

b=input(pin_b2);
  if (b==1)
  {w=4;}
  c=input(pin_b3);
 if(c==1)
 { w=7;}
output_low(pin_b5);
if (w!=64)
   {printf(lcd_putc,"\f%u",w);
   delay_ms(500);}
else { goto p;}

/////////Work of Point (Character)//////////

r:
y=64;
output_high(pin_b5);
a=input(pin_b4);
if(a==1)
  {y=3;}
  if (y==3)
   {printf(lcd_putc,"\f%u.",w);
   delay_ms(500);}
else { goto r;}

/////////Work of 2nd Variable//////////

q:
x=64;
output_high(pin_b7);
   a=input(pin_b1);
   if(a==1)
  {x=3;}
b=input(pin_b2);
  if (b==1)
  {x=6;}
  c=input(pin_b3);
 if(c==1)
 { x=9;}
output_low(pin_b7);
 output_high(pin_b6);
   a=input(pin_b1);
   if(a==1)
  {x=2;}

b=input(pin_b2);
  if (b==1)
  {x=5;}
  c=input(pin_b3);
 if(c==1)
 { x=8;}
 d=input(pin_b4);
 if(d==1)
 {x=0;}

output_low(pin_b6);
output_high(pin_b5);
   a=input(pin_b1);
   if(a==1)
  {x=1;}

b=input(pin_b2);
  if (b==1)
  {x=4;}
  c=input(pin_b3);
 if(c==1)
 { x=7;}
output_low(pin_b5);
if (x!=64)
   {printf(lcd_putc,"\f%u.%u ms" ,w,x);
   delay_ms(100);}
else { goto q;}     
////Work of PWM (1st Case)////

k=w*1000;
l=x*1000;
m=l/10;   
     n=k+m;
printf(lcd_putc,"\n    %Lu us    \f",n);
printf(lcd_putc,"\f%u.%u ms; %Lu us" ,w,x,n);
while(1)
     {
      output_low(pin_b5);
      output_low(pin_b6);
      output_high(pin_b7);
     
      output_high(pin_e1);
      delay_us(n);
      output_low(pin_e1);
      delay_us(20000-n);  
printf(lcd_putc,"\nPlease Press #  ");
      d=input(pin_b4);
      if (d==1)
      break;
   }
   goto s;
////Second Case of Switch Statement////
printf(lcd_putc,"\f%u.%u ms" ,w,x);
case 2:
printf(lcd_putc,"\fYou Have Choosed\nto Enter Angle");
delay_ms(2500);
/////////Work of 1st Variable of Second Case//////////

o:
printf(lcd_putc,"\fEnter your\nDesired Angle");
u:
w=64;
output_high(pin_b7);
   a=input(pin_b1);
   if(a==1)
  {w=3;}
b=input(pin_b2);
  if (b==1)
  {w=6;}
  c=input(pin_b3);
 if(c==1)
 { w=9;}
output_low(pin_b7);
 output_high(pin_b6);
   a=input(pin_b1);
   if(a==1)
  {w=2;}

b=input(pin_b2);
  if (b==1)
  {w=5;}
  c=input(pin_b3);
 if(c==1)
 { w=8;}
 d=input(pin_b4);
 if(d==1)
 {w=0;}
if (w==0)
output_low(pin_b6);
output_high(pin_b5);
   a=input(pin_b1);
   if(a==1)
  {w=1;}

b=input(pin_b2);
  if (b==1)
  {w=4;}
  c=input(pin_b3);
 if(c==1)
 { w=7;}
output_low(pin_b5);
if (w!=64)
   {printf(lcd_putc,"\f%u",w);
   delay_ms(500);}
else
{ goto u;}
/////////Work of 2nd Variable of Second Case//////////
if (w!=0)
{
v:
x=64;
output_high(pin_b7);
   a=input(pin_b1);
   if(a==1)
  {x=3;}
b=input(pin_b2);
  if (b==1)
  {x=6;}
  c=input(pin_b3);
 if(c==1)
 { x=9;}
output_low(pin_b7);
 output_high(pin_b6);
   a=input(pin_b1);
   if(a==1)
  {x=2;}

b=input(pin_b2);
  if (b==1)
  {x=5;}
  c=input(pin_b3);
 if(c==1)
 { x=8;}
 d=input(pin_b4);
 if(d==1)
 {x=0;}

output_low(pin_b6);
output_high(pin_b5);
   a=input(pin_b1);
   if(a==1)
  {x=1;}

b=input(pin_b2);
  if (b==1)
  {x=4;}
  c=input(pin_b3);
 if(c==1)
 { x=7;}
output_low(pin_b5);
if (x!=64)
   {
   printf(lcd_putc,"\f%u%u degree" ,w,x);
  }
else { goto v;}
/////////Work of -ve Angle//////////
if (w==4 && x==5)
{
printf(lcd_putc,"\fPress * to make\nangle -ve       ");
delay_ms(1500);
}
y=64;
output_high(pin_b5);
a=input(pin_b4);
if(a==1)
  {y=3;}
  if (y==3)
   {
   printf(lcd_putc,"\f-%u%u degree!" ,w,x);
   }
  else
  {printf(lcd_putc,"\f%u%u degree!" ,w,x);}
}
     else
   {printf(lcd_putc,"\f%u degree!" ,w);}
k=w*10;
l=k+x;
if (y==3 && l==45)
 { n=2000;}
else if (l==45)
 { n=1000;}
else if (l==90)
 { n=1500;}
else if (l==0)
 { n=600;}
while(1)
     {
      output_low(pin_b5);
      output_low(pin_b6);
      output_high(pin_b7);
     
      output_high(pin_e1);
      delay_us(n);
      output_low(pin_e1);
      delay_us(20000-n);  
     
printf(lcd_putc,"\nPlease Press #  ");
      d=input(pin_b4);
      if (d==1)
      break;
   }
   goto o;
   }
   }
else { goto t;}
}





No comments:

Post a Comment