查看TIM_PWMIConfig的代码: if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1) { ... } else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2) { ... }
只有Tim_Channl_1,2,没有3,4,查看了相关代码和寄存器 1,2只是是设置CCMR1,而要3,4是要设置CCMR2 由于相关寄存器的高度对称性,因此只要添加如下代码: else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3) { /* TI1 Configuration */ TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection, TIM_ICInitStruct->TIM_ICFilter);
/* Set the Input Capture Prescaler value */ TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
/* TI2 Configuration */ TI4_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
/* Set the Input Capture Prescaler value */ TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); } else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_4) { /* TI2 Configuration */ TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection, TIM_ICInitStruct->TIM_ICFilter);
/* Set the Input Capture Prescaler value */ TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
/* TI1 Configuration */ TI3_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
/* Set the Input Capture Prescaler value */ TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); }
就可实现TI3FP3(对应TI1FP1),TI4FP4(对应TI2FP2)
|