cancel
Showing results for 
Search instead for 
Did you mean: 

Wrong clock source on Timer!

PMach.1
Senior

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!

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

5 REPLIES 5
TDK
Guru

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".

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?

Nevermind! I just found out the Crystal is broken. Many, many thanks for the enlightenment!

Kind regards!

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".

A printf() of SYSCLK/HCLK, APB1, APB2 clock frequencies as perceived by the MCU can save hours of time.

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