AnsweredAssumed Answered

STM32F205 TIM5 PWM frequency calculation?

Question asked by Martin on Oct 10, 2013
Latest reply on Oct 10, 2013 by Martin
Hi,

I will output a PWM Signal on a STM21F205 Pin A3 and use the following code:

GPIO_InitTypeDef    GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
 
/* Clock für GPIOA einschalten */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
 
// PA3 kommt auf timer5 für PWM
// Clock für Timer 5 ein
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
 
GPIO_StructInit(&GPIO_InitStructure); // Reset init structure
 
GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure );
 
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5);
 
TIM_TimeBaseStructInit( &TIM_TimeBaseInitStruct );
 
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV4;
TIM_TimeBaseInitStruct.TIM_Period = 1000 - 1;   // 0..999
TIM_TimeBaseInitStruct.TIM_Prescaler = 240 - 1; // Div 240
TIM_TimeBaseInit( TIM5, &TIM_TimeBaseInitStruct );
 
TIM_OCStructInit( &TIM_OCInitStruct );
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
 
TIM_OCInitStruct.TIM_Pulse = 500;
TIM_OC4Init( TIM5, &TIM_OCInitStruct );
 
TIM_Cmd( TIM5, ENABLE );

I can measure a PWM with 250 Hz. But why?

Thanks Martin

Outcomes