Skip to main content
ERABALF
Associate III
December 11, 2021
Solved

STM32F103C8, How to stop PWM signal?

  • December 11, 2021
  • 2 replies
  • 2862 views

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

This topic has been closed for replies.
Best answer by TDK

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

2 replies

TDK
December 11, 2021

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
ERABALFAuthor
Associate III
December 12, 2021

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.

TDK
TDKBest answer
December 13, 2021

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""."
ERABALF
ERABALFAuthor
Associate III
December 12, 2021

I moved my comments to REPLY