2024-10-07 05:49 PM
I would like to use TIM2 as a performance counter to evaluate my software changes.
Is the TIM2 internal clock 1/4 of the CPU clock on the NUCLEO-G0B1RE board? Net effect, resulting in the TIM2 counter having a resolution of four CPU clock cycles.
Thank you.
Solved! Go to Solution.
2024-10-07 08:00 PM - edited 2024-10-07 08:00 PM
The system boos up using the HSI as a clock, which is 16 MHz. That certainly agrees with what the timer is telling you. HAL also has functions for retrieving the speed: HAL_RCC_GetHCLKFreq().
You can validate clock speeds by routing a signal out to MCO and monitoring it on a scope. Enable MCO in the RCC tab. (Not that there's a reason to doubt what the clock configuration tab is telling you.)
2024-10-07 05:54 PM
The TIM2 clock is the same as the CPU clock by default.
If you want it to be 1/4 of the CPU clock, change the prescaler to 3. This will result in a TIM2 clock of HCLK/4 or 4 MHz.
2024-10-07 07:49 PM
How can I validate my CPU clock frequency? I have been assuming that my CPU would be booting up to 64MHz.
After reset, I clear and start TIM2 and then delay HAL_Delay(1000) for 1 second. The count is 16M indicating that the timer frequency is 1/4 of 64MHz or the CPU clock is 16MHz. The TIM2 prescalar register is 0x0 indicating a divide by 1.
2024-10-07 08:00 PM - edited 2024-10-07 08:00 PM
The system boos up using the HSI as a clock, which is 16 MHz. That certainly agrees with what the timer is telling you. HAL also has functions for retrieving the speed: HAL_RCC_GetHCLKFreq().
You can validate clock speeds by routing a signal out to MCO and monitoring it on a scope. Enable MCO in the RCC tab. (Not that there's a reason to doubt what the clock configuration tab is telling you.)
2024-10-07 08:17 PM
Thank you.