如题, 在我将定时器1的ch4通道设置成比较中断之后, 我设置 TIM_OCInitStructure.TIM_Pulse = 0; 但是发现还是不停的进入比较中断,计数值 i 不停的在累加,进入中断,请问下是我哪配置错了吗,求解
配置代码:
TIM_OCInitTypeDef TIM_OCInitStructure;
/* PWM配置*/
TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_PWM1; //PWM模式1 2区别
TIM_OCInitStructure.TIM_OutputState =TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity =TIM_OCPolarity_High;
/*互补配置*/
TIM_OCInitStructure.TIM_OutputNState =TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_OCNPolarity =TIM_OCNPolarity_High;
// TIM_OCInitStructure.TIM_OCIdleState =TIM_OCIdleState_Reset; //刹车之后的输出状态
//TIM_OCInitStructure.TIM_OCNIdleState =TIM_OCNIdleState_Reset; //刹车之后的互补输出状态
TIM_OCInitStructure.TIM_Pulse =0; // 此处直接赋值设置占空比, 或者在其他地方调用TIM_SetCompare1(TIM1,3000);
// 也可以更改占空比,本程序是main函数中调用修改的占空比
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OC1Init(TIM8,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse =0;
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OC2Init(TIM8,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse =0;
TIM_OC3Init(TIM1,&TIM_OCInitStructure);
TIM_OC3Init(TIM8,&TIM_OCInitStructure);
//set adc sample time
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC4Init(TIM1, &TIM_OCInitStructure);
TIM_OC4Init(TIM8, &TIM_OCInitStructure);
//enable interrupt
TIM_ClearFlag(TIM1,TIM_FLAG_CC4);
TIM_ClearFlag(TIM8,TIM_FLAG_CC4);
TIM_ITConfig(TIM1, TIM_IT_CC4, ENABLE); //CCR4的中断,这个通过设置CCR4的pulse来控制产生中断相当于PWM-ON的位置
TIM_ITConfig(TIM8, TIM_IT_CC4, ENABLE);
中断代码:
u32 i;
void TIM1_CC_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1,TIM_IT_CC4) ==SET)
{
TIM_ClearITPendingBit(TIM1,TIM_IT_CC4);
Motor1_IValue =(float )ADC_Value[1]/ADC_PerCent*3.3;
i ++;
}
} |