|
|
View previous topic :: View next topic |
Author |
Message |
HOHOHAHA
Joined: 13 Apr 2007 Posts: 24
|
PWM control 2 DC Motor |
Posted: Mon Oct 01, 2007 1:50 am |
|
|
hi I am trying to implement PWm on my 2 motors ..... motors are connected to a motor driving IC L298, this IC provides 2 different pis to enable 2 motors... I want 2 use CCP1 and CCP2 to control them by just changing the duty cycle ....
Code: |
setup_timer_2(T2_DIV_BY_1, 127, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(255);
setup_ccp2(CCP_PWM);
set_pwm2_duty(255);
|
later I will use 2 functions to change the duty cycle as required.... will my this piece of code enable CCP1 and CCP2 to run at same frequency ??
I use PIC16f877A and 4.049 ... another thing ... the resolution of PWM is 10 bit .... so it will provide a 5V(0n average ... long span of time) if I set it to 1023.. ? As I need to change the fuse bits of ADC=10 from 8(as default) in case of fuse bit ... do we need to do anything like that here ?
Thanks in advance ... |
|
|
Ttelmah Guest
|
|
Posted: Mon Oct 01, 2007 2:19 am |
|
|
You need to do one thing.
Add an 'L' to the '255' values.
The way the set pwm duty function works, is that if it receives a value defines as an 8bit number, it assumes the PWM generator is not using the extra two bits. If it receives a value defined as a 16bit number, it assumes the extra two bits are in use. Adding 'L' to a value below 256, tells the compiler to treat this as a 16bit value, and hand this to the function. Without the 'L', values of 255 and below, will otherwise be assumed to be 8bit, and as shown, the output will simply be permanently 'on'.
Best Wishes |
|
|
HOHOHAHA
Joined: 13 Apr 2007 Posts: 24
|
grt |
Posted: Mon Oct 01, 2007 3:12 am |
|
|
Bro you are great ...thanks a lot !
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|