diff --git a/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp b/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp index 6cf8dcb07c..9ae890bdab 100644 --- a/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp +++ b/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.cpp @@ -104,7 +104,7 @@ uint16_t AP_AnalogSource_Arduino::read_vcc(void) // time read_average() was called. This gives a very cheap // filtered value, as new values are produced at 500/N Hz // where N is the total number of analog sources -uint16_t AP_AnalogSource_Arduino::read_average(void) +float AP_AnalogSource_Arduino::read_average(void) { uint16_t sum; uint8_t sum_count; @@ -119,7 +119,7 @@ uint16_t AP_AnalogSource_Arduino::read_average(void) pins[_pin_index].sum = 0; pins[_pin_index].sum_count = 0; sei(); - return sum / sum_count; + return sum / (float)sum_count; } // read with the prescaler. This uses the averaged value since diff --git a/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.h b/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.h index 0012e6db2d..b1e04e9880 100644 --- a/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.h +++ b/libraries/AP_AnalogSource/AP_AnalogSource_Arduino.h @@ -32,7 +32,7 @@ class AP_AnalogSource_Arduino : public AP_AnalogSource // read the average 16 bit ADC value since // we last called read_average(). - uint16_t read_average(void); + float read_average(void); private: uint8_t _pin_index;