cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 TIM3 Timebase problem?

kkarasti
Associate II
Posted on August 21, 2013 at 16:41

My timebase for TIM3 does seem to obey the laws of timebase calculation! I think I've had this problem before, what am I doing wrong.

TIMCLK = 36MHz

  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

  /* TIM3 clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  /* Time Base configuration */

  TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseStructure.TIM_Period = 10 - 1;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  /* TIM enable counter */

  TIM_Cmd(TIM3, ENABLE);

  /* Enable the Interrupt Request */

  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

And in my ISR:

  GPIOB->ODR ^= GPIO_Pin_0;

  TIM_ClearITPendingBit(TIM3, TIM_IT_Update);

When I use the above, the pulse width of my trace on PB0 is 5ms. Shouldn't it be 10ms?

Also when I use Pre = 36000 and Period of anything greater than 2000, the ISR never fires. I'm trying to get a toggle greater than 1sec.
5 REPLIES 5
John F.
Senior
Posted on August 21, 2013 at 17:19

According to the Clock Tree for TIM2,3, 4 ''If (APB1 prescaler =1) x1 else x2''.

Likely your clock is 72MHz?

Posted on August 21, 2013 at 17:27

1 Hz interrupt should be

TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1;

TIM_TimeBaseStructure.TIM_Period = 2000 - 1;

Period 4000 - 1 for 0.5 Hz (2 sec)

Period 8000 - 1 for 0.25 Hz (4 sec)

Period can be up to 65535 for 16-bit timers

Be sure to also enable NVIC for TIM interrupt

If you don't get an update interrupt, then something else is wrong.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kkarasti
Associate II
Posted on August 21, 2013 at 17:38

Verified in debug, PCLK1 = 36MHZ.

I went back to the 3210E demo board to make sure I don't have a hardware problem.

Here's what the scope tells me:

36000/2000 = 1sec int

36000/4000 = nothing

36000/1000 = 500ms

kkarasti
Associate II
Posted on August 21, 2013 at 17:40

Found the problem, I have some ADC stuff in the ISR that was hanging it up.

Thanks!

Posted on August 21, 2013 at 17:43

TIM3CLK = PCLK1 * 2, per Clock Tree

36000/4000 = nothing

Yes, that would be bizarre. Present a complete example.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..