2023-08-25 03:23 AM
Below i have attached a code which enables the PLL freq of 72MHz using HSI of 16MHz. The issue is if I give a Timer pre-scaler of 36000-1 (I am using timer2, which in case of STM32F401RE is on APB1 bus so using a pre-scaler of 2 for APB1 which makes it 36MHz, thus a pre-scaler of 36000-1 will generate a delay of 1 ms). Desired outcome is to generate 1 ms timer delay but it is not 1 ms when tested with timer ARR is set 5000. I have already checked clock using MCO1 pin with a pre-scaler of 2 which gave 36MHz on DSO. When i call a delay function by passing 5000 as timer ARR value, then i hardly get 2500 - 3000 ms delay.
Below is my RCC_Init() function, please let me know is there any other settings are needed for setting up timers using PLL.
Solved! Go to Solution.
2023-08-26 03:55 AM
Timer clocks are used only in the Timers. The APB peripheral clocks are used by all other peripherals on the APB bus, e.g. USART, SPI, I2C...
JW
2023-08-26 04:16 AM
Okay, so you are saying that the timer clock is still 72MHz, but due to timer PSC limitation of only 16 bits, hence the 36000-1, due to this reason we are doubling the ARR value. Is it?
Also can you please once again explain about the role of TIMPRE bit in RCC_DCKCFGR.
2023-08-28 01:27 AM
> Okay, so you are saying that the timer clock is still 72MHz, but due to timer PSC limitation of only 16 bits, hence the 36000-1, due to this reason we are doubling the ARR value. Is it?
Yes.
> Also can you please once again explain about the role of TIMPRE bit in RCC_DCKCFGR.
It's an afterthought.
Original behaviour of TIM clocks in STM32 is, that if APB clock is undivided, TIM clock is equal to APB clock; if APB clock is divided by any ratio (i.e. /2, /4, /8, /16), TIM clock is twice the APB clock. In other words, if APB clock is AHB clock /1 or /2, TIM clock is equal to AHB clock; otherwise TIM clock uses the next higher output from the AHB divider than the APB clock uses.
That's the default behaviour also with TIMPRE (being 0 by default).
Later some users may have complained that with higher APB divider the timers are unnecessarily slow, so as an afterthough ST added TIMPRE, which if set to 1, TIM clock is equal to AHB clock both when APB divider is /1 and /2, and equal to APB*4 when APB divider is /4. In other words, TIM clock is directly the AHB clock when APB divider is /1 and /2, and then is derived from two higher tap of the divider chain than the APB clock.
JW