Hi, Radek.
more informations...
*yes, the code is to capture period. precisely capture vehicle speed sensor
*43690 are in usec, not 16 bits (43690 * 3 / 2 = 65535). 43692 is an prescale configuration type(tick 0.666usec*65535 = 43692usec).
*correct, TC2 channel 2 is configured like input.
obs: I forgot to report, this code is inside the ISR TC2, Of course, whenever a level rise occurs, it is called the interruption TC2 on vector map.
--------------------
oh, is true! I have forgotten this detail of the past,present and the future. overflows are not easy to understand, because several situations may occur, and the code above shows this.
obs:
overflow ISR < priority than IC ISR
At least here it is configured so. ISR TCx come in first.
correct, in special ISR may be happen. I remember having failed in the period of this capture in a long capturing encounter
> 5min, spike very fast velocity or very long. after I copied that code ended that.
my simple code was just that. spike can be happen
if (! ICt_overflow) // no overflow
dt3 = t_in3 - t_in2;
else {
dt3 = t_in3 + ((long) ICt_overflow * 43690) - t_in2;
ICt_overflow = 0;
}
obs:
t_in2(last tc2 usec)
t_in3(new tc2 usec)
dt3(delta usec)
-------------------
original code with tips
// Need to test for overflow because overflow ISR < priority than
// IC ISR and might be pending, so ICt_overflow not up to date.
if (!(TFLG2 & 0x80) || (TCNT < TC0)) { // check for t overflow isr pending // no pending overflow isr or IC occurred < overflow
if(!ICt_overflow)
dt3 = t_in3 - t_in2;
else { dt3 = t_in3 + ((long)ICt_overflow * 43690) - t_in2;
ICt_overflow = 0;
}
}
else { // pending overflow isr and IC after overflow
dt3 = t_in3 + ((long)(ICt_overflow + 1) * 43690) - t_in2;
ICt_overflow = -1; // pending, so -1 will cause to clear in isr
}
--------------------
trace, me too.... i am fully noob. Maybe I want too much. I do not know if it has any correct tools, I was thinking of making a serial connection software, and capture those values and make a datalog. But I have to work for it. and a ready program would be great!