2013-10-09 11:20 PM
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
2013-10-10 05:02 AM
I can measure a PWM with 250 Hz. But why?
Probably because your APB1 clock is 30 MHz and TIM5CLK is 60 MHz (check system_stm32f2xx.c) 60,000,000 / (240 * 1,000) = 2502013-10-10 07:14 AM
Hello Clive,
That makes sense to me ;)But what aboutTIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV4;?
Martin2013-10-10 08:57 AM
Pretty sure that has zero impact on the time base, if I recall it relates to the clock used for dead-time generation and filtering elements.
2013-10-10 09:28 AM