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 18th December 2007, 12:03 PM   (permalink)
Default

Quote:
Originally Posted by nelson_kh
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?
I'm not 100% sure the PWM setting for 16F877 CCP1 is the same as the 16F628 as I haven't worked on one for while. But I know the ADC module in the 16F684 is different than the 16F877.

But anyway, does the motor turn at all? May be not , because you should use RC2 to control the motor instead of RC5. Check the data sheet, pin 17 is RC2/ CCP1.
__________________
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 18th December 2007, 12:09 PM   (permalink)
Default

Oh, just one more thing, is the motor controller chip or transistors circuit OK?
__________________
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 18th December 2007, 02:54 PM   (permalink)
Default

i m using a motor driver to control the direction and speed of motor turning. form the motor driver connected with motor and got 3 pin is connect to ic. 1 pin is RC1 and another 2 is the direction of turning which can set at RC4 or RC5. exp RC4 turn clockwise, RC5 turn anticlock wise!!then the code is ok?
nelson_kh is offline   Reply With Quote
Old 19th December 2007, 12:08 AM   (permalink)
Default

Quote:
Originally Posted by nelson_kh
i m using a motor driver to control the direction and speed of motor turning. form the motor driver connected with motor and got 3 pin is connect to ic. 1 pin is RC1 and another 2 is the direction of turning which can set at RC4 or RC5. exp RC4 turn clockwise, RC5 turn anticlock wise!!then the code is ok?
So you're using RC1 to control the speed, RC4 and RC5 to switch direction?
You should use RC2 for PWM to control the speed, because RC2 is the dedicated pin for CCP1. Check data sheet.
__________________
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 19th December 2007, 01:32 PM   (permalink)
Default

Quote:
Originally Posted by Wingmax
So you're using RC1 to control the speed, RC4 and RC5 to switch direction?
You should use RC2 for PWM to control the speed, because RC2 is the dedicated pin for CCP1. Check data sheet.

yaya i use RC2 wrong type last time!!! but the motor still not turning! Y? i use PIC simulate to test and see the RC2 some time on sometime off!! how come.... it should keep 'on' to turn the motor!!
nelson_kh is offline   Reply With Quote
Old 20th December 2007, 02:02 AM   (permalink)
Default

Quote:
Originally Posted by nelson_kh
yaya i use RC2 wrong type last time!!! but the motor still not turning! Y? i use PIC simulate to test and see the RC2 some time on sometime off!! how come.... it should keep 'on' to turn the motor!!
Is there any way you can monitor the output on RC2, eg oscilloscope? The output on RC2 should not be on all the time. It's pulses. So what you saw on PIC simulator may be what you suppose to see.

I think your seting is 2 Khz, 50% duty cycle pulses?
If you can confirm (with oscilloscope may be) there are pulses with 500uS period ( 2 Khz), 250uS on and 250uS off (50 % duty cycle) on RC2. then you know your program is working.

May be your setup on the motor driver is incorrect? May be the motor draws too much current? You have to isolate which part is not working.
Hope this helps.
__________________
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 21st December 2007, 08:26 AM   (permalink)
Default

ya i using a software call PIC simulator that can see the output and set the input to the PIC!!ya i get the RC2 on and off so it is correct!! but when i test to the motor driver and the motor, the motor not turning!! i think is my board problem!!
nelson_kh is offline   Reply With Quote
Old 21st December 2007, 08:37 AM   (permalink)
Default

because you already set the output of RC2 to PWM mode at the beginning, so you will see it sometime is on and sometime is off. i think is your main broad got problem, design problem. you should fully understand how your motor driver circuit function and which pin you are chosing. Direct copy without understand is not a process of study.
since you are using the 20Mhz crystal, so in calculation the time will different. the duty cycle and the period is most important part in PWM. If setting is wrong, your motor ofcause cannot function and control speed.
antkids is offline   Reply With Quote
Old 23rd December 2007, 09:26 AM   (permalink)
Default

Quote:
Originally Posted by antkids
because you already set the output of RC2 to PWM mode at the beginning, so you will see it sometime is on and sometime is off. i think is your main broad got problem, design problem. you should fully understand how your motor driver circuit function and which pin you are chosing. Direct copy without understand is not a process of study.
since you are using the 20Mhz crystal, so in calculation the time will different. the duty cycle and the period is most important part in PWM. If setting is wrong, your motor ofcause cannot function and control speed.
Ya i count the PWM, duty cycle,CCPR1L, and the period as well!!! i know which pin that i am using!! For the motor driver or h-bridge all is almost the same. Can find at anywebsite. Anyway thz 4 reply and i got 1 question do anyone know wat is the different of 2k pulse and 4k pulse that use to count the PR2?? What will effeted??
nelson_kh is offline   Reply With Quote
Old 23rd December 2007, 12:55 PM   (permalink)
Default

Wingmax i success control the speed and the direction alr!!! THZ alot!!! from the code below i cjust change the CCPR2L to max or min then can change the speed ler!!! but i still not understand wat the pulse for!! exp 4K pulse and 2K pulse!!! hope to hear from u!! thz!!

here is the code!!

#include <pic.h>
__CONFIG(WDTDIS & XT & UNPROTECT & BORDIS & LVPDIS);
#define XTAL 20000000 //crystal frequency- 20MHz
void setup ()
{
TRISB = 0xFF;
TRISC = 0x00;
PORTC = 0x00;
CCPR2L = 0x00;
CCP2CON = 0b00011100;
T2CON = 0b01111111;
PR2 = 0x9C;
}



void main ()
{
setup ();
if (RB7==1)
{
PORTC = 0b00010000;
CCPR2L = 0xff;
}
else
{
PORTC = 0b00100000;
CCPR2L = 0xff;
}
}
nelson_kh is offline   Reply With Quote
Old 5th January 2008, 11:13 AM   (permalink)
Default

Quote:
Originally Posted by nelson_kh
Wingmax i success control the speed and the direction alr!!! THZ alot!!! from the code below i cjust change the CCPR2L to max or min then can change the speed ler!!! but i still not understand wat the pulse for!! exp 4K pulse and 2K pulse!!! hope to hear from u!! thz!!

here is the code!!

#include <pic.h>
__CONFIG(WDTDIS & XT & UNPROTECT & BORDIS & LVPDIS);
#define XTAL 20000000 //crystal frequency- 20MHz
void setup ()
{
TRISB = 0xFF;
TRISC = 0x00;
PORTC = 0x00;
CCPR2L = 0x00;
CCP2CON = 0b00011100;
T2CON = 0b01111111;
PR2 = 0x9C;
}

}
The pulses are for driving the motor.
CCPR2L is to set the duty cycle of the pulse, ie the pulse width. That's what's adjusting the speed. So what you did is adjusting the speed of min to max.
We normally choose a suitable frequency of the pulses for the motor so that it's not making annoying noise, or causing erratic function of the motor. We keep this frequency constant and adjust the motor speed by varying the pulse width 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
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 03:00 AM.


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