当前位置:网站首页>When STM32 turns off PWM output, it is a method to fix IO output at high or low level.

When STM32 turns off PWM output, it is a method to fix IO output at high or low level.

2022-06-27 04:58:00 GZZXBCXM2005

See a lot of people on the Internet asking to stop PWM How to get the fixed output , Record here for reference .
Method 1: Set the duty cycle to 0xffff or 0 Then you can get what you want 0 or 1 Output .
Method 2 : Configure back to general IO mouth , Set it to 0 or 1.
The above two methods are found all over the Internet , But in many cases, it is not convenient to modify our duty cycle , It is necessary to maintain a fixed duty cycle , Just wanted to make PWM The following methods can be used to output or not output .
Method 3:
With TIM14 Of CHI For example
/* Set up GPIO Force output 0 /
TIM_SelectOCxM(TIM14,TIM_Channel_1,TIM_ForcedAction_InActive);
TIM_CCxCmd(TIM14,TIM_Channel_1,TIM_CCx_Enable);
/
Set up GPIO Force output 1 */
TIM_SelectOCxM(TIM14,TIM_Channel_1,TIM_ForcedAction_Active);
TIM_CCxCmd(TIM14,TIM_Channel_1,TIM_CCx_Enable);
The above can make PWM IO Direct output 0 or 1.

/* Restore the original duty cycle PWM Output */
TIM_SelectOCxM(TIM14,TIM_Channel_1,TIM_OCMode_PWM1);
TIM_CCxCmd(TIM14,TIM_Channel_1,TIM_CCx_Enable);

原网站

版权声明
本文为[GZZXBCXM2005]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270452079739.html