Skip to main content
VCapu
Associate III
May 24, 2021
Solved

HAL delay doesn't match the value

  • May 24, 2021
  • 9 replies
  • 1647 views

I am using an STM32 MCU. When I use the HAL_Delay function with a parameter of 1000 for example, I see that the delay is shorter than it should be. I have checked that HAL_IncTick(), but it works correctly and it is placed inside the SysTick_Handler. What do I need to check in my code? Or it could be a problem with some configuration made with Cube ? Thank you in advance.

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

    Solved. I recalculated the clock configuration with Cube and it seems to work well now. Thank you.

    9 replies

    Tesla DeLorean
    Guru
    May 24, 2021

    What STM32?

    What did period did you actually measure?

    Using SysTick?

    Frequency of external clock vs HSE_VALUE define?

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

    It's a STM32F405ZGT6. Now I have set in the Keil IDE the value Xtal(Mhz) at 25Mhz, and HSE_VALUE is the same. It seems that real delay is about a fifth of the parameter of the function. I am not measuring exactly the delay because the problem is very evident.

    TDK
    May 24, 2021

    Are you using CubeMX generated clock initialization or your own code? Show it. Output MCO to verify your clock is what you think it is.

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    Tesla DeLorean
    Guru
    May 24, 2021

    Toggle a GPIO in the SysTick_Handler

    No valid reason for delays to be 1/5th of expected. Would suggest you walk all the code, and math

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    TDK
    May 24, 2021
    > No valid reason for delays to be 1/5th of expected.
    Sure, but as they weren't actually measured, they could also be 1/3 or 8/25.
    "If you feel a post has answered your question, please click ""Accept as Solution""."
    VCapu
    VCapuAuthorBest answer
    Associate III
    May 25, 2021

    Solved. I recalculated the clock configuration with Cube and it seems to work well now. Thank you.