How do I restart a timer in one pulse mode after its overflow?
Maybe I am naive, but last year this code worked and now it doesn't...
I have this small lab experience where I manually implement PWM to control the brightness of the LEDs on a Nucleo F767ZI board. My idea was: let's ensure that the switching of the LEDs is synchronized with the overflow of the PWM timer (TIM6 to be precise) by setting the timer in one pulse mode, and restarting the timer in the period elapsed callback, after having switched the LEDs. The code of the callback is something like this:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if (htim->Instance == TIM6) {
PWM_status_high = /*alternatively true or false*/;
HAL_GPIO_WritePin(GPIOB, LD1_Pin|LD3_Pin|LD2_Pin, (PWM_status_high ?
GPIO_PIN_SET : GPIO_PIN_RESET));
htim->Instance->ARR = (PWM_status_high ? PWM_high_semiperiod : (PWM_MAX -
PWM_high_semiperiod));
HAL_TIM_Base_Start_IT(htim);
}
}
The problem is, the last call to HAL_TIM_Base_Start_IT fails because the timer is in state HAL_TIM_STATE_BUSY when invoked. As I said, the same code one year ago worked.
Can you spot what I am doing wrong? If my mistake is not immediately apparent tell me and I will post the STM32CubeIDE project. Of course I accept advices about possibly better approaches than mine.
Best,
Pietro
