[SOLVED] PIC16f876a PWM Help!!!!!!!!

Status
Not open for further replies.

malik_zohaib

Full Member level 5
Joined
Sep 1, 2010
Messages
261
Helped
36
Reputation
72
Reaction score
35
Trophy points
1,308
Location
Pakistan
Activity points
2,707
Hi guys
I am using the hi-tech compiler and above mentioned pic. I want to generate the pwm signal at pin rc2. My code is :
Code:
void main(){

    //generate 2khz freq with 50% duty cycle at rc2.

    TRISC=0;
    PORTC=0;
    //TMR2=0;
    
    PR2=155;
    T2CON=0x7;
    CCPR1L=0x4E;
    CCP1CON=0b00011111;
//    CCP1X=0;
//    CCP1Y=1;    


    while(1){

}
    

}

Crystal freq is 20MHz. I have done all this according to the datasheet (pg #60).
But the problem is my code is not generating anything. Is the code is ok?? Everything is complete? or i missed something???

Regards.
 

Hello guys!!
Long time no reply??????
Does anyone knows programming here???????


.......... my bad......i guess........
 

i will try to do it the other way,

let's hope that our masters might read this and help us out of this problem...
 

Hi guys after all i am able to solve the problem. Below is the code of mine (slightly changed). I hope it ll help the other people having the same problem.
Code:
#include <htc.h>
#include <pic.h>



    //generate 10khz freq with 50% duty cycle at rc2.


#define _XTAL_FREQ 20000000
#define sw RB0
main(void)
{
TRISC=0;
TRISB=1;

PR2=124;
T2CON=5;

for(;;)
{
if(sw==0)
{

CCPR1L=62;
CCP1CON=0x0C;//neglecting two bits
}
else
{
CCPR1L=0xE1;
CCP1CON=0x0C;
}
}
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…