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 CCS Technical Support

PIC24EP512GP806 - Need 6 PWM's...

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



Joined: 30 Oct 2007
Posts: 575
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PIC24EP512GP806 - Need 6 PWM's...
PostPosted: Mon Apr 14, 2025 7:30 am     Reply with quote

Device: PIC24EP512GP806
Compiler: 5.116

Hi again,

I need 6 PWM outputs on my device to drive 6 servos.

On another circuit, I use the following two to generate a 128kHz and 3.072MHz 50% signal:


Code:

#define XTAL_FREQ            29491200
#define SYS_CLOCK          129024000

#PIN_SELECT OC1  = PIN_D6                                                        // 128kHz PWM output -- PIN 54
#PIN_SELECT OC4  = PIN_D3                                                        // 3.072MHz PWM output -- PIN 51

setup_compare( 4, COMPARE_PWM_EDGE | COMPARE_TRIG_SYNC_TIMER3 | COMPARE_TIMER3 );
setup_timer3( TMR_INTERNAL | TMR_DIV_BY_1, PWM_VALUE_MCLK );
set_pwm_duty( 4, (( PWM_VALUE_MCLK + 1 ) / 2 ));


setup_compare( 1, COMPARE_PWM_EDGE | COMPARE_TRIG_SYNC_TIMER2 | COMPARE_TIMER2 );
setup_timer2( TMR_INTERNAL | TMR_DIV_BY_1, PWM_VALUE_BCLK_128 );
set_pwm_duty( 1, (( PWM_VALUE_BCLK_128 + 1 ) / 2 ));



I believe that there are only 5 OC pins but what about the 6th PWM if there are only 5 OC pins?

Will be going through the docs but thought I'd check here also.

Thanks,

Ben
Ttelmah



Joined: 11 Mar 2010
Posts: 19779

View user's profile Send private message

PostPosted: Mon Apr 14, 2025 10:12 am     Reply with quote

You are confusing yourself.
Historically, you can generate PWM's using the output compare. Correct.

However this chip has a separate PWM module that supports up to 7
outputs. These come on the PWMn pins.

So, don't use the output compare module, but the PWM module. However
this does not support PPS, so you have to use the PWM1L, PWM2L etc.
pins. You could use the H pins instead (the polarity is programmable).
This require different programming, but can give you severn separate
PWM modules.
benoitstjean



Joined: 30 Oct 2007
Posts: 575
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Apr 14, 2025 10:18 am     Reply with quote

Hmmm.... This is code I wrote about 10 years ago and when I got it to work back then, I never re-touched it nor had a reason to use PWM in another design just because the opportunity never came-up... so I will have to do some research because I have no idea how it works.

I will look at PWM1L and so on.

This is to control servo motors.

Thanks.

Ben
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