高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-10-13
|
请各位大神帮忙看一下怎么回事。
void TIM_ICConfig(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3, TIM_IT_CC1) == SET) //ê¼t2′¥·¢£¬TIM_GetITStatus£¨£©£»¼ì2éÖ¸¶¨μÄITÖD¶Ï·¢éúóë·ñ
{ //êäèë2¶×½£¬ê1óÃCC12aá¿êäèëWMμÄÆμÂê
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1); //ê×Ï轫TIMX_CCRÇåáã
if(CaptureNumber_1 == 0)
{
/* Get the Input Capture value */
IC3ReadValue1_Old = TIM_GetCapture1(TIM3); //μÃμ½êäèë2¶»ñ1μÄÖμ
CaptureNumber_1 = 1;
}
else if(CaptureNumber_1 == 1)
{
/* Get the Input Capture value */
IC3ReadValue1 = TIM_GetCapture1(TIM3);
/* Capture computation */
if (IC3ReadValue1 > IC3ReadValue1_Old)
{
Capture_1 = (IC3ReadValue1 - IC3ReadValue1_Old);
}
else
{
Capture_1 = ((0xFFFF - IC3ReadValue1_Old) + IC3ReadValue1);
}
TIM3Freq_1 = (uint32_t) SystemCoreClock / Capture_1;
CaptureNumber_1 = 0;
}
}
|
|