Skip to main content
Bahadir(Canceled)
Associate II
October 8, 2021
Solved

HAL_Delay(X) function delays by X/2 (@STM32L0)

Hello everyone,

I write HAL_Delay(1000) or HAL_Delay(5000) on my code but it delays it by half. I checked SystickTimer it works fine. But HAL_Delay function gives me half delay time.

I created another project with same board, same Cubemx features , it works fine.

Where should i check at my code to find what's wrong with it (at debug mode)?

This topic has been closed for replies.
Bahadir(Canceled)
Associate II
October 9, 2021

Why i did that i don't know but I had written twice HAL_IncTick(); function in the SysTick_Handler.

My stupidity I'm sorry.

It's solved.

Thank you all.

5 replies

Tesla DeLorean
Guru
October 8, 2021

What are you using for a clock source, and on what board?

For external clocks watch the define for HSE_VALUE, and use of HSE BYPASS for TCXO/XO type clock sources vs crystals

Internal clocks can typically be exported via MCO/PA8 pin so you can scope them.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Bahadir(Canceled)
Associate II
October 8, 2021

I am using HSI16, at PLL x4 and /2 32MHz all of the peripherals. Also I have a HSE osc. But situation is same. HAL_Delay gives me delay by half.

MCO is used as a input right now but i'll try tomorrow.

TDK
October 8, 2021

HAL_Delay uses SysTick to increment the counter. Can't see how one would be correct and the other would be wrong. The logic is very simple.

Most likely the clock is twice as fast as you think it is.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Bahadir(Canceled)
Bahadir(Canceled)AuthorBest answer
Associate II
October 9, 2021

Why i did that i don't know but I had written twice HAL_IncTick(); function in the SysTick_Handler.

My stupidity I'm sorry.

It's solved.

Thank you all.

Tesla DeLorean
Guru
October 13, 2021

Thanks for the update on that. That would certainly do it..

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