cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Timer pinE5

remco
Associate
Posted on March 21, 2015 at 15:28

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
2 REPLIES 2
Posted on March 21, 2015 at 17:34

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 23, 2015 at 07:39

Isn't the GPIOE_AFRL.AFRL5 setting missing?

[EDIT] No, I can see it now, did expect it with other GPIO-related code.

JW