Recently I have got a MultiWii FC board from HobbyKing and was very satisfied with its performance on my tricopter.


The first thing to try was the battery voltage sensor. Searching a bit on this forum I found this topic useful http://www.multiwii.com/forum/viewtopic.php?f=16&t=2490#p23255 which I then followed. After a bit of soldering and editing "config.h" I managed to get it working.

The idea behind voltage sensor is pretty simple: construct circuit of two resistors with proper values and get voltage divider.
Then the voltage at the output of circuit i expressed as:
Vout = Vbat * R2/(R1+R2).
The proposed values for resistors are R1 = 33k and R2 = 51k. Easy, isn't it?
However, reality is such that the battery voltage is typically fall within the range of [9 ... 12.6] Volts (Li-Po 3S) which in turn related to Vout in range [3.54 ... 4.95] V. The Vout is then measured by 10-bit ADC tuned for range of [0 ... 5] V giving 289 ADC counts which is about 28% of acceptable ADC range.

In other words the battery voltage is measured with resolution of
12.6/1024 = 0.012 V
or even less if accounted for rounding errors in calculation by MultiWii code. Also, the resolution is getting even worse for 4S-6S battery packs, so does the accuracy of measurement of mAh consumed by aircraft.
Improvement
Here, I propose an improved voltage sensor circuit still preserving its simplicity. Keeping in mind that realistic battery voltage can be written as
Vbat = Vc + [9 ... 12.6].
The idea is to use Zener diode to subtract constant amount Vz from battery's voltage and measure the rest. So the sensor output is given as:
Vout = (Vbat - Vz)*R2/(R1+R2)
In such way it is possible to fully utilize ADC resolution. Please note that now the values for R1 and R2 are different from that said above!
The circuit:
R3 is intended to protect MCU (in case of an accident

I have made a simple MATLAB code which can find the best combinations of required D1, R1, R2 values utilizing list of standard values of real components. Here is the input data and result for 3S Li-Po.
Code: Select all
% Battery params
Bat_cells = 3; % Number of cells in battery
Bat_Vcell_min = 3; % [V] Min cell voltage
Bat_Vcell_max = 4.2; % [V] Max cell voltage
% ADC Params
ADC_Vmin = 0; % [V] Min ADC input voltage
ADC_Vmax = 4.9; % [V] Max ADC input voltage. Safe margin allowed (Real Vmax = 5V)
ADC_bit = 10; % Bit depth of ADC
% Zenner diode params
Dz_Imin = 5e-3; % [A] Minimal Zenner diode current
Dz_Imax = 40e-3; % [A] Maximal Zenner diode current
... CODE OMITTED ...
****************************************** RESULTS **************************************************
Some combinations.
Vbat range: [9.00 => 12.60 V]. Cells: 3S
R1 R2 Vz I range Vout range ADC range Resol [dVa/dVb] Pow dissipated on D1
8 200 7.5 [ 7 => 24 mA] [1.44 => 4.90 V] [ 300 => 1023] 4.98 [mV] 0.96 [ 54 .. 184 mW] << the best
... some results omitted
10 240 7.5 [ 6 => 20 mA] [1.44 => 4.90 V] [ 300 => 1022] 4.98 [mV] 0.96 [ 45 .. 153 mW]
...
12 270 7.5 [ 5 => 18 mA] [1.44 => 4.88 V] [ 299 => 1019] 5.00 [mV] 0.96 [ 40 .. 136 mW]
7 150 7.5 [ 10 => 33 mA] [1.43 => 4.88 V] [ 299 => 1019] 5.00 [mV] 0.96 [ 72 .. 244 mW]
10 220 7.5 [ 7 => 22 mA] [1.43 => 4.88 V] [ 299 => 1018] 5.00 [mV] 0.96 [ 49 .. 166 mW]
9 200 7.5 [ 7 => 24 mA] [1.43 => 4.88 V] [ 299 => 1018] 5.00 [mV] 0.96 [ 54 .. 183 mW]
8 180 7.5 [ 8 => 27 mA] [1.43 => 4.88 V] [ 299 => 1018] 5.00 [mV] 0.96 [ 60 .. 203 mW]
11 240 7.5 [ 6 => 20 mA] [1.43 => 4.88 V] [ 299 => 1018] 5.00 [mV] 0.96 [ 45 .. 152 mW]
...
10 200 7.5 [ 7 => 24 mA] [1.43 => 4.86 V] [ 298 => 1014] 5.02 [mV] 0.95 [ 54 .. 182 mW]
11 220 7.5 [ 6 => 22 mA] [1.43 => 4.86 V] [ 298 => 1014] 5.02 [mV] 0.95 [ 49 .. 166 mW]
12 240 7.5 [ 6 => 20 mA] [1.43 => 4.86 V] [ 298 => 1014] 5.02 [mV] 0.95 [ 45 .. 152 mW]
...
33 130 7.5 [ 9 => 31 mA] [1.20 => 4.07 V] [ 249 => 849] 6.00 [mV] 0.80 [ 69 .. 235 mW]
33 130 6.8 [ 13 => 36 mA] [1.75 => 4.63 V] [ 366 => 966] 6.00 [mV] 0.80 [ 92 .. 242 mW]
56 220 6.8 [ 8 => 21 mA] [1.75 => 4.62 V] [ 365 => 965] 6.00 [mV] 0.80 [ 54 .. 143 mW]
56 220 7.5 [ 5 => 18 mA] [1.20 => 4.07 V] [ 249 => 849] 6.00 [mV] 0.80 [ 41 .. 139 mW]
...
360 330 2.7 [ 9 => 14 mA] [3.01 => 4.73 V] [ 629 => 988] 10.01 [mV] 0.48 [ 25 .. 39 mW]
240 220 2.7 [ 14 => 22 mA] [3.01 => 4.73 V] [ 629 => 988] 10.01 [mV] 0.48 [ 37 .. 58 mW]
360 330 3.0 [ 9 => 14 mA] [2.87 => 4.59 V] [ 599 => 958] 10.01 [mV] 0.48 [ 26 .. 42 mW]
360 330 3.9 [ 7 => 13 mA] [2.44 => 4.16 V] [ 509 => 869] 10.01 [mV] 0.48 [ 29 .. 49 mW]
120 110 5.6 [ 15 => 30 mA] [1.63 => 3.35 V] [ 339 => 699] 10.01 [mV] 0.48 [ 83 .. 170 mW]
240 220 5.6 [ 7 => 15 mA] [1.63 => 3.35 V] [ 339 => 699] 10.01 [mV] 0.48 [ 41 .. 85 mW]
120 110 6.2 [ 12 => 28 mA] [1.34 => 3.06 V] [ 279 => 639] 10.01 [mV] 0.48 [ 75 .. 173 mW]
240 220 6.2 [ 6 => 14 mA] [1.34 => 3.06 V] [ 279 => 639] 10.01 [mV] 0.48 [ 38 .. 86 mW]
...
120 110 6.8 [ 10 => 25 mA] [1.05 => 2.77 V] [ 219 => 579] 10.01 [mV] 0.48 [ 65 .. 171 mW]
120 110 7.5 [ 7 => 22 mA] [0.72 => 2.44 V] [ 149 => 509] 10.01 [mV] 0.48 [ 49 .. 166 mW]
360 330 5.1 [ 6 => 11 mA] [1.87 => 3.59 V] [ 389 => 749] 10.01 [mV] 0.48 [ 29 .. 55 mW]
240 220 2.5 [ 14 => 22 mA] [3.11 => 4.83 V] [ 649 => 1008] 10.01 [mV] 0.48 [ 35 .. 55 mW]
240 220 2.8 [ 13 => 21 mA] [2.97 => 4.69 V] [ 619 => 978] 10.01 [mV] 0.48 [ 38 .. 60 mW]
360 330 3.3 [ 8 => 13 mA] [2.73 => 4.45 V] [ 569 => 929] 10.01 [mV] 0.48 [ 27 .. 44 mW]
Some shortcuts explained
I range: Range of current flowing in circuit
Vout range: Range of sensor output values
ADC range: Range of ADC counts
Resol: mV per one ADC count
dVo/dVb = (Vout_max - Vout_min)/(Vbat_max - Vbat_min)
Pow dissipated on D1: Range of power converted to heat on Zener diode. Should not exceed maximal ratings of the diode used.
The result shows that D1, R1 and R2 can be selected to maximize voltage measurement resolution. Also, resolution can be selected for easy calculation, say 5mV or 10mV per ADC count.
One more example, this time for 6S Li-Po. The result shows that even for 6S it is possible to get 10mV resolution. Also more powerful Zener diode required.
Code: Select all
Vbat range: [18.00 => 25.20 V]. Cells: 6S
R1 R2 Vz I range Vout range ADC range Resol [dVa/dVb] Pow Dz
160 180 16.0 [ 6 => 27 mA] [1.06 => 4.87 V] [ 220 => 1017] 9.04 [mV] 0.53 [ 94 .. 433 mW]
...
240 220 15.0 [ 7 => 22 mA] [1.43 => 4.88 V] [ 299 => 1018] 10.01 [mV] 0.48 [ 98 .. 333 mW]
One of the drawbacks of this sensor is increased current consumption in comparison with original sensor. Wasted power on sensor when using 6S Li-Po is about 0.7 Watts.
Huuuh. Enough theory

I will update the post once I try it on experiment. I have ordered all needed components and now waiting for them shipped.
NEW

Now I finally received the set of different Zener diodes so I did experiment with the proposed circuit.
The setup consists of Adruino nano board, used for voltage measurement, PC controlled power supply and the proposed circuit with Zener diode assembled on a breadboard.
The measurement procedure is very simple and consists of setting the voltage of power supply and simultaneously recording Arduino ADC output. The results presented in the next 3 figures which are showing input voltage in Volts vs output voltage in terms of ADC counts (Vbat and Vout, respectively). I experimented with voltages typical for 3S and 6S LiPo batteries.
All measurements show linear response of the circuit. So I did linear fit of the measured values, with fit expression shown in each figure. In fact, these expressions are the ones to use for conversion ADC counts into real voltage. First coefficient (one multiplied with "x") in the fit expression shows achieved resolution while the second term shows minimal measurable voltage defined by Zener voltage. Small steps on experimental curves is due to the way my power supply changes the voltage and is not inherent to the circuit under test.
I noticed some some issues which lead to slight nonlinearity of the circuit response resulting in limited accuracy of battery voltage measurement. The reason is in slight dependence of Zener voltage on current flowing through the diode. The changes in case of 6S battery and 18v diode was about 0.1V within nominal battery voltage range (18V ... 25.2V). In case of 6S and 16v diode the Zener voltage was changed only about 0.05V, which explained by higher current through diode and well known Voltage-Current characteristic of Zener diode.

Conclusion
To conclude, the proposed circuit allows to obtain higher resolution than with the simple resistive divider. The gain in the resolution of voltage measurement is more significant for higher voltage batteries like 6S batteries. However, the presence of Zener diode, which always have non ideal properties, may limit accuracy of voltage measurement with this accuracy dependent on the diode and current in the circuit. I would personally consider to use such circuit with 4S-6S batteries and I will be already satisfied with the simple divider in case of 3S battery. There is no reason at all to use proposed circuit with 1S or 2S batteries where is the simple divider is the right solution.