PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller

In our last PIC online tutorial we have covered PWM generation using PIC Microcontroller. As I told earlier PWM has wide application in electronics and robotics engineering.In this article I’m gonna show you one of the important applications of PWM in Robotics, it is called Pulse Width Modulation motor speed control.

The method of generation of PWM signal is the same as before and this signal is applied to the Enable terminal of L293 motor driver IC. L293 is an H bridge motor controller IC capable of driving 2 Motor loads at a time.

Below is the detailed description of dc motor speed control using PWM technique with Proteus simulation and video demonstration.

Read more about: H Bridge L293 Motor driver 

PWM+DC+Motor+Controller+Simulation PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller

This demonstration was done with available latest version of Proteus design suite and Mikro C pro.

Why We Need PWM For Speed Controlling Of DC Motor?

You may wonder why we need PWM signal for controlling DC motor speed when a resistor in series with the motor can simply do this job.

It’s because this method is not recommended in practical and also you don’t get enough torque to drive the motor with the help of resistor.

Limitation of using resistor

  • DC motor needs more power during the operation, also it draws more current from the supply.
  • If we use resistors, the motor will not get enough power to rotate because some of the power is dropped across the resistor (Low current).
  • Also the current will be very low.

So, How to control DC motor speed effectively? Here comes the importance of PWM technique…!

DC Motor Speed Control Using PWM Technique

  • With the help of PWM it is possible to control the average power delivered to a load and by thus we can easily regulate the speed of the DC Motor.
  • When the width of pulse is high, the motor will rotate with full speed.
  • Obviously with low pulse width, speed of motor gets reduced.
  • In both cases full current reaches the motor and only the average power changes, thus we get better torque in  each case.
  • Basically in this method we are chopping the DC voltage at regular interval.

PWM DC Motor Speed Driver Schematic

PWM+DC+Motor+Speed+Controller+Circuit+Using+PIC16F877A PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller
Click to enlarge

PIC 16F877A PWM DC Motor Speed Control Mikro C Program

In this Mikro C embedded C program, two input switches are used to control the duty cycle of PWM signal.

S1 for increasing duty cycle and S2 for decreasing the same.

Frequency of PWM signal is set to 1 KHz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void main()
{
short duty1 = 16; //initial value for duty
TRISD = 0xFF; //PORTD as input
TRISC = 0x00; //PORTC as output
TRISB = 0x00; //PORTB as output
PORTB = 0x02; //Run motor in anticlock wise
PWM1_Init(1000); //Initialize PWM1
PWM1_Start(); //start PWM1
PWM1_Set_Duty(duty1); //Set current duty for PWM1

while (1) // endless loop
{

if (PORTD.F0==0) //Checking the button pressed or not
{
Delay_ms(1);
duty1++; // increment duty cycle
PWM1_Set_Duty(duty1); //Change the duty cycle
}

if (PORTD.F1==0) // Checking the button pressed or not
{
Delay_ms(1);
duty1--; // decrement duty cycle
PWM1_Set_Duty(duty1);
}
Delay_ms(10);
} }

All the program codes are self-explanatory, if you have any doubts please let us know through the comment box below.

PIC PWM Motor Speed Control Simulation in Proteus 8

Let’s start our virtual lab!

Step 1:
Generate .Hex file for PWM speed control in Mikro C.
Compile the above program in Mikro C, if you don’t know how to build hex file please read our Getting started guide for Mikro C Pro.

Step 2:
Draw the schematic in Proteus 8 as shown.

PWM+DC+Motor+Speed+Controller+Circuit+Using+PIC16F877A PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller
(Click on the image to enlarge)

Step 3:
Load .Hex file to the PIC.

Browse+.HEX+file+to+PIC+MCU+in+Proteus+8 PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller

Practical help: Use our USB PIC Programmer circuit for burning PIC Microcontroller practically.

Step 4:
Now Run the simulation.

Run+Simulation+Button+in+Proteus+8 PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller

Step 5:
Change duty cycle using provided keys and observe the speed of DC motor (watch the video).

Adjusting+the+speed+of+DC+motor+with+PWM+technique PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller

Downloads:PWM DC Motor control .Hex file.

Circuits Gallery Video Lab

Watch this video from our Video lab where I have explained everything related to PIC PWM DC motor speed controller.

Please like our Facebook page to stay connected.

Next → Speed and Direction control of DC motor using PIC Microcontroller

Ads

One thought on “PWM DC Motor Speed Controller Circuit Using PIC16F877A Microcontroller

  1. Anyway to control the PWM depending on the load current so that voltage changes and speed is maintained constant during different loads?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>