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;
" fun开发者_运维知识库ction.
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
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.
Maybe i can do like this:
// if (Ts1/GTsy1) is under 40 and have'nt increased within 2h
if (AD0 < 40 && (TickGetDiv256() - (startingTick + (TICKS_PER_SECOND * 7200)/256)) >= 7200)
{
sip.PL = 0;
sip.PU = 0;
// Failure(code);
}
// if (Ts1/GTsy1) is under 40, start countdown
if (AD0 < 40)
{
if (!alflags.ColdTimer)
startingTick = TickGetDiv256(); //Start timer
alflags.ColdTimer = 1;
}
else
alflags.ColdTimer = 0;
精彩评论