Configure an PWM on a timer output.
Hi guys,
I am having a problem with the configurations for a PWM on an timer channel. I am working on a STM32L552ZE with LL library. I am tring to configure a PWM on pin PB9 (TIM17 CH1). I have first configuret as a PWM with interrupts (TIM17 update interrupt and in interrupt toggle pin) it works ok. But when I trie to configure it with OC I get nothing just the pin in 1.3V. To the pin I have connected only the base of an NPN transistor. Below you will find the code used to configure the PWM:
void Config_125kHzPWM(void)
{
LL_TIM_InitTypeDef TIM_InitStruct={0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct={0};
LL_GPIO_InitTypeDef GPIO_InitStruct={0};
/*Enable registers CLK*/
RCCCLK_ENABLE_DISABLE((uint32_t *)&RCC->AHB2ENR,RCC_AHB2ENR_GPIOBEN,ENABLE);
GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Alternate = LL_GPIO_AF_14;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
RCCCLK_ENABLE_DISABLE((uint32_t *)&RCC->APB2ENR,RCC_APB2ENR_TIM17EN ,ENABLE);
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
/* Set the default configuration */
TIM_InitStruct.Prescaler = (uint16_t)0x0000;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 0x00DCU;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV4;
TIM_InitStruct.RepetitionCounter = 0U;
LL_TIM_Init(TIM17, &TIM_InitStruct);
LL_TIM_EnableCounter(TIM17);
//LL_TIM_EnableIT_UPDATE(TIM17);
//LL_TIM_ClearFlag_UPDATE(TIM17);
//NVIC_SetPriority(TIM17_IRQn, 2);
//NVIC_EnableIRQ(TIM17_IRQn);
/* Set the default configuration */
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
TIM_OC_InitStruct.CompareValue = 0x006EU;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_HIGH;
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_HIGH;
LL_TIM_OC_Init(TIM17, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_EnablePreload(TIM17, LL_TIM_CHANNEL_CH1);
}
And in main i just execut this function.
The MCU APB clock is 110MHz.
Can someone point me to my mistake?
Thank you.
