+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 26

Thread: Speed Control Of Dc Motor

  1. #1
    nelson_kh Newbie
    Join Date
    Dec 2007
    Posts
    14

    Unhappy Speed Control Of Dc Motor

    do anyone got any simple sample code in C language that can control the speed of dc motor?? it can help more easy to understand wat the datasheet talking about!! i set the CCP1L,CCP1CON,T2CON, PR2 and a output signal for motor alr but motor still cant move.i using pic06f877a. thanks for urs help!!!


  2. #2
    jpanhalt Excellent jpanhalt Excellent jpanhalt Excellent jpanhalt Excellent jpanhalt Excellent jpanhalt Excellent
    Join Date
    Jun 2006
    Location
    Cleveland, OH, USA
    Posts
    1,589

    Default

    Can you post your code? I can't do C, but many others here can. They will want to see the code.

    You seem to be using the motor drive as a test of the code. There can be errors between the PIC and the motor, so I would suggest something more directly related to the PIC, like putting a scope probe or an LED on the output pin(s). That way, you can troubleshoot the PIC aspect without worrying whether the problem is in the PIC program or the motor drive circuit. John

  3. #3
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default

    Quote Originally Posted by nelson_kh
    do anyone got any simple sample code in C language that can control the speed of dc motor?? it can help more easy to understand wat the datasheet talking about!! i set the CCP1L,CCP1CON,T2CON, PR2 and a output signal for motor alr but motor still cant move.i using pic06f877a. thanks for urs help!!!
    If it's any help at all, you can refer to my post in Microcontroller section- "Setting up CCP PWM". It's a method of setting up the Pulse width Modulation. You use this method to drive the DC motor. Of course, there's always different techniques.
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg

  4. #4
    nelson_kh Newbie
    Join Date
    Dec 2007
    Posts
    14

    Default

    thz wingmax....
    i using the 20mega hz crystal... i just change PR2 oni izzit? the formula devide by two value of 4, the both 4 also is scale value?
    if i use the pulse of 4khz wat different? i use power window as motor!
    and the scale i use 16 can??

  5. #5
    Krumlink Excellent Krumlink Excellent Krumlink Excellent Krumlink Excellent Krumlink Excellent
    Join Date
    Aug 2007
    Location
    Michigan, USA
    Posts
    2,093
    Blog Entries
    1

    Default

    Moterz r controlld by voltege, so you need 2 increze your voltagr to make the go faester...

    Spell correctly, it can be difficult to read it!
    IF YOU WANT TO HELP FINE IF NOT PLEASE DON"T PEE IN MY CHEERO'S

  6. #6
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default

    Refer to the formula 1 to find PR2 first: All you need is to substitute the frequency of the osc you use, the frequency of the pulses you want to generate, and choose a prescale so that the overall result would not > 255. this is because PR2 is a 8 bit register, max number is FFh or 255d. don't change the other number 4, it's a constant. And that's it.
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg

  7. #7
    nelson_kh Newbie
    Join Date
    Dec 2007
    Posts
    14

    Default

    the prescale i can chose anynumber? from data sheet there write (1,4,16), we oni can chose this three number as prescale value?i use 20megahz, 2k hz pulse.

    PR2 = 20000000
    ------------ - 1
    2000 x 16 x 4

    is this correct?

  8. #8
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default

    Quote Originally Posted by nelson_kh
    the prescale i can chose anynumber? from data sheet there write (1,4,16), we oni can chose this three number as prescale value?i use 20megahz, 2k hz pulse.

    PR2 = 20000000
    ------------ - 1
    2000 x 16 x 4

    is this correct?
    That's correct. Now you have to calculate the value of CCPR1L and CCR1CON bit 4 and bit 5. And don't forget to set up the CCP1CON and T2CON etc. just follow my example program.
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg

  9. #9
    Rami00972 Bad
    Join Date
    Jan 2007
    Posts
    76

    Default see this tut.


  10. #10
    nelson_kh Newbie
    Join Date
    Dec 2007
    Posts
    14

    Default

    Quote Originally Posted by Wingmax
    That's correct. Now you have to calculate the value of CCPR1L and CCR1CON bit 4 and bit 5. And don't forget to set up the CCP1CON and T2CON etc. just follow my example program.



    Form the example CCPR1L:CCP1CON<5:4> = 250/ 11111010. how u get the CCP1CON bit 4=0 bit 5=1??
    i count the CCPR1L:CCP1CON by duty cycle50%, pulse 2k, scale16. get result is 312.5 which bigger then 256 how? since 16 is the biggest scale can use.

  11. #11
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default

    Quote Originally Posted by nelson_kh
    Form the example CCPR1L:CCP1CON<5:4> = 250/ 11111010. how u get the CCP1CON bit 4=0 bit 5=1??
    i count the CCPR1L:CCP1CON by duty cycle50%, pulse 2k, scale16. get result is 312.5 which bigger then 256 how? since 16 is the biggest scale can use.
    Now you got me confused. How did you get that formula?
    To calculate the value in CCPR1L: CCP1CON>5:4, you need formula 2) in my post, ie, (duty cycle x Fosc)/ TMR2 prescale

    You need to work out the duty cycle first: 50% of 2K pulses= 0.5/2000= 0.00025.

    now , (0.00025 x Fosc)/ 16
    When you got this answer, then you convert it to binary.
    The converted binary number becomes the value of CCPR1L and bit 4 and bit 5 of CCP1CON.
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg

  12. #12
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default

    Quote Originally Posted by nelson_kh
    Form the example CCPR1L:CCP1CON<5:4> = 250/ 11111010. how u get the CCP1CON bit 4=0 bit 5=1??
    i count the CCPR1L:CCP1CON by duty cycle50%, pulse 2k, scale16. get result is 312.5 which bigger then 256 how? since 16 is the biggest scale can use.

    Sorry, I calculated the value and it's 312.5 as you calculated. So now you just round off the number to 313 and convert it to binary. The LSB (bit 0)of the converted number is bit 4 of CCP1CON, bit 1 of the converted number is bit 5 of CCP1CON and so on...
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg

  13. #13
    nelson_kh Newbie
    Join Date
    Dec 2007
    Posts
    14

    Default

    Quote Originally Posted by Wingmax
    Sorry, I calculated the value and it's 312.5 as you calculated. So now you just round off the number to 313 and convert it to binary. The LSB (bit 0)of the converted number is bit 4 of CCP1CON, bit 1 of the converted number is bit 5 of CCP1CON and so on...
    THZ!!
    313 is 100111001. then the bit 4 of CCP1CON is 1 bit 5 is 0.... then the CCPR1L is 01001110..... is this correct??
    The value calculated can not more then 256 right, i count is 313 can use??

  14. #14
    Wingmax Excellent Wingmax Excellent Wingmax Excellent Wingmax Excellent
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    163

    Default

    Quote Originally Posted by nelson_kh
    THZ!!
    313 is 100111001. then the bit 4 of CCP1CON is 1 bit 5 is 0.... then the CCPR1L is 01001110..... is this correct??
    The value calculated can not more then 256 right, i count is 313 can use??
    The binary conversion is correct. And CCP1CON and CCPR1L are correct.You're almost there.
    I think you got confused with PR2. PR2 is a 8 bit register and so the value can't be > 255. But CCPR1L and CCP1CON bit 4 and 5 combined becomes a 10 bit register. So 313 is OK to use. Value in CCPR1L and CCP1CON is for adjusting duty cycle or pulse width. Adjusting that will adjust the speed of the motor. PR2 is for adjusting the frequency or period of the pulses.
    May the force be with you.


    My project: Simple White Line Follower

    http://au.youtube.com/watch?v=8Z_MmrdH4oc

    http://i271.photobucket.com/albums/j...nefollower.jpg

  15. #15
    nelson_kh Newbie
    Join Date
    Dec 2007
    Posts
    14

    Default

    Quote Originally Posted by Wingmax
    The binary conversion is correct. And CCP1CON and CCPR1L are correct.You're almost there.
    I think you got confused with PR2. PR2 is a 8 bit register and so the value can't be > 255. But CCPR1L and CCP1CON bit 4 and 5 combined becomes a 10 bit register. So 313 is OK to use. Value in CCPR1L and CCP1CON is for adjusting duty cycle or pulse width. Adjusting that will adjust the speed of the motor. PR2 is for adjusting the frequency or period of the pulses.
    thank you so much, really help me alot!! i write this code why the speed cant change when i change theCCP1CON and CCPR1L?
    #include <pic.h>
    __CONFIG(WDTDIS & XT & UNPROTECT & LVPDIS);
    #define XTAL 20000000 //crystal frequency = 20MHz

    void main()
    {
    TRISC = 0x00;
    TRISB = 0xFF;
    PR2 = 156;
    CCP1CON = 0b00011100;
    CCPR1L = 0b01001110;
    PORTC = 0b00000010;
    T2CON = 0b00000110;
    if (RB2==0) RC4=1;
    else RC4=0;
    }
    RC5 is output to the turn the motor! and rb2 is input! is the code wrong?

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. Looking for AC motor speed control circuit
    By Tako Kichi in forum Electronic Projects Design/Ideas/Reviews
    Replies: 5
    Latest: 17th January 2009, 11:34 AM
  2. Motor Overheating w/ Speed
    By dknguyen in forum Robotics Chat
    Replies: 10
    Latest: 16th October 2007, 04:53 PM
  3. DC motor Control, Timer
    By mitchell.s in forum General Electronics Chat
    Replies: 3
    Latest: 6th October 2007, 08:18 PM
  4. Variable DC motor speed control
    By fabbie in forum Electronic Projects Design/Ideas/Reviews
    Replies: 6
    Latest: 17th October 2004, 05:14 AM
  5. To control speed of motor by distance of 2 objects
    By ahkumm in forum Electronic Projects Design/Ideas/Reviews
    Replies: 1
    Latest: 28th October 2002, 10:07 AM

Tags for this Thread