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:
Potentiometer(0-10k) ,voltage regulator 7805 ,dc motoer ,motor driver with pwm control, pic16f877a, connectors etc.
PROGRAM USING MPLAB :
#define _XTAL_FREQ 4000000
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.