We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
It's my first project with STM32 and ST firmware library. I have a problem with my timer configuration. I want a cyclic timer 2 interrupt all 100 us (10 kHz). So I configured the timer:
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure ); TIM_TimeBaseStructure.TIM_Period = 100; TIM_TimeBaseStructure.TIM_Prescaler = 35; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit( TIM2, &TIM_TimeBaseStructure ); TIM_ITConfig( TIM2, TIM_IT_Update, ENABLE ); TIM_Cmd( TIM2, ENABLE );
Notes: TIM2CLK is 36 MHz. Prescaler = 35 ==> TIM2 counter clock = 1 MHz - because TIM2 counter clock = TIM2CLK / (Prescaler +1) Auto reload preload value: 1 MHz / 10 kHz = 100
So I expected an timer 2 interrupt all 100 ms. But when my program runs at my ST STM3210B evaluation board or in the simulator, the interrupt comes all 50 us (20 kHz).
What is wrong? - Any idea?
Thanks in advance, Norbert
the clock generation for the timers are well documented in the STM32 reference manual chapter Clocks in Reset and clock control (RCC): The timer clock frequencies are automatically fixed by hardware. There are two cases: 1. if the APB prescaler is 1, the timer clock frequencies are set to the same frequency as that of the APB domain to which the timers are connected. 2. otherwise, they are set to twice (*2) the frequency of the APB domain to which the timers are connected.
Best Regards, Martin Guenther
Thank you for your note. I didn't notice this paragraph before. Now the timer's behavior is understandable.
Thanks, Norbert