 |
 |
View previous topic :: View next topic |
Author |
Message |
benoitstjean
Joined: 30 Oct 2007 Posts: 575 Location: Ottawa, Ontario, Canada
|
PIC24EP512GP806 - Need 6 PWM's... |
Posted: Mon Apr 14, 2025 7:30 am |
|
|
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
|
|
Posted: Mon Apr 14, 2025 10:12 am |
|
|
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
|
|
Posted: Mon Apr 14, 2025 10:18 am |
|
|
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 |
|
 |
|
|
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
|