Pic18f4520 pwm

Status
Not open for further replies.
I had to insert my own LCD library... ( Oh I also used AN0 instead of AN7 )..
 
Hi,

I think this little snippet in the interrupt routine might be causing you grief:

Code:
	if(Duty_cycle == 0)
	{
		PWM1_OUT = 0;
		}

Try commenting it out and test the result.
 
Hi,

Try this as your interrupt routine:

Code:
#pragma interrupt ccpisr_hand
void ccpisr_hand()
{
if(PIR1bits.CCP1IF == 1)
    
    if(PWM1_OUT == 1 )                      //Will be 1 if we are at end of pulse
    {
        PWM1_OUT = 0;
        CCPR1 = 5000 - temp;                //Off time
        }

    else
    {
        if(Duty_cycle > 0 && Duty_cycle < 97)
        {
            PWM1_OUT = 1;
            temp = 50 * (int) Duty_cycle;
            CCPR1 = temp;                   //On time
            }

    else PWM1_OUT = 0;
    }

    PIR1bits.CCP1IF = 0;                    //Clear int flag

}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…