Skip to main content
Visitor II
August 26, 2015
Question

when the Hal_GetTick() will overflow and what happen with it ???

  • August 26, 2015
  • 2 replies
  • 5625 views
Posted on August 26, 2015 at 11:54

 hi !! i like as the question  , i   can see the Hal_GetTick() will return the variable uWick that is uni32_t type  and increment one unit when the systick interrupt happen .and  will it overflow when the uint32 type data to to  the maximun value ??? and will it be return 0 ??

the best thank

#old-school-basics
    This topic has been closed for replies.

    2 replies

    Visitor II
    August 28, 2015
    Posted on August 28, 2015 at 17:25

    Yes, the systick value will reset after overrrun (~49 days@1000 tick/s). the vallue will reset back to 0. If your application will run mor than 49 days without resseting AND you remember tick count to make measurements then you nee to take care about it.

    Graduate II
    August 28, 2015
    Posted on August 28, 2015 at 17:45

    If you just do the math properly the wrapping won't matter, assuming your delays are less than 49 days.

    uint32_t start, current, delta;

    delta = (current - start); // The math works and accounts for the wrap

    DON'T USE end = (start + x) type constructs.

    Visitor II
    November 18, 2024

    This is not correct. Even with delays < 49 days this will break exactly when the counter wraps...

    You need to keep track of the previous tick value to detect a wrap and then re-calculate your timing logic for any future tick based events.

    Graduate II
    November 18, 2024

    Tesal deLorean is right!

    That's how unsigned mathematics works.

    If  current is smaller then start, the result will be: current + UINT32_MAX - start.