本帖最后由 loosens111 于 2016-7-13 10:40 编辑
用了原子的例程,是测量高电平时间的,现在有一个高低电平时间不定的波形需要测量周期,想要每个5个上升沿测量一次时间
这是原子例程
[mw_shl_code=applescript,true]void TIM5_IRQHandler(void)
{
if((TIM5CH1_CAPTURE_STA&0X80)==0)//»1Î′3é1|2¶»ñ
{
if (TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET)
{
if(TIM5CH1_CAPTURE_STA&0X40)//òѾ-2¶»ñμ½¸ßμçƽáË
{
if((TIM5CH1_CAPTURE_STA&0X3F)==0X3F)//¸ßμçƽì«3¤áË
{
TIM5CH1_CAPTURE_STA|=0X80;//±ê¼Ç3é1|2¶»ñáËò»′Î
TIM5CH1_CAPTURE_VAL=0XFFFF;//2¶»ñÖμ
}else TIM5CH1_CAPTURE_STA++;
}
}
if (TIM_GetITStatus(TIM5, TIM_IT_CC1) != RESET)//2¶»ñ1·¢éú2¶»ñê¼t
{
if(TIM5CH1_CAPTURE_STA&0X40) //2¶»ñμ½ò»¸öϽμÑØ
{
TIM5CH1_CAPTURE_STA|=0X80; //±ê¼Ç3é1|2¶»ñμ½ò»′ÎéÏéyÑØ
TIM5CH1_CAPTURE_VAL=TIM_GetCapture1(TIM5);
TIM_OC1PolarityConfig(TIM5,TIM_ICPolarity_Rising); //CC1P=0 éèÖÃÎaéÏéyÑØ2¶»ñ
}else //»1Î′¿aê¼,μúò»′Î2¶»ñéÏéyÑØ
{
TIM5CH1_CAPTURE_STA=0; //Çå¿Õ
TIM5CH1_CAPTURE_VAL=0;
TIM_SetCounter(TIM5,0);
TIM5CH1_CAPTURE_STA|=0X40; //±ê¼Ç2¶»ñμ½áËéÏéyÑØ
TIM_OC1PolarityConfig(TIM5,TIM_ICPolarity_Falling); //CC1P=1 éèÖÃÎaϽμÑØ2¶»ñ
}
}
}
TIM_ClearITPendingBit(TIM5, TIM_IT_CC1|TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}[/mw_shl_code]
下面是我的修改
[mw_shl_code=applescript,true]void TIM5_IRQHandler(void)
{
if((TIM5CH1_CAPTURE_STA&0X80)==0)//»1Î′3é1|2¶»ñ
{
if (TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET)
{
if(t<5)//òѾ-2¶»ñμ½¸ßμçƽáË
{
if((TIM5CH1_CAPTURE_STA&0X3F)==0X3F)//¸ßμçƽì«3¤áË
{
TIM5CH1_CAPTURE_STA|=0X80;//±ê¼Ç3é1|2¶»ñáËò»′Î
TIM5CH1_CAPTURE_VAL=0XFFFF;//2¶»ñÖμ
}else TIM5CH1_CAPTURE_STA++;
}
}
if (TIM_GetITStatus(TIM5, TIM_IT_CC1) != RESET)//2¶»ñ1·¢éú2¶»ñê¼t
{
if(t==0)
{
TIM5CH1_CAPTURE_STA|=0X40;
TIM_SetCounter(TIM5,0);
TIM5CH1_CAPTURE_VAL=0;
t++;
TIM5CH1_CAPTURE_STA&=!0X80;
}
if(t<5&&t>0)
{t++;}
if(t==5)
{
TIM5CH1_CAPTURE_STA|=0X80;
TIM5CH1_CAPTURE_VAL=TIM_GetCapture1(TIM5);
TIM5CH1_CAPTURE_STA&=!0X40;
t=0;
}
}
}
TIM_ClearITPendingBit(TIM5, TIM_IT_CC1|TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}[/mw_shl_code]
怎么也得不出正确时间,焦头烂额两天了,请各位指教一下。非常感谢!
开启定时器自由计数,
输入作为中断,上升沿触发。
一周热门 更多>