2024-10-13 06:33 AM
Hello Everybody,
I would like transform the HAL_GetTick() function more than 49 days.
I don't find a NVIC overflow on this function to increment a second variable.
In my while I have do this with
uint32_t Mem_GetTick;
uint64_t Tick64;
while (1)
{
if (HAL_GetTick() != Mem_GetTick)
{
Mem_GetTick = HAL_GetTick();
Tick64++;
}
.
.
.
}
MAybe there is a more efficicent solution
Thank you to share your exeprience
2024-10-13 06:53 AM - edited 2024-10-13 11:15 AM
>>Maybe there is a more efficient solution
In SysTick or via HAL_IncTick() ??
You really shouldn't have any timeouts / spin loops that wait for 49-50 days, perhaps address those parts of the code.
Try to use delta time measurements, and not wait of things like >= time-in-future or >= (start + delay-time)
Some STM32 have a 64-bit count in the ETH-PTP hardware
2024-10-13 10:55 AM
Why don't you use the RTC peripheral? It'll be more accurate than using Systick and incrementing a uint64_t variable. It could drift over time due to n amount of instruction cycles it take to increment the 64 bit value.
2024-10-14 12:45 AM
What you are doing in the while loop will go wrong as soon as you do other stuff in there (that takes more than a millisecond).
Why not build a timer with a 1 ms interrupt, in its ISR you can count these 1 ms ticks with a uint64_t.
Or just hack the SysTick interrupt by incrementing an extra uint64_t variable. Or do you need "clean" HAL ?
2024-10-14 06:42 AM
> Or just hack the SysTick interrupt by incrementing an extra uint64_t variable.
... and when using it, keep atomicity in mind.
JW
2024-10-14 04:00 PM
Hi,
@waclawek.jan wrote:> Or just hack the SysTick interrupt by incrementing an extra uint64_t variable.
... and when using it, keep atomicity in mind.
JW
If you are going to reference the uint64_t often, then, atomicity may become inconvenient. You could consider using a uint32_t variable inside the SysTick interrupt at different rate - like :-
if ((uwTick % 10) == 0) myunit32++; // every 10mS = 490 days'ish....
I hope this helps.
Kind regards
Pedro