2015-08-26 02:54 AM
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-basics2015-08-28 08:25 AM
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.
2015-08-28 08:45 AM
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 wrapDON'T USE end = (start + x) type constructs.2024-11-17 07:40 PM
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.
2024-11-17 11:54 PM
Tesal deLorean is right!
That's how unsigned mathematics works.
If current is smaller then start, the result will be: current + UINT32_MAX - start.