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

Help with pwm!

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



Joined: 15 Feb 2012
Posts: 39
Location: italia

View user's profile Send private message AIM Address MSN Messenger ICQ Number

Help with pwm!
PostPosted: Wed Feb 15, 2012 7:31 am     Reply with quote

Hello everyone!
This is my first time here in this forum. I'm a mechatronics engineering student going to build my own quadcopter, so I need 4 pwm or ccp in my microcontroller pic. In fact I am so confused about the kind and number of PIC I'm gonna use!! So can anyone help me with a tutorial on how I program the pwm of a pic using the pwm pin (not the ccp because I know about it).
Thanks for reading this.
Ttelmah



Joined: 11 Mar 2010
Posts: 19332

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 8:53 am     Reply with quote

Not possible....
We can't talk about the PWM, without the CCP. Guess what the last 'P' in CCP means?.

The CCP _is_ the PWM module. The module has three different modes of operation 'capture' (records a count when an event occurs). 'Compare' (performs some event when a count matches a value), and 'PWM'. Generate a waveform with a programmed period and pulse width.

Now the first key thing is to distinguish PWM pins, from modules. A single CCP module, can only develop one 'timing' (width/period), but may be able to drive several outputs (simple single pulse train, full bridge, and half bridge typically), so may drive up to four pins. For four separate motors with four distinct speeds, you need four actual timing modules. A chip like perhaps the PIC18F25K80 (five modules), is about the smallest.

Then the basic code is the same for all modules. You have to set the timer to generate the frequency you want (will depend on the capacitances on the input pins of the FET's used for the drive, inductance's of the motors, how good your actual drivers are, etc. etc.), and then just setup the CCP to use CCP_PWM, and set the required duty cycle.
So:
Code:

setup_timer_2(T2_DIV_BY_16,249,1);
setup_ccp1(CCP_PWM); //CCP1 to CCP5
set_pwm1_duty(499L); //50% duty cycle

Then just adjust the value fed to the set_pwmX_duty function as needed.
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