// 假设已经配置了定时器和中断
void TIMx_IRQHandler(void) {
if(TIM_GetITStatus(TIMx, TIM_IT_CC1) != RESET){
// 读取捕获值
uint32_t highTime = TIM_GetCaptureValue(TIMx, TIM_CHANNEL_1);
uint32_t lowTime = TIM_GetCaptureValue(TIMx, TIM_CHANNEL_2);
// 计算周期和占空比
uint32_t period = highTime + lowTime;
float dutyCycle = (float)highTime / period;
// 清除中断标志
TIM_ClearITPendingBit(TIMx, TIM_IT_CC1);
}
} |