Why in HardwareTimer FREQ_DUTY mode don't use timer slave reset Mode?

Post here first, or if you can't find a relevant section!
Post Reply
KiraVerSace
Posts: 2
Joined: Tue Oct 13, 2020 1:09 pm

Why in HardwareTimer FREQ_DUTY mode don't use timer slave reset Mode?

Post by KiraVerSace »

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.

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 */
only one attach interrupt could get the result, the Frequency_Dutycycle_measurement.ino is too complex.
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Why in HardwareTimer FREQ_DUTY mode don't use timer slave reset Mode?

Post by fpiSTM »

Hi @KiraVerSace

You are probably right this is not the best way to do this but this is only an example using basic HardwareTimer api provided by the core.
That's all ;)
Feel free to provide an example using HAL TIM and it could be added to the STM32Examples.
Post Reply

Return to “General discussion”