DC Motor Speed Control using PWM with PIC Microcontroller

DC Motor Speed Control using PWM with PIC Microcontroller

I already posted about Interfacing DC Motor with PIC Microcontroller. In our robotics applications we may have to control the speed of the DC Motor. In this tutorial we will see how to control the speed of a DC Motor using Pulse Width Modulation (PWM). By using PWM we can easily control the average power delivered to a load and by thus we can easily control the speed of the DC Motor.

You may think that a variable resistor in series with a DC Motor can control its speed. There are three reasons for “Resistor is not a good choice for controlling the speed of a DC Motor”.

  • The main problem is that the motor is a varying electrical load so a resistor can’t do this task. It needs more power during start up than in running state. It draws more current also when a mechanical load is applied to motor shaft.
  • The resistor drops excess energy as heat. Thus it is not good for a battery powered device.
  • We all know that motor requires more current, so resistors with higher power rating are required to drop excess energy.

PWM can be easily generated using the inbuilt CCP module of a PIC Microcontroller. CCP stands for Capture/Compare/PWM. CCP modules are available with a number of PIC Microcontrollers. Most of them have more than one CCP  module. MikroC Pro for PIC Microcontroller provides built in library routines for PWM which makes our task very simple. Please refer the following articles.

In this example project DC Motor is interfaced with PIC Microcontroller using L293D Motor Driver. Two Push Button switches are provided to control the speed of the motor. Here we are using 12V DC Motor and average DC value delivered to motor can be varied by varying the duty ratio of the PWM. The average DC Voltage of 0% duty cycle is 0V, 25% duty cycle is 3V, 50% duty cycle is 6V, 75% duty cycle is 9V and for 100% duty cycle 12V.


Circuit Diagram – DC Motor Speed Control

DC Motor Speed Control using PWM with PIC Microcontroller

DC Motor Speed Control using PWM with PIC Microcontroller

Note: VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND.

Two push button switches are connected to 1st and 2nd pins of PORTD which is used to control the duty ratio of the generated PWM. Pressing the UP switch increases the duty cycle, which increases the motor speed while pressing the DOWN switch decreases the duty cycle, which decreases the motor speed. Here we use CCP1 module of PIC 16F877A to generate PWM and it is given to the enable pin of L293D. The direction of rotation of motor can be control using the 1st and 2nd pins of PORTB.

MikroC Code

void main()
{
  short duty  = 0; //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(duty); //Set current duty for PWM1

  while (1)        // endless loop
  {
     if (!RD0_bit && duty<250) //if button on RD0 pressed      
     {       
        Delay_ms(40);       
        duty = duty + 10;  //increment current_duty     
        PWM1_Set_Duty(duty);  //Change the duty cycle      
     }     
     if (!RD1_bit && duty >0) //button on RD1 pressed
     {
       Delay_ms(40);
       duty = duty - 10;  //decrement duty
       PWM1_Set_Duty(duty);
     }
    Delay_ms(10);      // slow down change pace a little
  }
}

The parameter of PWM1_Set_Duty() is duty ratio which ranges from 0 to 255, ie 0 means 0% duty cycle and 255 means 100% duty cycle.

I think the program is self explanatory, so if you have doubts please comment below.

You can download the hex file, MikroC source code, Proteus files etc here…

DC Motor Speed Control with PIC Microcontroller

Share this post

Comments (141)

  • jeffin91

    HI…ur posts are very useful and informative…i was wondering if you could provide me with the details of doing this same task with a pic18f452.

    February 3, 2013 at 12:09 pm
  • Ligo George

    You can use the above program for pic 18f452 with some modifications. As shown above TRIS registers are used to set the direction of a pin while to write a data to a output pin LAT register is used. But for reading a port PORT register is used as above………. You can use the above functions in mikroc for 18f452

    February 3, 2013 at 2:30 pm
  • jeffin91

    thank u so much..is there a fuzzy logic concept in the above code or can we incorporate the fuzzy logic concept into the above code.?

    February 3, 2013 at 2:51 pm
  • Ligo George

    Yes, it may be said like that as the motor is not fully ON or OFF …. …. You can incorporate fuzzy logic concept in to above code, for eg: speed control of FAN according to the room temperature…

    February 3, 2013 at 4:37 pm
  • Nishantk

    Hi..I had a doubt that rather than using switch to control duty cycle is it possible for us to write a code and accordingly generate pwm?

    February 12, 2013 at 10:36 pm
  • Ligo George

    Yes, of course…………. You can generate appropriate pwm for your applications.. This is just a tutorial for getting started with PWM

    February 13, 2013 at 7:18 am
  • mylz muzik

    can i use this setup to drive brushless outrunner motors ?
    i have tries using ESC with very little luck
    thank you !

    April 5, 2013 at 5:43 pm
  • Ligo George

    Brushless DC Motors uses a 3 phase AC motor that has connected to a Electronic Speed Controller (ESC) circuit…. so there is no use of DC PWM controller in this case……..

    April 6, 2013 at 8:06 am
  • mylz muzik

    am trying 2 run it with pwm from pic16f887 but it keeps implying that somrthing is wrong with my signal ,.. so am thinking of substituting the ESC with a motor driver IC .. good idea or not ?

    April 6, 2013 at 11:14 pm
  • Ligo George

    Use a 3 phase brushless motor instead of dc brushless motor…. and control its speed using 3 pwm…………

    April 7, 2013 at 3:11 am
  • pervez karim

    can you please help me to right the above program in assembly language plzzz

    April 22, 2013 at 12:53 am
  • Ligo George

    Sorry, I haven’t yet used pic assembly language ..

    April 23, 2013 at 7:10 pm
  • Dante

    i have a problem here. I’m using PIC 18F4550. Is it requires a totally different code?

    April 27, 2013 at 6:44 pm
  • Ligo George

    Nop, since we are using MikroC compiler, there are only some modifications… To set direction of io pins use TRIS register, to read data from io pins use PORT register but for write data to io pins use LAT register…
    In the above program change PORT register to LAT, it will work..

    April 28, 2013 at 10:31 am
  • metwally shoier

    hi,
    I am using a pic18f452 with a crystal 4Mhz …. Do i have to change the constant 1000 ???

    May 12, 2013 at 2:45 am
  • Ligo George

    Nop, change the Clock Frequency in the project settings..

    May 12, 2013 at 11:54 am
  • Fathin Amira

    Can i use crystal 20mhz and 18pf capacitor? And what should i change in the coding?

    May 14, 2013 at 11:44 pm
  • Ligo George

    You need to change only the crystal frequency in the project settings…

    May 15, 2013 at 2:04 pm
  • Muhammad Arslan Khurshid Bhatt

    I want to generate continuous pwm on the basis of voltage. Can it possible that one pin generate pwm continuously while my program observing voltage continuously with out disturbing PWM. IN this program you add 10 in duty cycle how much duty it increase.Thanks

    May 16, 2013 at 9:30 pm
  • Ligo George

    Yes you can generate continuous pwm by changing dutycycle…
    The parameter of PWM1_Set_Duty() is duty ratio which ranges from 0 to 255, ie 0 means 0% duty cycle and 255 means 100% duty cycle.

    May 17, 2013 at 8:46 am
  • Tolga

    Hey great documents, thanks. Sir, I need to do a pic16f84a project that controls dc motor gonna use mosfet, i need to speed it up and slow it down with a pwm technique can you help me with circuit and assm code if you have some time?

    May 29, 2013 at 2:04 am
  • Ligo George

    Sorry, I haven’t yet used pic assembly language…

    May 29, 2013 at 7:28 pm
  • bunny

    can we i use this program for pic 18f4520 to control the speed of 12v dc motor??

    June 4, 2013 at 7:51 pm
  • layan

    what about 3ph induction motor i wanna connect potentiometer with pic to controlled motor speed i need pic code of this case any one help me

    June 6, 2013 at 9:33 am
  • Ligo George

    For the speed control of 3 phase induction motor you need 3 pwm channel.. but the above pic has only two.. but you can generate a Software generated pwm using interrupts of CCP module……
    You need to vary the frequency of the pwm to control the speed of three phase induction motor..

    June 8, 2013 at 8:11 am
  • Ligo George

    Yes.. of course… .. Note that for 18f series.. output register is LAT… not PORT… PORT is used for reading data……You need to change the output registers of above program as LAT… no other changes in program..

    June 8, 2013 at 8:13 am
  • Srishti Srivastava

    what’s the purpose of using the crystal?

    July 2, 2013 at 5:42 pm
  • Ligo George

    If you need to connect only one 7 segment, simply connect its 7 inputs to any of the output pins of the microcontroller. If you need to connect more than one 7 segments… try this article. It might help you..
    http://www.electrosome.com/multiplexing-seven-segment-displays/

    July 2, 2013 at 7:36 pm
  • Srishti Srivastava

    okay, thanks! And what about the coding part ? If i want to display the speed in rpm

    July 2, 2013 at 9:40 pm
  • Ligo George

    To display speed in rpm you need more than one seven segment.. You can use above link and Hex() covert a number to its 7 segment code…
    The speed of the dc motor can be find using an IR transmitter and Receiver, by counting the no. of times IR beam is cutting in a minute…….

    July 3, 2013 at 5:37 am
  • Srishti Srivastava

    Thank you so much!

    July 4, 2013 at 10:22 am
  • Xolani M Charlie

    does a atmega16 microcontroller have a CCP?

    August 5, 2013 at 11:28 pm
  • Ligo George

    Why don’t you refer its datasheet??
    There are 4 PWM channels in Atmega16… there is no CCP…

    August 7, 2013 at 11:09 am
  • Kinetic Energy

    My input is form the dtmf decoder, can i use this code to control my DC motors?

    August 26, 2013 at 3:43 pm
  • Ligo George

    Sure,,, give the output of DTMF decoder to input of PIC and write the required code to control the motor..

    August 26, 2013 at 5:40 pm
  • rajatbhise

    PLEASE GIVE ME THE FUTURE USE AND APPS OF

    SPEED
    CONTROL OF A DC MOTOR USING MICROCONTROLLER 8051

    August 26, 2013 at 9:14 pm
  • Ligo George

    It can be used in robotics applications…….

    August 27, 2013 at 4:35 am
  • kite

    PWM to control stepper motor is it possible

    August 31, 2013 at 6:40 pm
  • Ligo George

    To adjust the speed of stepper motor, you should control the delay between stepping..

    August 31, 2013 at 9:32 pm
  • derr

    two questions

    1) Can this setup receive an analog signal to the microcontroller? does it have ADC? Basically what type of micro controller is used to monitor an analog signal in real time and compute the motor speed based on a function of the incoming analog signal? (or would a DSP be more suited for this)

    2)is it always necessary to have a motor driver between the microcontroller and the motor? Or are do there exist microcontrollers that can directly control the motor speed?

    September 4, 2013 at 1:31 am
  • Ligo George

    The above microcontroller have ADC…. I think the above microcontroller is enough for you… since I think you are dealing with slowly varying analog signals…………..
    A driver is required.. to drive the motor..

    September 8, 2013 at 8:01 am
  • rahul

    is the above method suitable to control the speed of a 36v 360 watt dc motor?

    September 26, 2013 at 8:38 pm
  • Ligo George

    You can use the PWM Method,… but can’t use L293D…. ..
    You should use appropriate drivers…

    September 28, 2013 at 7:23 am
  • RINS

    the above circuit not working, i tried many times, pls help me….

    October 11, 2013 at 10:32 pm
  • Ligo George

    Hello, it will work..
    Did you tried it in hardware..??
    If it is not working in hardware.. try connecting the EN1 pin to VDD and check whether the motor is working……..
    if it works.. then reconnect it to ccp pin… then try reducing the pwm frequency…

    October 14, 2013 at 7:26 am
  • jan

    How to use this with a PIC32, what ports to use ?

    December 12, 2013 at 4:37 am
  • Ligo George

    Please refer the datasheet of your microcontroller..

    December 12, 2013 at 4:22 pm
  • Mout Hunter

    I have one project about line follower. Can you give me some information about it???

    December 27, 2013 at 9:25 am
  • Ligo George

    You can use PWM to control the speed of motors… depending upon the curves..

    December 29, 2013 at 8:59 pm
  • Mout Hunter

    But i don’t know how to write code with Mikro Basic to apply to my line follower.

    January 6, 2014 at 9:17 am
  • Ligo George

    Use google .. There are a lot of tutorials over internet..

    January 12, 2014 at 5:34 pm
  • fifi

    is it possible to run a 3V DC motor directly from the microcontroller? or do i need a motor driver for it to turn?

    February 4, 2014 at 12:52 pm
  • Safaa Monther

    hello iwant to control dc motor and feed back to micro controller by using vco ineed the program in micro c

    February 26, 2014 at 1:19 pm
  • rinku

    hi i am doing project on people counting system and home automation so as number of people increase temperature increase it is necessary and if yes so i can control the speed by pwm ? i am mot using temperature sensor. thanks

    March 19, 2014 at 12:41 pm
  • sachin poly

    sir ,
    i want to make a temperature controlled fan using pic168f77a i connected a temperature sensor in to pic’s adc input port A0.. and tried with your above program with slight modification.. but it shows error . it shows we want to initialise the identifier TRISD,C,B.. and lot of other errors..
    can you please help me..?

    March 20, 2014 at 6:34 am
  • Gaurees

    Hi Mate, I want to use this for a robotic arm, I am planing to use 2 DC motors for 2 joints (Each motor for each joints). I decided to use L293 motor driver full bridge IC. My question is should I use two L293 IC for 2 motors? both joints moves up and down wards. not side movement.
    I am designing my own PCB board on Altium designer. so plzz give me clear full circuit the with PIC16f877A and L193 for 2 motors. Thank you and have a nice day

    April 3, 2014 at 6:45 am
  • Nguyễn Đình Việt

    This wish is reversible reversible how dear?, You can edit the code to help me please? Thank you

    April 24, 2014 at 7:26 pm
  • myra

    how to do if i want to control the speed by using 5 switches
    means that i have 5 speed. (just like fan)

    May 12, 2014 at 6:31 am
  • Cristian

    xc8.exe –pass1 –errformat=”Error at file %%f line %%l column %%c: (%%n) %%s” –warnformat=”Warning at file %%f line %%l column %%c: (%%n) %%s” –msgformat=”Message at file %%f line %%l column %%c: (%%n) %%s” -G –chip=16F877A -O”main.p1″ “../main.c”

    Microchip MPLAB XC8 C Compiler (Free Mode) V1.31

    Copyright (C) 2014 Microchip Technology Inc.

    License type: Node Configuration

    Warning at file line column : (1273) Omniscient Code Generation not available in Free mode

    Warning at file ../main.c line 15 column 1: (361) function declared implicit int

    Warning at file ../main.c line 16 column 1: (361) function declared implicit int

    (908) exit status = 1

    make: *** [main.p1] Error 1

    Warning at file ../main.c line 17 column 1: (361) function declared implicit int

    Error at file ../main.c line 21 column 18: (195) expression syntax

    Error at file ../main.c line 23 column 13: (194) “)” expected

    Error at file ../main.c line 27 column 18: (195) expression syntax

    Error at file ../main.c line 29 column 13: (194) “)” expected

    Error at file ../main.c line 33 column 10: (194) “)” expected

    Error at file ../main.c line 34 column 1: (285) no identifier in declaration

    Warning at file ../main.c line 34 column 1: (374) missing basic type; int assumed

    Error at file ../main.c line 34 column 1: (314) “;” expected

    Error at file ../main.c line 35 column 1: (285) no identifier in declaration

    Warning at file ../main.c line 35 column 1: (374) missing basic type; int assumed

    Error at file ../main.c line 35 column 1: (314) “;” expected

    Error code 2

    May 24, 2014 at 6:23 pm
  • Cristian

    were is my mistake???

    May 24, 2014 at 6:24 pm
  • Ligo George

    Hello,
    The above code is written for MikroC PRO Compiler..

    June 12, 2014 at 9:19 pm
  • azam khan

    hii , can i use a 12v/ 2 amp dc motor here

    August 31, 2014 at 9:53 pm
  • Ligo George

    No, L293D is able to handle only 600mA continuous current and 1.2A Peak current.
    You can use power transistors.

    September 1, 2014 at 4:44 pm
  • user

    Sir, Here the pwm signals are being generated but in which part of the code are we sending them to Inputs of L293D (RB10 and RB11) ??

    October 24, 2014 at 11:44 pm
  • Ligo George

    PORTB = 0x02; //Run motor in anticlock wise
    0x02 = 0b00000010

    October 26, 2014 at 10:00 am
  • Nustian

    hey Ligo, can you tell me the rating of the motors for which this cct is applicable? and is it verified in terms of hardware ???…..

    November 5, 2014 at 1:07 am
  • Mohd Tarmidzi

    Hi Mr. Ligo. do u have whatsapp or Facebook? I want talk with u in privacy.. I need your help, sir. Please email ur personal contact at [email protected]

    i really need ur help..

    November 9, 2014 at 5:20 pm
  • yogesh

    sir i want to use two stepper motors. i am using a3967 driver kit so i need to controlled them step by step in horizontal and vertical manner as i am building a xy scanner so suggest me some help for it

    November 10, 2014 at 11:49 am
  • Ligo George November 10, 2014 at 1:11 pm
  • kauthar

    i want to know how to control the direction of motor using push button,which means it have forward button and reverse button.thank you

    November 12, 2014 at 7:00 am
  • Ligo George

    Do like this :
    if(button1 pressed)
    {
    PORTB.F0 = 1;
    PORTB.F1 = 0;
    }
    if(button 2 pressed)
    {
    PORTB.F0 = 0;
    PORTB.F0 = 1;
    }

    November 13, 2014 at 9:07 am
  • ANIL KUMAR

    sir i want program in assemly language in pic16f877

    December 4, 2014 at 1:30 pm
  • ANIL KUMAR

    dear sir,
    whethere i can control the motor speed with IR remote

    December 4, 2014 at 1:32 pm
  • Ligo George

    Sorry, we don’t have assembly language programs..

    December 5, 2014 at 11:28 am
  • ANIL KUMAR

    sir,
    whether we can control the same ckt with remote.
    if you having any circuit diagram means please mail me.

    December 8, 2014 at 3:21 pm
  • ANIL KUMAR

    sir, may I know how the unique code is generated from an ir sensor when it sense the ir remote pulse. and how can we get the codes…….?
    can u help us…..

    December 8, 2014 at 3:25 pm
  • ANIL KUMAR

    sir,
    And need the circuit diagram of automatic railway gate on/off controller .If u having please send me

    December 8, 2014 at 3:28 pm
  • Ligo George

    Sorry we haven’t yet that project..

    December 8, 2014 at 4:34 pm
  • Ligo George

    You can read it using a microcontroller.

    If you need more support, please open a new topic in our forums (https://electrosome.com/forums)

    December 8, 2014 at 4:35 pm
  • jeganathan v

    sir i want to the circuit diagram of pic controller of 230v but above circuit only give 12v,i am want 230v so pls reply me

    February 21, 2015 at 12:05 pm
  • Ligo George

    Sorry, I don’t understand your question. Can you please elaborate ?

    February 23, 2015 at 4:29 pm
  • naveen

    what is pwm1_init for 20mhz frequenc

    March 13, 2015 at 1:19 pm
  • Ligo George

    What do you mean ?

    March 17, 2015 at 4:56 pm
  • AKHIL

    while using pwm the torque decreases , why?

    March 23, 2015 at 9:20 pm
  • Ligo George

    Yes… torque will decrease… as the current decreases.
    If you want to decrease speed without lossing speed, you should use proper gears ..

    March 29, 2015 at 11:11 am
  • sam

    hye ligo..how to control motor speed and direction at same time using pic microcontroller..

    March 30, 2015 at 12:38 pm
  • akshaydadhich

    hi ligo . i am using adxl 345 and using dc servo . i wish to know after the conversion of analog values from adxl by pic microcontroller 16f452 how will i give this digital value to pwm so that my motor rotaes proportionally with the adxl tilting.
    thnx in advance

    April 4, 2015 at 9:31 pm
  • Ligo George

    Just invert RB0 and RB1

    April 5, 2015 at 1:04 pm
  • Ligo George

    As you are using Servo Motor.. please read our servo motor tutorial..
    https://electrosome.com/servo-motor-pic-microcontroller/
    Just change the pulse width according to the adc value.

    April 5, 2015 at 1:16 pm
  • akshaydadhich

    hey i used the foolowing code

    unsigned int temp_res;

    unsigned short temp_duty;

    void main()

    {
    ADCON1 = 0x80; // Configure analog inputs and Vref

    PORTC = 0;

    TRISC = 0; //all PORTC pins output

    // Initialize and start the PWM unit

    PWM1_Init(5000);

    PWM1_Start();

    while(1){

    temp_res = Adc_Read(0); // Get results of
    AD conversion

    //from channel
    0 (RA0 pin)

    temp_duty = (temp_res/4); // Convert the 10
    bit value

    //to 8 bits

    PWM1_Set_Duty(temp_duty); // Set the duty
    value

    Delay_ms(20000); // Slow everything down a
    little

    }

    }

    the value of servo remains const at -90 degree .

    its value is not changing with adc values

    April 5, 2015 at 6:41 pm
  • anandi

    Sir ..Good evening………..
    How can we control the speed a DC motor by receiving a sms or alert signal

    April 7, 2015 at 5:39 pm
  • anandi

    In above problem ………..by using 8051 Microcontoller?

    April 7, 2015 at 5:46 pm
  • Solomon Mingle

    hey guys i need help to solve this question?
    draw a circuit to Turn ’ON’ the ignition circuit when
    the interior light is ‘OFF’ AND when your student number has been entered.

    After 3 failed attempts at entering
    the student number the required number will default to ‘25122015’.

    Once ‘ON’ the ignition must stay
    ‘ON’ even if the interior light is switched ‘ON’

    This must be simulated in Circuit
    Wizard.

    April 13, 2015 at 7:49 am
  • Ligo George

    Hello, the above tutorial is for DC Motor.. not for Servo Motor…and you can’t use PWM module for controlling servo.

    April 13, 2015 at 10:14 am
  • Ligo George

    You should use a GSM modem for that.

    April 13, 2015 at 10:31 am
  • Elboreene Emad

    hello can you write the code for pic18f4550
    in xc8

    April 20, 2015 at 4:49 pm
  • Ligo George

    Just change the PORT register to LAT for output write operations. …

    April 27, 2015 at 10:08 pm
  • jammu

    sir may i use 12v BLDC motor???have ccs compiler..may i use the code in mplab ide

    July 23, 2015 at 1:36 pm
  • jammu

    if i use ccs compiler my program is not dumping ..dont knw wats wrong with dat?

    July 23, 2015 at 1:41 pm
  • Aashish Joshi

    Hi, what are the header files and library files required for this?
    Thanks

    August 14, 2015 at 10:16 am
  • Aashish Joshi

    the coding is

    #include

    #include

    #include”xc.h”

    #include

    #define byte unsigned char

    void main()

    {

    short duty = 0; //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(duty); //Set current duty for PWM1

    while (1) // endless loop

    {

    if (!RD0_bit && duty0) //button on RD1 pressed

    {

    __delay_ms(40);

    duty = duty – 10; //decrement duty

    PWM1_Set_Duty(duty);

    }

    __delay_ms(10); // slow down change pace a little

    }

    August 14, 2015 at 12:22 pm
  • Ligo George

    No, the above code is intended for MikroC only.

    August 14, 2015 at 9:17 pm
  • Ligo George

    No header files or library files are required. It uses built in library of MikroC.

    August 14, 2015 at 9:46 pm
  • Ligo George

    Check for the errors shown by the compiler.
    If you want detailed help, please post it with complete code in our forums, https://electrosome.com/forums/

    August 14, 2015 at 9:48 pm
  • Ligo George August 14, 2015 at 9:52 pm
  • Ei Ei Aung

    Is this the same for bldc motor???

    October 9, 2015 at 3:40 am
  • nisa

    hey,i just wan to know the is that coding can be use in mplab ide?

    October 10, 2015 at 2:29 pm
  • Ligo George

    NO, you cannot vary the speed of brush less dc motor by simply varying voltage.

    November 21, 2015 at 1:12 pm
  • Ligo George

    Yes, you can use. Try the following link.
    https://electrosome.com/pwm-pic-microcontroller-mplab-xc8/

    November 21, 2015 at 1:14 pm
  • le Prince

    How can i control DC motor speed using two potentiometer and op-amp with PIC Microcontroller??

    November 22, 2015 at 12:45 am
  • Ligo George

    You can connect potentiometer to ADC input of microcontroller. Then vary the PWM depending on the A/D results.

    November 22, 2015 at 9:26 am
  • Minas Sk

    Hello can i have the code for direction and speed control in assembly? Thank you

    December 4, 2015 at 12:54 am
  • Ligo George

    Just connect a potentiometer to the ADC input of a microcontroller. As the input voltage varies, adc result will also vary. You can easily convert this to PWM.

    December 19, 2015 at 3:13 pm
  • Ligo George

    Sorry, we don’t have any assembly codes.

    December 19, 2015 at 3:41 pm
  • le Prince

    The micro C code plz….

    December 19, 2015 at 4:15 pm
  • Mahnoor Naseer

    When i increase the duty cycle the motor speed keeps on increasing how to make it constant ?

    February 3, 2016 at 2:06 pm
  • yatish khare

    hello sir, i don’t know much about electronics as a mechanical engineer but i want to know, by this method described above can we control the speed of a heavy motor like 1.5kw to 2kw power capacity or there is any other way?
    thanks in advance

    February 5, 2016 at 2:44 pm
  • Ligo George

    What do you mean by that ? Motor speed should increase when you increase the duty cycle. If you need constant speed, don’t change duty cycle.

    February 14, 2016 at 6:13 pm
  • Ligo George

    It actually depends on the type of motor you need to use.

    February 14, 2016 at 7:01 pm
  • yatish khare

    the motor about which i am talking is a DC series wound motor which is used as starter motor in automobiles.these motors are powered by 12V dc supply by battery and what i know is that speed of dc motor depends on applied voltage and i think there is no other way than PWM by which speed of DC motor could be varied over a range. so please help me if i am wrong about this and would it be possible to control this type of motor by this method.

    February 14, 2016 at 10:52 pm
  • Mahnoor Naseer

    when I simulate this on proteus, on one fixed value of duty cycle the speed keeps on increasing. Infact it should remain constant for a a single value of duty cycle. You think is that a software draw back ?

    February 16, 2016 at 2:23 am
  • Ligo George

    PWM is varying the average output voltage, so it controls the speed by changing voltage itself.

    February 27, 2016 at 7:47 pm
  • Ligo George

    That will be showing animation with taking account of inertia. It should become constant after some time… after attaining maximum speed.

    February 27, 2016 at 7:53 pm
  • yatish khare

    ok got it, thanks sir

    February 28, 2016 at 11:17 am
  • OldPirate

    how does one change direction?

    March 17, 2016 at 3:19 pm
  • Ligo George

    Just invert the inputs to IN1 & IN2 of L293D.

    March 19, 2016 at 11:20 am
  • meena

    how to do in mplab?

    March 24, 2016 at 7:57 am
  • dhilipan

    sir , i hove a doubt about how to stop the dc motor? using pic 16f877a ..please send me souce code.

    April 4, 2016 at 6:41 pm
  • lei

    hi sir. can i know is this code program can use in pic c compiler. if cant how to change it

    May 16, 2016 at 6:03 am
  • Ligo George

    This code is for MikroC pro compiler.

    June 2, 2016 at 6:35 pm
  • Luan

    Me I use Pic16F628A? What should I change in code?

    June 5, 2016 at 8:23 pm
  • Ligo George

    There won’t be much changes since it is MikroC compiler.

    August 27, 2016 at 12:07 pm
  • Ligo George

    Yes, you can use H bridge with mosfets.

    If you want additional protection, you can add additional circuits for that.

    September 22, 2016 at 7:35 pm
  • jyoti

    hi..in power factor correction how to calculate the time difference average

    November 10, 2016 at 10:17 am
  • jyoti

    hi..in power factor correction how to calculate the time difference average.

    November 10, 2016 at 10:19 am
  • Ligo George

    Sorry, I don’t understand.

    Kindly use our forums ( https://electrosome.com/forums/ ) for asking dobuts outside the scope of above article.

    November 27, 2016 at 2:34 pm
  • Bob Remb

    hey sir about this post how to add another output ad IC Machine Drive?

    March 1, 2017 at 7:32 pm
  • Zanz Ahmad September 23, 2018 at 5:25 pm
  • NIHAL SADATH CM

    How to check L293D whether working or not ? Easily ???

    October 14, 2018 at 1:17 am

Leave a Reply

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