how to enable or disenable the pwm geration CH1 or CH1N of stm32f4 respectivley in simulink ?
9 views (last 30 days)
Show older comments
how to enable or disenable the pwm geration CH1 or CH1N respectivley of stm32f4 cpu in simulink ?
the hardware of stm32 has the pwm out block,which can enable the ch1 ,ch2 and ch3 at the same time.
but i find no way to enable the ch1 and disenable ch1n at the same time.
in c code ,i have:
TIM_CCxCmd(BLDC_TIMx,TIM_Channel_1,TIM_CCx_Disable);
TIM_CCxCmd(BLDC_TIMx,TIM_Channel_1,TIM_CCxN_Enable);
TIM_CCxCmd(BLDC_TIMx,TIM_Channel_2,TIM_CCx_Enable);
how to do that in simulnk?
win11+2023b+stm32f4
0 Comments
Answers (1)
Nithin
on 22 Apr 2024
Hello,
There is no direct way to disable a particular channel from the PWM Output block at present. A workaround for this would be to add the LL_TIM_CC_DisableChannel function call in the System Outputs Custom Code block. Refer to the attached example model for your reference.
When the switch is enabled, the constant block value is set to 1 and the "Disable PWM CH1 and CH1N" subsystem is enabled and thus executed. This disables CH1 and CH1N resulting in a 0 output in both lines. When the switch is set to "off", the "Enable PWM CH1 and CH1N" subystem is enabled and the CH1 and CH1N channels are enabled again. One limitation in this approach is that the first argument to the LL_TIM_CC_DisableChannel function call, which is the timer handle needs to be hardcoded based on the timer module configured in the PWM Output block. In the attached model, since the timer module used is TIM1, the first argument passed to the funciton call is TIM1 as well. (This timer handler comes from the STM32CubeMX generated code)
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!