Double independent PWM frequencies over 65 KHz with 33FJ12GP202

Started by Wimax, Apr 18, 2022, 04:55 PM

Previous topic - Next topic

Wimax

Hello Everybody !  ;D

I need to generate two PWM signals with a frequency greater than 65535 Hz, but I can't use Positron16's "HPWM" command. I use the "PWM_24.inc" routine (as recommended to me by Les some time ago) with a slight modification to handle 16 bit numbers.
I use these settings, but I see the same signal on both ports.

Declare CCP1_Pin PORTB.7
Declare CCP2_Pin PORTB.10
Include "PWM_24.inc"                      ' Load the Hardware PWM procedures into the program

PPS_Output(cOut_Pin_RP7, cOut_Fn_OC1)   ' Make RP7(RB7) the pin for  PWM1
PPS_Output(cOut_Pin_RP10, cOut_Fn_OC2)   ' Make RP10(RB10) the pin for  PWM2

then I call:

HPWM2_SetFreq(80000, 127)
HPWM1_SetFreq(100000, 127)

and I see the 100 KHz waveform on both ports...what I'm wrong ?



Wimax

Hi folks!

With calm and patience solved the arcane mystery.  ;D

The routines within the PWM24 file operate adaptively, determining the best prescaler configuration, using always Timer2 as the time base for the CCP units in the microcontroller.
This means that, in order to generate two PWM signals with different frequencies and duty cycles, the time base of the second CCP unit must be modified, enabling Timer3 by modifying the relative OCxCON register and using PR3 register where needed.