CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PWM control 2 DC Motor

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
HOHOHAHA



Joined: 13 Apr 2007
Posts: 24

View user's profile Send private message AIM Address

PWM control 2 DC Motor
PostPosted: Mon Oct 01, 2007 1:50 am     Reply with quote

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







PostPosted: Mon Oct 01, 2007 2:19 am     Reply with quote

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

View user's profile Send private message AIM Address

grt
PostPosted: Mon Oct 01, 2007 3:12 am     Reply with quote

Bro you are great ...thanks a lot !

Very Happy Very Happy Very Happy Very Happy Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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