Hello,
I am using PIC18F4520 microcontroller and building PWM.
According to this code:
void main(void) {
CCP1CON = 0; //Clear CCP1CON register
PR2 = 12; //19.5V
CCPR1L = 9; //81.025% Duty Cycle
TRISCbits.TRISC2 = 0; //Make PWM pin an output
T2CON = 0x01; //Timer 2
CCP1CON = 0x3C; //PWM Mode, 11 for DC1B1:DC1B2
TMR2 = 0; //Clear Timer 2
T2CONbits.TMR2ON = 1; //Turn ON Timer 2
while(1)
{
PIR1bits.TMR2IF = 0; //Clear Timer 2 Flag
while (PIR1bits.TMR2IF == 0); //Wait for end of period
}
}
And the calculation of PR2, i.e. PR2 = 8M/(38K* 4 *4) - 1 where 8M is crystal frequency and 38K is fpwm frequency. and 4 is prescaler.
And after simulating I got result for half of the frequency as shown in this linked image
https://postimg.cc/bDmWDq40 i.e. 20kHz. But why? Why I am not getting result for 38kHz?