Pulse Width Modulation Using PIC16F877A

THEORY

Pulse width modulation (PWM) is a method of controlling the amount of power provided to an motor or any other  load connected. The fraction of the period for which the signal is high is known as the duty cycle. The average DC value of the signal can be varied by varying the duty cycle.With the help of potentiometer we can change voltage at analog pin and then according to program vary the duty cycle thus changing the average DC value. This method is commonly used for controlling speeds of DC motors and controlling brightness of leds. For example, if motor has 100 rpm then you can vary its speed between 0 t0 100 rpm.

By changing the width of pulse applied to the DC motor we can increase or decrease the amount of power provided to the DC motor .The ability to control the DC motor with PWM is one of the reason to prefer it over AC motors.

In this post we will see how you can use ADC(analog-digital conversion) and PWM(pulse width modulation) function of PIC to control the speed of DC motors.In this project I have used mosfet motor driver, it has to be provided with a seperate power supply of 12 volts. Connect the pins of motor driver according to the following manual:

http://www.robokits.co.in/documentation/DC_Motor_Driver_24V_20A.pdf

CIRCUIT

IMAG0516

COMPONENTS REQUIRED

Potentiometer(0-10k) ,voltage regulator 7805 ,dc motoer ,motor driver with pwm control, pic16f877a, connectors etc.

PROGRAM USING MPLAB :

#include<htc.h>
#define _XTAL_FREQ 4000000
int adc();
int adc()
{
int h;
ADCON1=0x80;
ADCON0=0x01;
ADGO=1;
while(ADGO==1);
h=ADRESH;
h<<8;
h=h+ADRESL;
return(h);
}
void main()
{
TRISC=0x00;
while(1)
{
CCP1CON=0x0C;
PR2=100;
T2CON=0x04;
CCPR1L=(adc()*100)/1023;
}
}

The value of the registers can be found by following image-

Here we are only using CCP1.Just vary the voltage at analog pin and control the speed of DC motor.

-ABHISHEK KATHPAL

Advertisements

One thought on “Pulse Width Modulation Using PIC16F877A

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s