cancel
Showing results for 
Search instead for 
Did you mean: 

Timer 1 output pin not performing PWM

Leroy3
Associate II

Leroy3_0-1704906464221.png

I have defined PE9 as belonging to Timer 1;

I setup timer 1 as PWM as shown above.

When I enable the timer, nothing happens at PE9.

I tried setting force  high; no change

When I define PE9 as standard output forced high, it goes high.  So I know that the pin is connected correctly to the board.

But I'm not doing something to correctly setup PE9 as a PWM output

 

4 REPLIES 4
TDK
Guru

Set the MOE bit in TIM1->DIER register.

HAL will do this for you if you enable PWM in code. Show your code if it's not working.

Also possible you're starting the timer but not starting PWM output. Again, show code to diagnose. CubeMX initializes but doesn't start anything.

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

With HAL, use HAL_TIM_PWM_Start() to enable PWM output.

 

Without HAL, set CCER register and MOE bit in BDTR.

 

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Sarra.S
ST Employee

For advance timers only (TIM1, TIM8, TIM20), to get an output, you have to enable the main output of the timer which is the MOE bit 

SarraS_0-1704963366305.png

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Leroy3
Associate II

The answers given were helpful but not the full story.

Using the GUI for Timer1 was confusing and unsuccessful.

Here is the code that eventually worked

htim1.Instance = TIM1;
__HAL_RCC_TIM1_CLK_ENABLE();
/* Set the Time Base configuration */

//uint32_t ui32_tmpcr1;
// set to up, deactived, edge-aligned, no remap, no clock division; reload buffered
TIM1->CR1 = TIM_CR1_ARPE | TIM_CR1_URS;
/* COMPARE PULSE*/
TIM1->CR2 = (0x4 << TIM_CR2_MMS_Pos) | TIM_CR2_CCUS;
// set frequency to 100e6/5000 = 20Khz or 50 usec
TIM1->ARR = 5000;
/* prescaler to to 1 */
TIM1->PSC = 0;
/* no repetions */
TIM1->RCR = 0;
/* PWM */
TIM1->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE;
/* enable timer */
TIM1->CCR1 = 500;
TIM1->CR1 |= TIM_CR1_CEN;
TIM_CHANNEL_STATE_SET(&htim1, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);