Timer Encoder Mode, change HAL Filter after initialization
Hi all,
I'm using a Timer in Encoder Mode on STM32F103, using the HAL framework on STM32CubeIDE.
I would like to change encoder filter feature (IC1F[3:0]: Input capture 1 filter) depending on the behaviour selected in my MCU operation mode (so IC1Filter and IC2Filter) after the initialization of the timer has been made, so after HAL_TIM_Encoder_Init is called.
- Can I do this with no problem
- Do I have to Call HAL_TIM_Encoder_DeInit, set the values, then call HAL_TIM_Encoder_Init again if changing one of the values
- Do I have to restart the MCU after changing the values, and set it before the first timer initialization (so HAL_TIM_Encoder_Init)
I'm thinking on something like this: if there's no need to reinitialize the timer.
void TIM_Encoder_SetFilters(TIM_HandleTypeDef *htim, uint32_t IC1Filter, uint32_t IC2Filter)
{
assert_param(IS_TIM_IC_FILTER(IC1Filter));
assert_param(IS_TIM_IC_FILTER(IC2Filter));
uint32_t ccmr1 = htim->Instance->CCMR1;
ccmr1 &= ~(1U << 4) & ~(1U << 5) & ~(1U << 6); // clear bits
ccmr1 &= ~(1U << 12) & ~(1U << 13) & ~(1U << 14); // clear bits
ccmr1 &= (IC1Filter << 4U) | (IC2Filter << 12U); // set bits
htim->Instance->CCMR1 = tmpccmr1;
}
Thanks for your help.
