PIC进不了OC1中断函数

[复制链接]
1438|1
 楼主| hlhfootbal 发表于 2015-1-24 17:26 | 显示全部楼层 |阅读模式
  1. void initPWM()
  2. {
  3.         //PPSUnLock;
  4.         iPPSOutput(OUT_PIN_PPS_RP7,OUT_FN_PPS_OC1);    //configure RP7 as OC1
  5.         //PPSLock;

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

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

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

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

  33.         if(OC1RS <= 0XFAE0)
  34.                 OC1RS = 0X7FFF + 0X0001;
  35.         else
  36.                 OC1RS = 0X7FFF;

  37.         flag = 0;
  38. }

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

  44. Try:       
  45.         LATBbits.LATB14 = 0;
  46.         Delay_ms(16);
  47.         while(!flag);
  48.                 //{
  49.                         PWMDutyChange();
  50.                         LATBbits.LATB14 = 1;
  51.                         Delay_ms(16);
  52.                 //}
  53. goto Try;
  54.        
  55.         return success;
  56. }
以上程序想实现的功能:实时改变PWM的输出占空比。

我使能了0C1的中断优先级,中断使能,但是进入不中断函数。
请帮忙看下问题出在哪里了。
 楼主| hlhfootbal 发表于 2015-1-24 22:39 | 显示全部楼层
知道了,PWM模式,应该使能timer中断,而不是OC中断。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

133

主题

417

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部