Skip to main content
SShid
Associate III
July 15, 2020
Solved

What is the Actual Input Clock Source for TIM1 of STM32F103RG?

  • July 15, 2020
  • 4 replies
  • 4504 views

I found from ref manual that the internal clock source for TIM1 is APB2 pre-scaled value.

(Please see attached image).

0693W000001sv68QAA.png

From CubeMx, I've configured my main clock frequency to be 48MHz, which is a PLL multiplied value from external crystal oscillator of 8MHz.

(Please see second attached image)

0693W000001sv6IQAQ.png

With these in mind, I was trying to get a 1ms timer tick by configuring the timer as below:

(please see third attached image)

0693W000001sv8xQAA.png

But when I measured the clock period on an oscilloscope, I found it to be 2ms and NOT 1ms.

This showed that the internal clock input to TIM1 is being taken as 24MHz, and not 48MHz

(I confirmed this by adjusting the pre-scalar to 24000).

So what exactly is the clock input source for TIM1?

Few other points -

I've absolutely made no timer configuration changes in the code.

I was able to get calculated timer period of 1ms on TIM3, which seems to be fed with 48MHz clock input.

This topic has been closed for replies.
Best answer by Msd.1

fclock is 48 MHz and you see 2 ms because you set ARR=1, Time Period = ((PSC+1)*(ARR+1))/FClock in Second in your case ((48000+1)*(1+1))/48000000 almost equal to 2 Ms.

4 replies

waclawek.jan
Super User
July 15, 2020

Timer period is 1/fclock*(PSC+1)*(ARR+1).

JW

SShid
SShidAuthor
Associate III
July 16, 2020

Hello JW,

Thanks for the response,

but I just need to know what is the input clock source which is selected as default for TIM1?

Is it APB2 peripheral clock or APB2 timer clock?

From my observations, it seems to be APB2 peripheral clock (24MHz in my case), but the documentation says it is APB2 timer clock (48MHz in my case).

Msd.1
Msd.1Best answer
Visitor II
July 17, 2020

fclock is 48 MHz and you see 2 ms because you set ARR=1, Time Period = ((PSC+1)*(ARR+1))/FClock in Second in your case ((48000+1)*(1+1))/48000000 almost equal to 2 Ms.

SShid
SShidAuthor
Associate III
July 20, 2020

Oh

Thanks a lot for bringing out my mistake.

With this formula, I was able to get a 1ms timer period.

I tried achieving 1us, but I guess the timer doesn't go beyond 7us.

Anyway, I'll ask this query in a different post.

Thanks Msd.1