Author Topic: Why their is change in calculated and simulated frequency?  (Read 326 times)

0 Members and 1 Guest are viewing this topic.

Offline radhika

  • Regular Contributor
  • *
  • Posts: 101
  • Country: in
Why their is change in calculated and simulated frequency?
« on: October 15, 2018, 04:59:07 am »
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?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf