- 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的中断优先级,中断使能,但是进入不中断函数。
请帮忙看下问题出在哪里了。
|