新手上路
- 积分
- 26
- 金钱
- 26
- 注册时间
- 2017-7-21
- 在线时间
- 9 小时
|
5金钱
本帖最后由 Leessang 于 2017-7-27 16:53 编辑
我设置的是一秒钟产生一次溢出中断,void TIM2_IRQHandler(void){
/* timer interrupt */
//单独使用下面六行代码的时候是一秒钟产生一次溢出中断,但是将下面代码一起使用的时候一秒钟就要产生好几次溢出中断,这是为啥啊
if (TIM_GetITStatus(TIM2, TIM_IT_Update) !=RESET)
{
cnt++;
printf("cnt=%d\r\n", cnt);
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
}
//PWM输入捕获中断
if(TIM_GetITStatus(TIM2,TIM_IT_CC2) !=RESET)
{
/* Get the Input Capture value */
IC1Value = TIM_GetCapture1(TIM2);
IC2Value = TIM_GetCapture2(TIM2);
whole = IC2Value;
falling = IC1Value;
// Frequency = SystemCoreClock / IC2Value;
// DutyCycle = (IC1Value * 100) / IC2Value;
if((cnt > 0) && (cnt < 60))
{
//如果故障
if((TIM_GetCapture2(TIM2) > 2*whole)||(TIM_GetCapture1(TIM2) > 2*falling))
{
cnt = 0;
}
printf("IC1Value=%d\r\n", IC1Value);
printf("IC2Value=%d\r\n", IC2Value);
}
else if((cnt > 60) && (cnt < 70))
{
//计算
Frequency1 = SystemCoreClock / IC2Value;
DutyCycle1 = (IC1Value * 100) / IC2Value;
// printf("DutyCycle1=%d\r\n", DutyCycle1);
// printf("Frequency1=%d\r\n", Frequency1);
}
else if(cnt >70)
{
Frequency = SystemCoreClock / IC2Value;
DutyCycle = (IC1Value * 100) / IC2Value;
// printf("DutyCycle=%d\r\n", DutyCycle);
// printf("Frequency=%d\r\n", Frequency);
if((Frequency == Frequency1)&&(DutyCycle == DutyCycle1))
{
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
GPIO_ResetBits(GPIOF,GPIO_Pin_7);
}
else
{
//报警
GPIO_SetBits(GPIOB,GPIO_Pin_2);
}
if((DutyCycle < 48) && (DutyCycle > 0))
{
GPIO_ResetBits(GPIOF,GPIO_Pin_8);
}
else if((DutyCycle < 52) && (DutyCycle >= 48))
{
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
}
else if(DutyCycle >= 52)
{
GPIO_ResetBits(GPIOF,GPIO_Pin_10);
}
}
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
}
}
|
|