cancel
Showing results for 
Search instead for 
Did you mean: 

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

SShid
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Msd.1
Associate II

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.

View solution in original post

4 REPLIES 4

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

JW

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
Associate II

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
Associate III

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