2021-08-04 08:56 AM
Hi
I would like to know if the following code can be used to set the PWM to a constant 0.
TIM_OC_InitTypeDef sConfigOC = {0};
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if ( HAL_TIM_PWM_ConfigChannel ( &htim12, &sConfigOC, TIM_CHANNEL_2 ) != HAL_OK )
If that is wrong, could someone let me know what is the right code? thanks
2021-08-04 09:18 AM
Seems right. If not, flip the polarity.
Did you try it?
The code you linked doesn't actually start the PWM. Presumably you are starting it and the associated timer elsewhere.
2021-08-04 09:20 AM
Have you already tried HAL_TIM_PWM_Stop() and did that not work? I would've thought just disabling PWM and perhaps set the pin low would be ok.
2021-08-04 09:41 AM
HAL_TIM_PWM_Stop() most probably (I am not going to look it up) clears TIMx_CCER.CCxE and that effectively threestates the pin, which is different from setting it to 0.
JW