From 5a4d417737cdb9c2b8ce8c42584c49e82992ab38 Mon Sep 17 00:00:00 2001 From: Jonathan Loong Date: Tue, 21 Nov 2023 15:57:50 -0800 Subject: [PATCH] AP_BattMonitor: patch for fuel level calibration function from ottanoX --- .../AP_BattMonitor/AP_BattMonitor_FuelLevel_Analog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_FuelLevel_Analog.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_FuelLevel_Analog.cpp index 1b0f00bb86..7f176b17f6 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_FuelLevel_Analog.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_FuelLevel_Analog.cpp @@ -21,6 +21,10 @@ extern const AP_HAL::HAL& hal; +// ADC Calibration for CX31021020 Rev D Voltage Divider for ADC #3 +#define CPN_ADC_5V_SLP 797.76 +#define CPN_ADC_5V_OFF 1.11 + const AP_Param::GroupInfo AP_BattMonitor_FuelLevel_Analog::var_info[] = { // @Param: FL_VLT_MIN @@ -128,7 +132,8 @@ void AP_BattMonitor_FuelLevel_Analog::read() const uint32_t dt_us = tnow - _state.last_time_micros; // get voltage from an ADC pin - const float raw_voltage = _analog_source->voltage_average(); + //const float raw_voltage = _analog_source->voltage_average(); + const float raw_voltage = (_analog_source->read_average() - CPN_ADC_5V_OFF) / CPN_ADC_5V_SLP; // Converting sensor reading to actual volume in tank in Litres (quadratic fit) const float voltage =