![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Guru Narasimha V S
Joined: 05 Aug 2022 Posts: 5
|
How to use PWM slice in PIC18F47Q43?[SOLVED] |
Posted: Fri Aug 05, 2022 12:41 am |
|
|
I am a beginner to the PIC controllers. Trying to generate 4 PWM signals using PIC18F47Q43.
Used 3 CCP modules one with PWM slicing.
But could not turn on the fan.
It would be really helpful if I get this issue solved.
Need to know to how to use PWM slicing properly to generate PWM signals.
Code: |
#pin_select CCP1OUT = PIN_C2
#pin_select CCP2OUT = PIN_C5
#pin_select CCP3OUT = PIN_B5
#pin_select PWM2S1P2 = PIN_C1
void main(void)
{
enable_interrupts(GLOBAL);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
setup_pwm2_slice(1, PWM_STANDARD);
setup_timer_2(T2_DIV_BY_2, 250, 1);
while(1)
{
set_pwm1_duty(200);
set_pwm2_duty(1, 200, 200);
set_pwm3_duty(200);
}
} |
Last edited by Guru Narasimha V S on Thu Sep 01, 2022 4:01 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Aug 09, 2022 1:04 am |
|
|
First, if you are a beginner, trying to start with one of the newest most
complex PIC's, is not a sensible way of going.
Now, that having been said, several comments on using the slice PWM:
First you are trying to program it to an unsupported pin. If you are
using the 47Q43, the PWM2 pins can only go to ports B and ports D.
Table 21-2 in the data sheet. Look at the columns for 40 pin devices.
You can put the PWM1 pins onto port C.
Then you are not telling the PWM what to use as a clock. Understand that
the standard CCP PWM's all by default use Timer2, but the slice PWM's
use a separate clock. They have their own internal 16bit timers, and
these have to be clocked from something. Look at the PWM_CLK_ entries
for these.
Then understand that these are 16bit PWM's. With the standard PWM's, the
'period' is determined by the timer. With these you have to separately set
the period to be used. set_pwm2_period.
As a comment, why are you using slice2?. More simple to just use
the slice1 output, so the first number is the duty for this slice.
Then understand that with the standard PWM's, the duty values you show
won't work. You need to tell the function that these are 16bit values, so
set_pwm1_duty(200L);
Note the 'L'.
Then add a delay in the loop. Currently you are continuously resetting the
period before even a single cycle can execute.
These are the obvious problems I can see... |
|
![](templates/subSilver/images/spacer.gif) |
Guru Narasimha V S
Joined: 05 Aug 2022 Posts: 5
|
|
Posted: Wed Aug 10, 2022 4:29 am |
|
|
Hi Ttelmah ,
Thank you very much, information helped me a lot and I could get the fans running.
The updated code:
Code: |
#pin_select CCP1OUT = PIN_C2
#pin_select CCP2OUT = PIN_C5
#pin_select CCP3OUT = PIN_B5
#pin_select PWM1S1P2 = PIN_C1
void main(void)
{
enable_interrupts(GLOBAL);
setup_pwm1(PWM_ENABLED | PWM_CLK_FOSC | PWM_CLK_DIV_BY_8, 249);
setup_pwm1_slice(1, PWM_STANDARD);
setup_timer_2(T2_DIV_BY_2, 250, 1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
while(1)
{
set_pwm1_duty(200);
set_pwm2_duty(200);
set_pwm3_duty(200);
set_pwm1_duty(1, 200L, 200L);
delay_ms(100);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Aug 10, 2022 9:47 am |
|
|
Good.
The clocking was the critical bit. ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|