2021-12-11 12:22 PM
Hi ST Community.
I need your help. I am working on a PWM Proyect, Duty cicle must be change every period, and there is delta time where the PWM must be OFF.
I am using a Timer, it fire an interrution and this interruption set a flag to 1 in order to reload the CCRX:
TIM2->CCR1=lookUptable1[LookUpTableIndiceUsar_R]
so far, the issue that I can´t handle is when I need to STOP the PWM, i am using:
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);
But PWM generation continue working......
Can you guide/help me please.
Thanks in advance.
Br
Alfredo
Solved! Go to Solution.
2021-12-12 04:54 PM
Read the timer section in the reference manual, particularly the OCxM field in the TIMx_CCMRx register, to force a particular output level.
2021-12-11 12:58 PM
You could just stop the timer.
TIM2->CR1 &= ~TIM_CR1_CEN;
You could set the CCR1 value to zero or max depending on the polarity you want (as long as ARR is less than max).
TIM2->CCR1 = 0;
TIM2->CCR1 = 0xFFFFFFFF;
That said, the HAL_TIM_PWM_Stop call should work, so there may be something else going on in your code which explains the results you're seeing. It disables the timer right here:
https://github.com/STMicroelectronics/STM32CubeF1/blob/c750eab6990cac35ab05020793b0221ecc1a8ce5/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c#L1497
2021-12-12 02:47 PM
I moved my comments to REPLY
2021-12-12 02:47 PM
Thanks for your answer TDK.
TIM2->CR1 &= ~TIM_CR1_CEN; will STOP all PWM channels from TIM2?
I need to STOP just one and all three channels must continue working in TIM2, is it possible?
I will test loading TIM2->CCR1=0; for example, but I need to check with Oscilloscope if this change it is not generating anything as output ( I mean, the channel is always in zero)
in few words: I need the PWM channel generate 1500 Period (each period using different Duty Cycle) and next 1500 periods, the PMW channel must remain in ZERO (no activity)
Any comment, any advice is welcome.
Br
Alfredo.
2021-12-12 04:54 PM
Read the timer section in the reference manual, particularly the OCxM field in the TIMx_CCMRx register, to force a particular output level.
2021-12-12 06:56 PM
I will read it.
Thanks a lot for your comments.
Br
Alfredo