Pravin Gosavi
Member
Hello I want to generate a PWM for my application. I am using PIC16F1939, MicroC and PICkit 2 to burn the program.
Here's my code-
void interrupt()
{
if (TMR2IF_bit == 1)
{
CCPR1L = 100;
TMR2IF_bit = 0;
}
}
void main()
{
C1ON_bit = 0;
C2ON_bit = 0; // Disable Comparators
TRISC = 0XFF;
PR2 = 249;
CCP1CON = 12;
CCPR1L = 0;
TMR2IF_bit = 0;
T2CON = 0X04;
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISC = 0X00;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1)
{
//Do other stuff
}
}
I replaced old crystal with a new one still no change. Crystal is 20MHZ. Frequency I get on the CCP pin is 500HZ only where according to the calculations it should be 20 KHZ. Also I replaced PIC16F1939 with PIC16F877A.
Where could be the problem? Please help!
Here's my code-
void interrupt()
{
if (TMR2IF_bit == 1)
{
CCPR1L = 100;
TMR2IF_bit = 0;
}
}
void main()
{
C1ON_bit = 0;
C2ON_bit = 0; // Disable Comparators
TRISC = 0XFF;
PR2 = 249;
CCP1CON = 12;
CCPR1L = 0;
TMR2IF_bit = 0;
T2CON = 0X04;
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISC = 0X00;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1)
{
//Do other stuff
}
}
I replaced old crystal with a new one still no change. Crystal is 20MHZ. Frequency I get on the CCP pin is 500HZ only where according to the calculations it should be 20 KHZ. Also I replaced PIC16F1939 with PIC16F877A.
Where could be the problem? Please help!