Browse Source

AP_Baro: work around occasional 0 values from MS5611

this was seen on the PXF board. It isn't yet known why it happens
master
Andrew Tridgell 11 years ago
parent
commit
be02f0c34f
  1. 45
      libraries/AP_Baro/AP_Baro_MS5611.cpp

45
libraries/AP_Baro/AP_Baro_MS5611.cpp

@ -363,30 +363,39 @@ void AP_Baro_MS5611::_update(void)
_timer = tnow; _timer = tnow;
if (_state == 0) { if (_state == 0) {
_s_D2 += _serial->read_adc();// On state 0 we read temp // On state 0 we read temp
_d2_count++; uint32_t d2 = _serial->read_adc();
if (_d2_count == 32) { if (d2 != 0) {
// we have summed 32 values. This only happens _s_D2 += d2;
// when we stop reading the barometer for a long time _d2_count++;
// (more than 1.2 seconds) if (_d2_count == 32) {
_s_D2 >>= 1; // we have summed 32 values. This only happens
_d2_count = 16; // when we stop reading the barometer for a long time
// (more than 1.2 seconds)
_s_D2 >>= 1;
_d2_count = 16;
}
} }
_state++; _state++;
_serial->write(CMD_CONVERT_D1_OSR4096); // Command to read pressure _serial->write(CMD_CONVERT_D1_OSR4096); // Command to read pressure
} else { } else {
_s_D1 += _serial->read_adc(); uint32_t d1 = _serial->read_adc();;
_d1_count++; if (d1 != 0) {
if (_d1_count == 128) { // occasional zero values have been seen on the PXF
// we have summed 128 values. This only happens // board. These may be SPI errors, but safest to ignore
// when we stop reading the barometer for a long time _s_D1 += d1;
// (more than 1.2 seconds) _d1_count++;
_s_D1 >>= 1; if (_d1_count == 128) {
_d1_count = 64; // we have summed 128 values. This only happens
// when we stop reading the barometer for a long time
// (more than 1.2 seconds)
_s_D1 >>= 1;
_d1_count = 64;
}
// Now a new reading exists
_updated = true;
} }
_state++; _state++;
// Now a new reading exists
_updated = true;
if (_state == 5) { if (_state == 5) {
_serial->write(CMD_CONVERT_D2_OSR4096); // Command to read temperature _serial->write(CMD_CONVERT_D2_OSR4096); // Command to read temperature
_state = 0; _state = 0;

Loading…
Cancel
Save