你好梁工,我在中断里更新T2的值还是会出现反转的情况,在某个周期里T2没反转电平,代码如下
- void pwminit(void)
- {
- //IP2 |=0x04;
- P_SW2 |= 0x80;
- PWMCFG = 0x00;
- PWMCKS = 0x01;
- PWMC = CTL_CYCLE;
- PWM3CR = 0x00;
- PWM3T1 = 0x00;
- PWM3T2 = CTL_CYCLE/2;
- PWMCR |= 0xc0;
- P_SW2 &=~0x80;
- }
- void PWM_int(void) interrupt 22
- {
- if(PWMIF & 0x40)
- {
- PWMIF &=~0x40;
- ceshi=!ceshi;
- if((ctl_duty>0)&&(ctl_duty<100))
- {
- if(last_pwmt2_count!=pwmt2_count)
- {
- last_pwmt2_count=pwmt2_count;
- P_SW2 |= 0x80;
- PWM3T2 = pwmt2_count;
- PWMCR |= 0x02; //设置为pwm输出口
- P_SW2 &=~0x80;
- }
- }else if(ctl_duty>=100)
- {
- PWMCR &=~0x02;
- ctl_pul=1;
- }else if(ctl_duty<=0)
- {
- PWMCR &=~0x02;
- ctl_pul=0;
- }
- }
- }
复制代码
|