Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 804 → Rev 806

/branches/V0.68d Code Redesign killagreg/rc.c
81,7 → 81,6
// check for at least one input capture event per timer overflow (timeout)
ISR(TIMER1_OVF_vect)
{
int16_t signal = 0;
static uint16_t lastICR1 = 0;
// if ICR1 has not changed
// then no new input capture event has occured since last timer overflow
115,9 → 114,7
{
int16_t signal = 0, tmp;
static int16_t index;
static int16_t Sum_RC_Quality = 0;
static uint16_t oldICR1 = 0;
int16_t Noise;
 
// 16bit Input Capture Register ICR1 contains the timer value TCNT1
// at the time the edge was detected
131,7 → 128,7
// lost frame?
if(signal > 8000)
{
Sum_RC_Quality -= Sum_RC_Quality/2;
RC_Quality /= 2;
}
else
//sync gap? (3.52 ms < signal < 25.6 ms)
154,29 → 151,22
// shift signal to zero symmetric range -154 to 159
signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms)
// check for stable signal
Noise = abs(signal - PPM_in[index]);
if((Noise/16) > (200-RC_Quality)) // spike detector
{
Sum_RC_Quality -= 3*RC_Quality;
Sum_RC_Quality += 3*(200 - Noise);
if(abs(signal-PPM_in[index]) < 6)
{
if(RC_Quality < 200) RC_Quality +=10;
}
else
{
Sum_RC_Quality -= RC_Quality;
Sum_RC_Quality += 200 - Noise;
}
// calculate exponential history for signal
tmp = (3 * (PPM_in[index]) + signal) / 4;
if(tmp > signal+1) tmp--; else
if(tmp < signal-1) tmp++;
// calculate signal difference on good signal level
if(RC_Quality >= 170) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for nois reduction
if(RC_Quality >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for nois reduction
else PPM_diff[index] = 0;
PPM_in[index] = tmp; // update channel value
}
else
{ // invalid PPM time
Sum_RC_Quality /= 8;
RC_Quality /= 2;
}
index++; // next channel
// demux sum signal for channels 5 to 7 to J3, J4, J5
188,8 → 178,7
}
}
}
if(Sum_RC_Quality < 0) Sum_RC_Quality = 0;
RC_Quality = Sum_RC_Quality/128;
if(RC_Quality) RC_Quality--;
}