This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32 timer does not work like expected

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

Parents
  • Hello,

    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

Reply
  • Hello,

    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

Children