I have connected 3S LiPo batter to pxfmini power module. Power module is powering pxfmini + pi0. All the values below are when LiPo battery is fully charged. Multimeter shows exactly 12.0 V on its output.
I'm trying to figure out how read ADS1115 output in C code without ArduPilot/ros.
First I tried running AP_BattMonitor_test from ArduPilot codebase (from "libraries/AP_BattMonitor/examples/AP_BattMonitor_test" folder in https://github.com/erlerobot/ardupilot/ codebase).
It is printing ~5.80 value for voltage.
Now I am writing C code to read ADS1115 registers over i2c. I've set gain to ±6.144V (PGA[2:0] = 000). That means if output is 32767, then expected voltage is +6.144V. Is that right?
I configured input multiplexer to read input 3 and ground (MUX[2:0] = 111) - this is same what AP_BattMonitor is doing in here: libraries/AP_BattMonitor/AP_BattMonitor_Analog.h#L60
It chooses voltage "pin" to be index 5. And index 5 corresponds to ADS1115_MUX_P3_NG value in libraries/AP_ADC/AP_ADC_ADS1115.cpp#L105
The value I am getting is 3056. Converting to V would give 3056 * 6.144 / 32767 = 0.573 V. That doesn't seem right...
It seems that ArduPilot simply multiples this result with 10.1, from this location: libraries/AP_BattMonitor/AP_BattMonitor_Analog.h#L62
This would give approximately same result as AP_BatteryMonitor_test - 0.573 * 10.1 = 5.78
But if I measure voltage between power and ground pin on wire that goes from power module into pxfmini (two wires on side of connector), I get reading for 5.25 V. I see same voltage reading when I measure on PWM output pins ~5.25V.
1) Is this formula for calculating voltage is correct - raw_signed_16bit_value * gain / 32767 * 10.1 ?
Where does value 10.1 comes from? Is it power module thing? Or ADS1115 thing?
2) Why there is a difference between what multimeter reads (5.25) and what ADS1115 provides (5.78), is this expected?
3) Is there something useful I can read from ADS1115 other pints (pin0/pin1/pin2) ?
4) How can I know if 3S battery voltage will drop to low level - let's say 10V? Does power module output V also will change and how much?