Skip to main content
PMach.1
Senior
November 4, 2020
Solved

Wrong clock source on Timer!

  • November 4, 2020
  • 1 reply
  • 1320 views

Hello,

I am trying to program my TIM2 to set an interrupt every 100ms. As seen in the pictured that is attached, its APB runs on 170MHz. Given so, I have set the prescaler to 34000 and the counter to 500.

It has been functioning correctly this whole time.

Recently, I noticed it was behaving in a quite slowly manner. Checking it carefully by toggling an LED every interrupt and measuring with the oscilloscope, I noticed the interrupt arising every 1.06s, which, for the given prescaler and counter values (that I checked and remain the same), indicates it is running on an internal clock of 16MHz. The only one available is HSI RC, which is not even selected on the clock tree.

What might be wrong? Any idea?

Thanks in advance!

This topic has been closed for replies.
Best answer by TDK

It boots up with HSI as the clock source. My guess is you didn't change it from that, or your call to change the source to HSE failed.

1 reply

TDK
TDKBest answer
Super User
November 4, 2020

It boots up with HSI as the clock source. My guess is you didn't change it from that, or your call to change the source to HSE failed.

"If you feel a post has answered your question, please click ""Accept as Solution""."
PMach.1
PMach.1Author
Senior
November 4, 2020

You're right! There's a timeout during the HAL_RCC_OscConfig when waiting for RCC_CR_HSERDY bit to be set to 1, which indicates HSE is ready. What might be the cause?

TDK
Super User
November 4, 2020
Some possibilities:
HSE crystal not present, or improperly connected
HSE crystal incompatible
HSE bypass mode chosen instead of crystal (or vice versa)
HSE bypass clock source not present
"If you feel a post has answered your question, please click ""Accept as Solution""."