2023-04-12 01:46 AM
Hello! I am working on PWM generation using several timers, in this case: TIM3, TIM4, TIM8, TIM15. I have gotten TIM3, TIM4 and TIM8 to work perfectly. I am currently testing this on a STM32F3DISCOVERY board. TIM15 however, does not behave properly for me. It uses the same code as for the other general purpose timers I use (Besides the code for CCR3 and CCR4 of course.
In this case, I use PF9 and PF10 with AF3 enabled. The registers show that AF3 is selected for these.
RCC Configuration:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);
RCC_AHBPeriphClockCmd((RCC_AHBPeriph_GPIOF), ENABLE);
GPIO configuration:
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_PinAFConfig(GPIOF, GPIO_PinSource9, GPIO_AF_3);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource10, GPIO_AF_3);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIO_InitStruct);
Code for the TimeBaseStructure config:
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/*Fill struct with default values*/
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
/*Prescale AHB clock to give 64KHz*/
TIM_TimeBaseStructure.TIM_Prescaler = (1000 - 1);
/*Set the time ARR (auto-reload register value) to 64000*/
TIM_TimeBaseStructure.TIM_Period = (uint16_t)(64000 - 1);
/*No clock division and counting up to the ARR (auto-reload register) value*/
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
/*Initialize struct*/
TIM_TimeBaseInit(PWMTIMERx, &TIM_TimeBaseStructure);
OCInitStructure:
TIM_OCInitTypeDef TIM_OCInitStructure;
/*Fill struct with default values*/
TIM_OCStructInit(&TIM_OCInitStructure);
/*Setup for PWM modulated output signal*/
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
/*Set the pulse width (duty cycle) to 0 initially*/
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(PWMTIMERx, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(PWMTIMERx, TIM_OCPreload_Enable);
TIM_OC2Init(PWMTIMERx, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(PWMTIMERx, TIM_OCPreload_Enable);
I did consider whether the PF9 and PF10 pins was connected to an internal function on the STMF3DISCOVERY, but I could perform a GPIO_SetBits without issues, and setting both to high/low, and the datasheet did not mention that it was used for anything. The issue is that i get no PWM output whatsoever on PF9 or PF10. I did my best to compare the registers between one of my working General purpose timers and TIM15, but they looked identical to me. Am I missing a small crucial step here?
Thank you in advance!
Solved! Go to Solution.
2023-04-12 05:50 AM
Hi! For anyone else having this issue, I found out my issue:
The following line had to be added, I thought it was only for advanced timers.
TIM_CtrlPWMOutputs(TIM15, ENABLE);
2023-04-12 05:11 AM
Check the TIMx->CCER register, which is modified by HAL_TIM_PWM_Start().
2023-04-12 05:50 AM
Hi! For anyone else having this issue, I found out my issue:
The following line had to be added, I thought it was only for advanced timers.
TIM_CtrlPWMOutputs(TIM15, ENABLE);