打印

PIC进不了OC1中断函数

[复制链接]
1150|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hlhfootbal|  楼主 | 2015-1-24 17:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void initPWM()
{
        //PPSUnLock;
        iPPSOutput(OUT_PIN_PPS_RP7,OUT_FN_PPS_OC1);    //configure RP7 as OC1
        //PPSLock;

        T2CONbits.TCS = 0;        //choose the internal clock
       
        /*set the PWM frequency as 61Hz*/
        PR2 = 0XFFFF;
        T2CONbits.TCKPS = 0;
               
        OC1R = 0X7FFF;        //the time to the rising edge of the output pluse
        OC1RS = 0X7FFF;        //the time to the falling edge of the pulse,should less or equal to PR2
        IPC0bits.OC1IP = 0X7;//interrupt is priority 7
        IEC0bits.OC1IE = 1;//enable OC1 interrupt
        OC1CONbits.OCM = 6;        //initialize OC1 pin low,generate continous output pulses
        OC1CONbits.OCTSEL = 0;        //select timer2
        T2CONbits.TON = 1;        //start 16 bit timer2
}

/*void __attribute__((__interrupt__, no_auto_psv)) _T2Interrupt()
{
        IFS0bits.T2IF = 0;        //clear timer 2 interrupt flag
   
}*/

void __attribute__((__interrupt__, no_auto_psv)) _OC1Interrupt()
{
        IFS0bits.OC1IF = 0;        //clear OC1 interrupt flag
        flag = 1;
}

/*change duty cycle from 50% to 98% continous*/
void PWMDutyChange()
{

        if(OC1RS <= 0XFAE0)
                OC1RS = 0X7FFF + 0X0001;
        else
                OC1RS = 0X7FFF;

        flag = 0;
}

nt main()
{
        TRISBbits.TRISB14= 0;                         //P1B4 is output,control D8;
        LATBbits.LATB14 = 0;
        initPWM();

Try:       
        LATBbits.LATB14 = 0;
        Delay_ms(16);
        while(!flag);
                //{
                        PWMDutyChange();
                        LATBbits.LATB14 = 1;
                        Delay_ms(16);
                //}
goto Try;
       
        return success;
}
以上程序想实现的功能:实时改变PWM的输出占空比。

我使能了0C1的中断优先级,中断使能,但是进入不中断函数。
请帮忙看下问题出在哪里了。
沙发
hlhfootbal|  楼主 | 2015-1-24 22:39 | 只看该作者
知道了,PWM模式,应该使能timer中断,而不是OC中断。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

133

主题

417

帖子

1

粉丝