2024-01-10 09:10 AM
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
2024-01-10 09:35 AM - edited 2024-01-10 09:35 AM
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.
2024-01-10 10:53 AM
With HAL, use HAL_TIM_PWM_Start() to enable PWM output.
Without HAL, set CCER register and MOE bit in BDTR.
2024-01-11 12:57 AM
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
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.
2024-01-18 05:57 AM
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);