Skip to main content
VCapu
Associate III
May 24, 2021 11:42 AM UTC
Solved

HAL delay doesn't match the value

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.
    VCapu
    VCapuBest answer
    Associate III
    May 25, 2021 6:49 AM UTC

    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 11:48 AM UTC

    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 12:10 PM UTC

    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 1:10 PM UTC

    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 1:18 PM UTC

    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 1:45 PM UTC
    > 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 6:49 AM UTC

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