Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does TickGetDiv256() works?

Hi I wonder if anyone could give me an example how the TickGetDiv256(); function works. It came from Microchip in Tick.c

Im trying to count for 2 houre's, if fullfilled an engine will be stopped.

I could might use "threshold = tick + TICKS_PER_SECOND * 60;" function. But I dont know if it would be good to use it for this amount of time: threshold = tick + (TICKS_PER_SECOND * 60 * 60)*2;

Kind Regards

like image 224
Christian Avatar asked Nov 06 '22 09:11

Christian


1 Answers

Judging from the MPLAB C guide, the largest integer data type supported by the C compiler is 32-bits. From what I can glean elsewhere, the tick counter is six bytes - TickGetDiv256 returns the 'middle four' of these bytes.

Since the full six bytes of the tick counter cannot fit into a 32-bit integer, you'd use TickGetDiv256 to extract the middle bytes and thus have a count of the number of '256 tick' intervals that have passed since the counter was started. Of course, this isn't strictly true since it's ignoring the highest byte of the tick counter. You'd use this function if the lower four bytes of the tick counter do not provide enough of a range for the timespan you're interested in.

like image 171
Will A Avatar answered Nov 15 '22 05:11

Will A