Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Feb 15, 2012 8:53 am |
|
|
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. |
|