cancel
Showing results for 
Search instead for 
Did you mean: 

TIM clock

yohann
Associate II
Posted on October 31, 2014 at 10:41

Hello,

I want to make a timer for my software (call a call back when time is finish).

I need to understand the clock source for the timer.

I choose to work with TIM7 for that (basic timer).

As I see, using RCC_GetClocksFreq(&Clock_Info_s), I have some clock on my system.:

 SYSCLK_Frequency 168000000 

 HCLK_Frequency 168000000 

 PCLK1_Frequency 42000000 

 PCLK2_Frequency 84000000 

What is the clock source to be used to calculate the prescaler and period for my timer?

By experience I found that the source clock shall be 82.6MHz. The nearest is PCLK2 @84MHz, but with 2% error!!

How can I configure my period and prescaler to have a good accuracy (<0.5%)?

2 REPLIES 2
ivani
Associate II
Posted on October 31, 2014 at 14:09

TIM7 is residing in APB1 clock domain. However, the clock frequency for each timer is double the frequency of its clock domain if the prescaler of the clock domain is bigger than 1.

So, the correct frequency in your case is 2*42MHz = 84MHz.

BTW, you could use for benchmarking also DWT_CYCCNT residing on 0xE0001004. It is a 32-bit counter running at core clock frequency.
Posted on October 31, 2014 at 17:30

What APB is the timer on? Look at the clock tree in the Reference Manual, and observe that TIMCLK is typically x2 except in DIV1 settings.

Also that Period and Prescaler are programmed in N-1 form, and the accuracy of the HSI clock is pretty rough compared to a crystal or TCXO source, or measurement equipment using such.

OutputClock = TIMCLK / (P * Q)

where

Prescaler = P - 1;

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