可行,不过捕获范围太小。于是用另外的定时器T2定时,T1四个通道捕获。
static void Init_TIM1(void)//1us
{
TIM1_DeInit();
TIM1_TimeBaseInit(15, TIM1_COUNTERMODE_UP, 0x6666, 0x00);//115us-26000us,0x6666=26214
/* 通道1,上升沿,映射在T1通道CH1-PC1,1分频,无滤波 */
GPIO_Init(GPIOC, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT);
TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0x00);
/* 通道2,上升沿,映射在T1通道CH2-PC2,1分频,无滤波 */
GPIO_Init(GPIOC, GPIO_PIN_2, GPIO_MODE_IN_PU_NO_IT);
TIM1_ICInit(TIM1_CHANNEL_2, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0x00);
/* 通道3,上升沿,映射在T1通道CH3-PC3,1分频,无滤波 */
GPIO_Init(GPIOC, GPIO_PIN_3, GPIO_MODE_IN_PU_NO_IT);
TIM1_ICInit(TIM1_CHANNEL_3, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0x00);
/* 通道4,上升沿,映射在T1通道CH4-PC4,1分频,无滤波 */
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_IN_PU_NO_IT);
TIM1_ICInit(TIM1_CHANNEL_4, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, 0x00);
TIM1_ITConfig(TIM1_IT_CC1, ENABLE);//捕获使能
TIM1_ITConfig(TIM1_IT_CC2, ENABLE);
TIM1_ITConfig(TIM1_IT_CC3, ENABLE);
TIM1_ITConfig(TIM1_IT_CC4, ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC1);
TIM1_ClearFlag(TIM1_FLAG_CC2);
TIM1_ClearFlag(TIM1_FLAG_CC3);
TIM1_ClearFlag(TIM1_FLAG_CC4);
TIM1_Cmd(ENABLE);//使能TIM1 |