2024-11-02 06:07 AM - edited 2024-11-02 06:09 AM
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?
2024-11-02 09:31 AM
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.
2024-11-02 12:36 PM - edited 2024-11-02 12:38 PM
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?
2024-11-02 03:38 PM
Yes, that's typically how one would un-pack the clock tree. Or directly at a register level through the RCC peripheral.
2024-11-03 01:10 AM
I am too old to understand why would someone call a function to evaluate the constant value that was decided on and set by himself. ;)