PWM off
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-04 8: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
- Labels:
-
STM32Cube MCU Packages
-
STM32H7 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-04 9: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-04 9: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-04 9: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
