Skip to main content
OGhis
Senior
November 2, 2024
Question

STM32H7B0 How to get input frequency of timer 3

  • November 2, 2024
  • 1 reply
  • 1927 views

Dear,

Used MCU: STM32H7B0, 100 pins.


In the datasheets we had found that TIM3 use the APB1 peripheral clock.
In our case is this 120MHz. But when we use the function "HAL_RCC_GetPCLK1Freq()" we become 60MHz.
This isn't correct. 
So what function should we use to obtain the correct input frequency so that we can calculate the correct prescaler (PSC) and counter period values?

OGhis_0-1730552934505.png

 

 




1 reply

gbm
Lead III
November 2, 2024

You set the frequency, so there is no need to call any function to get what you decided on. The picture above says it all - ABP timer clock freq is 120 MHz. It is also stated clearly in the manual: if general ABP clock is HCLK divided by more than 1, timer clock is 2x ABP clock.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
OGhis
OGhisAuthor
Senior
November 2, 2024

Dear,

Yes we seen in the picture that the clock is 120MHz, but with function(s) we should use to get this 120MHz.
We use this timer as sample rate trigger for the ADC2 and this can be variable. 
So we must calculate the periode and prescaler value for the TIM3.

At this moment we use the follow functions to get the Timer3 input clock freq.

 

 RCC_ClkInitTypeDef clkCfg;
 uint32_t latency;

 HAL_RCC_GetClockConfig(&clkCfg, &latency);
 timer_clock = HAL_RCC_GetPCLK1Freq();
 if (clkCfg.APB1CLKDivider != RCC_CDCFGR2_CDPPRE1_DIV1) {
 timer_clock *= 2uL;
 }
 Timer3_input_freq = timer_clock 

 

Is this the correct way to get the timer 3 input frequency?

Tesla DeLorean
Guru
November 2, 2024

Yes, that's typically how one would un-pack the clock tree. Or directly at a register level through the RCC peripheral.

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