cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 Timer Frequency

AlexSmart
Senior
Posted on March 09, 2015 at 17:56

I can't understand how come TIM1 frequency is 42 MHz.

Here is my config:

12 MHz HSE -> 168 MHz PLLCLK (MCO/4 = 42 MHz, checked)

APB1 prescaler = 4

APB2 prescaler = 2

so TIM1, as it clocked from APB2 x 2 frequency should be 168 MHz.

But output (GPIO^PIN in update interrupt) generates 0.21 MHz frequency

0.21x100x2 = 42MHz.

RCC_PCLK1Config(RCC_HCLK_Div4);

RCC_PCLK2Config(RCC_HCLK_Div2);

RCC_HCLKConfig(RCC_SYSCLK_Div1);

TIM_TimeBaseStructure.TIM_Period                         = 99;

TIM_TimeBaseStructure.TIM_Prescaler                     = 0;

TIM_TimeBaseStructure.TIM_ClockDivision                 = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode                     = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

#tim #stm32
3 REPLIES 3
Posted on March 09, 2015 at 19:43

Odd, what do you see with this?

TIM_TimeBaseStructure.TIM_Period = 999;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

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 09, 2015 at 19:43

> (GPIO^PIN in update interrupt)

OK, so how long (in seconds or microseconds) does the pin remain in LOW state?

And how long does it remain in HIGH state?

The frequency is inverse of the WHOLE period, i.e. tLOW + tHIGH.

JW

AlexSmart
Senior
Posted on March 10, 2015 at 10:24

Thank you so much!

Problem was in

TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;