cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8, How to stop PWM signal?

ERABALF
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

Read the timer section in the reference manual, particularly the OCxM field in the TIMx_CCMRx register, to force a particular output level.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
TDK
Guru

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

 

If you feel a post has answered your question, please click "Accept as Solution".
ERABALF
Associate III

I moved my comments to REPLY

ERABALF
Associate III

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.

Read the timer section in the reference manual, particularly the OCxM field in the TIMx_CCMRx register, to force a particular output level.

If you feel a post has answered your question, please click "Accept as Solution".

I will read it.

Thanks a lot for your comments.

Br

Alfredo