![]() |
![]() |
![]() |
|
|
|||||||
| Robotics Chat Specific to discussions about robots and the making of. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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!!!
|
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
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 |
||
|
|
|
|
|
(permalink) |
|
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?? |
|
|
|
|
|
|
(permalink) |
|
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! |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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? |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
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 |
||
|
|
|
|
|
(permalink) |
|
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
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. |
||
|
|
|
|
|
(permalink) | |
|
Quote:
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 |
||
|
|
|
|
|
(permalink) | |
|
Quote:
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 |
||
|
|
|
|
|
(permalink) | |
|
Quote:
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?? |
||
|
|
|
|
|
(permalink) | |
|
Quote:
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 |
||
|
|
|
|
|
(permalink) | |
|
Quote:
#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? |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |