views:

34

answers:

2

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

+1  A: 

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.

Will A
A: 

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;
Christian
TickGetDiv64K() will give you the upper four bytes of the tick counter - this may be a little safer if you're not resetting the tick counter during operation - you'll 2s resolution with this function @ 32,768 tps.
Will A