2021-10-14 02:06 AM
however, pwm1 doesn't output pulses. I think timer1 stop comparing output if calling Stop() function. Anyone has idea to implement this?
Thank you.
Solved! Go to Solution.
2021-10-14 07:41 AM
Which STM32?
Note, that disabling CCxE puts the given pin to Hi-Z. Also note that the complementary channel does not output inverted version of the waveform if CCxE is cleared.
Because of these minor but surprising features, it may be easier just swap the pins' setting in GPIO_MODER from AF to Out and vice versa.
I don't think you should seek Cube/HAL incantations for these things as they are beyond what Cube/HAL authors deem as "normal usage".
JW
2021-10-14 02:16 AM
Just don't connect the pwm output signal of the timer to any mcu pin....
2021-10-14 06:09 AM
HAL_TIM_PWM_Stop stops the timer. You can see this in the source code.
If you just want to disable that channel, clear the CC1E bit:
TIM1->CCER &= ~TIM_CCER_CC1E;
If you want to start output on CH1N, and the timer is already started, enable the CC1NE bit:
TIM1->CCER |= TIM_CCER_CC1NE;
If you really want to use HAL, you can use TIM_CCxChannelCmd/TIM_CCxNChannelCmd.
2021-10-14 07:41 AM
Which STM32?
Note, that disabling CCxE puts the given pin to Hi-Z. Also note that the complementary channel does not output inverted version of the waveform if CCxE is cleared.
Because of these minor but surprising features, it may be easier just swap the pins' setting in GPIO_MODER from AF to Out and vice versa.
I don't think you should seek Cube/HAL incantations for these things as they are beyond what Cube/HAL authors deem as "normal usage".
JW
2021-10-14 06:34 PM
thank You.
2024-04-08 09:39 AM
For the sake of completion and correctness I would like to clarify that the output for the complementary PWM channel can indeed be managed separately from the main output. This can be achieved by utilizing the following HAL functions, which are designed to selectively activate or deactivate the relevant bits:
To turn off the main channel and turn on the complementary channel, you can use the following code snippets:
Using HAL Functions:
// Turn off main channel (TIM_CHANNEL_1) TIM_CCxChannelCmd(TIM1, TIM_CHANNEL_1, TIM_CCx_DISABLE); // use TIM_CCx_DISABLE to enable // Turn on complementary channel (TIM_CHANNEL_1) HAL_TIMEx_OCN_Start(&htim1, TIM_CHANNEL_1); // use HAL_TIMEx_OCN_Start to stop
Using Direct Register Manipulation:
// Enable main output (Channel 1) TIM1->CCER |= TIM_CCER_CC1E; // Disable complementary output (Channel 1N) TIM1->CCER &= ~TIM_CCER_CC1NE;
Note that TIM_CCxChannelCmd expects a TIM_TypeDef *TIMx
while HAL_TIMEx_OCN_Star expects a TIM_HandleTypeDef *htim