2015-03-21 07:28 AM
Dear stm community,
I'm struggling with a problem that i can't get a timer to work. Im trying to get the PINE5 Timer to work.If I read everything well it has the TIM9_CH1 timer as alternating function.
So I wrote this code: </colgroup>PE5 P2.14
(64) 4 PE5 FT PE5 TRACED2 FSMC_A21 TIM9_CH1 DCMI_D6 void InitializeTimer() { int period = 500; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM9, ENABLE); TIM_TimeBaseInitTypeDef timerInitStructure; timerInitStructure.TIM_Prescaler = 40000; timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up; timerInitStructure.TIM_Period = period; timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; timerInitStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM9, &timerInitStructure); TIM_Cmd(TIM9, ENABLE); } void InitializePWMChannel() { TIM_OCInitTypeDef outputChannelInit = {0,}; outputChannelInit.TIM_OCMode = TIM_OCMode_PWM1; outputChannelInit.TIM_Pulse = 400; outputChannelInit.TIM_OutputState = TIM_OutputState_Enable; outputChannelInit.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM9, &outputChannelInit); TIM_OC1PreloadConfig(TIM9, TIM_OCPreload_Enable); GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_TIM9); } void Initializepin() { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitTypeDef gpioStructure; gpioStructure.GPIO_Pin = GPIO_Pin_5; gpioStructure.GPIO_Mode = GPIO_Mode_AF; gpioStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOE, &gpioStructure); } Can someone tell me where im making a mistake, or help me in the right direction? any help would be appreciated. Greetings
2015-03-21 09:34 AM
A cursory scan suggests it's not unreasonable. The order in which you call these functions would be important, and I'd probably double check if TIM9 supports PWM or not.
2015-03-22 11:39 PM
Isn't the GPIOE_AFRL.AFRL5 setting missing?
[EDIT] No, I can see it now, did expect it with other GPIO-related code. JW