Why in HardwareTimer FREQ_DUTY mode don't use timer slave reset Mode?
Posted: Tue Dec 17, 2024 2:32 am
After read the source code and Frequency_Dutycycle_measurement.ino, I found that use the capture the CC and timer count to calculate the duty and frequency, but there is a more convenient method.
Eg: Let the TIM1 work in slave mode(reset mode), and use TI1FP1 as trigger source.
only one attach interrupt could get the result, the Frequency_Dutycycle_measurement.ino is too complex.
Eg: Let the TIM1 work in slave mode(reset mode), and use TI1FP1 as trigger source.
Code: Select all
/* USER CODE BEGIN 4 */
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
//注意这里为HAL_TIM_ACTIVE_CHANNEL_1而不是TIM_CHANNEL_1
{
PWM_RisingCount = HAL_TIM_ReadCapturedValue(&htim3,TIM_CHANNEL_1);
duty = (float)PWM_FallingCount / PWM_RisingCount;
}
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
{
PWM_FallingCount = HAL_TIM_ReadCapturedValue(&htim3,TIM_CHANNEL_2);
}
}
/* USER CODE END 4 */