Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Robotics Chat


Robotics Chat Specific to discussions about robots and the making of.

Reply
 
Thread Tools Display Modes
Old 10th December 2007, 04:58 PM   (permalink)
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!!!
nelson_kh is offline   Reply With Quote
Old 10th December 2007, 05:20 PM   (permalink)
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
jpanhalt is offline   Reply With Quote
Old 10th December 2007, 10:15 PM   (permalink)
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
Wingmax is offline   Reply With Quote
Old 13th December 2007, 11:17 AM   (permalink)
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??
nelson_kh is offline   Reply With Quote
Old 13th December 2007, 09:51 PM   (permalink)
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!
Krumlink is online now   Reply With Quote
Old 13th December 2007, 09:57 PM   (permalink)
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
Wingmax is offline   Reply With Quote
Old 14th December 2007, 03:34 PM   (permalink)
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?
nelson_kh is offline   Reply With Quote
Old 15th December 2007, 10:38 AM   (permalink)
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
Wingmax is offline   Reply With Quote
Old 15th December 2007, 08:54 PM   (permalink)
Default see this tut.

http://www.ikalogic.com/tut_closed_loop_spd_ctrl.php


you can learn something
Rami00972 is offline   Reply With Quote
Old 16th December 2007, 10:49 AM   (permalink)
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.
nelson_kh is offline   Reply With Quote
Old 16th December 2007, 12:00 PM   (permalink)
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
Wingmax is offline   Reply With Quote
Old 16th December 2007, 12:08 PM   (permalink)
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
Wingmax is offline   Reply With Quote
Old 16th December 2007, 03:03 PM   (permalink)
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??
nelson_kh is offline   Reply With Quote
Old 16th December 2007, 10:01 PM   (permalink)
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
Wingmax is offline   Reply With Quote
Old 17th December 2007, 07:20 PM   (permalink)
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?
nelson_kh is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Motor Overheating w/ Speed dknguyen Robotics Chat 10 16th October 2007 04:53 PM
DC motor Control, Timer mitchell.s General Electronics Chat 3 6th October 2007 08:18 PM
Variable DC motor speed control fabbie Electronic Projects Design/Ideas/Reviews 6 17th October 2004 05:13 AM
Looking for AC motor speed control circuit Tako Kichi Electronic Projects Design/Ideas/Reviews 3 4th August 2004 06:16 AM
To control speed of motor by distance of 2 objects ahkumm Electronic Projects Design/Ideas/Reviews 1 28th October 2002 10:07 AM



All times are GMT. The time now is 02:44 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.