Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2034 → Rev 2035

/branches/dongfang_FC_rewrite/analog.c
500,18 → 500,26
// If AIRPRESSURE_OVERSAMPLING is an odd number we only want to add half the double sample.
// The 2 cases above (end of range) are ignored for this.
debugOut.digital[1] &= ~DEBUG_SENSORLIMIT;
if (pressureMeasurementCount == AIRPRESSURE_OVERSAMPLING - 1)
airPressureSum += simpleAirPressure / 2;
else
airPressureSum += simpleAirPressure;
airPressureSum += simpleAirPressure;
}
// 2 samples were added.
pressureMeasurementCount += 2;
if (pressureMeasurementCount >= AIRPRESSURE_OVERSAMPLING) {
// Assumption here: AIRPRESSURE_OVERSAMPLING is even (well we all know it's 14 haha...)
if (pressureMeasurementCount == AIRPRESSURE_OVERSAMPLING) {
 
// The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half.
airPressureSum += simpleAirPressure >> 2;
 
lastFilteredAirPressure = filteredAirPressure;
filteredAirPressure = (filteredAirPressure * (AIRPRESSURE_FILTER - 1)
+ airPressureSum + AIRPRESSURE_FILTER / 2) / AIRPRESSURE_FILTER;
 
if (!staticParams.airpressureWindowLength) {
filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1)
+ airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant;
} else {
// use windowed.
filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength;
}
pressureMeasurementCount = airPressureSum = 0;
}
//int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
520,7 → 528,7
windowedAirPressure += simpleAirPressure;
windowedAirPressure -= airPressureWindow[windowPtr];
airPressureWindow[windowPtr] = simpleAirPressure;
windowPtr = (windowPtr+1) % MAX_AIRPRESSURE_WINDOW_LENGTH;
windowPtr = (windowPtr+1) % staticParams.airpressureWindowLength;
}
}