cancel
Showing results for 
Search instead for 
Did you mean: 

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

chauvoluuhuong
Associate II
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
4 REPLIES 4
Osto
Senior
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.

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.

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

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.

Tesal deLorean is right!

That's how unsigned mathematics works.

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