各位好,最近在做PWM捕获的程序,但是做到现在发现只有TIM1 的ch1可以捕获,其他路有获取不到,下面是小弟的源程序,请大神帮忙看看
TIM初始化
void TIME1_INIT_1(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(15, TIM1_COUNTERMODE_UP, PWM_FERQ-1, 0);
TIM1_ICInit( TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI , TIM1_ICPSC_DIV8, 0x0);
TIM1_ITConfig( TIM1_IT_CC1 , ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC1);
TIM1_Cmd(ENABLE);
}
void TIME1_INIT_2(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(15, TIM1_COUNTERMODE_UP, PWM_FERQ-1, 0);
TIM1_ICInit( TIM1_CHANNEL_2, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI , TIM1_ICPSC_DIV8, 0x0);
TIM1_ITConfig( TIM1_IT_CC2 , ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC2);
TIM1_Cmd(ENABLE);
}
void TIME1_INIT_3(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(15, TIM1_COUNTERMODE_UP, PWM_FERQ-1, 0);
TIM1_ICInit( TIM1_CHANNEL_3, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI , TIM1_ICPSC_DIV8, 0x0);
TIM1_ITConfig( TIM1_IT_CC3 , ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC3);
TIM1_Cmd(ENABLE);
}
void TIME1_INIT_4(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(15, TIM1_COUNTERMODE_UP, PWM_FERQ-1, 0);
TIM1_ICInit( TIM1_CHANNEL_4, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI , TIM1_ICPSC_DIV8, 0x0);
TIM1_ITConfig( TIM1_IT_CC4 , ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC4);
TIM1_Cmd(ENABLE);
}
IO初始化
GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOC,GPIO_PIN_4,GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOC,GPIO_PIN_3,GPIO_MODE_IN_FL_NO_IT);
中断函数
if(TIM1_GetITStatus(TIM1_IT_CC1))
{
TIM1_ClearITPendingBit(TIM1_IT_CC1);
IC1Value=TIM1_GetCapture1();
i++;
if(i==0xff)
i=0;
}
if(TIM1_GetITStatus(TIM1_IT_CC2))
{
TIM1_ClearITPendingBit(TIM1_IT_CC2);
IC2Value=TIM1_GetCapture2();
i++;
if(i==0xff)
i=0;
}
if(TIM1_GetITStatus(TIM1_IT_CC3))
{
TIM1_ClearITPendingBit(TIM1_IT_CC3);
IC3Value=TIM1_GetCapture3();
i++;
if(i==0xff)
i=0;
}
if(TIM1_GetITStatus(TIM1_IT_CC4))
{
TIM1_ClearITPendingBit(TIM1_IT_CC3);
IC4Value=TIM1_GetCapture4();
i++;
if(i==0xff)
i=0;
}
在使用上面函数是只有在初始化TIME1_INIT_1()也就是CH1才能捕获到PWM波形,其他都不行。
|
|