Add DMA handlers to targets
[betaflight.git] / docs / Battery.md
blob00079944245c6157c31038a66cb23bae97739345
1 # Battery Monitoring
3 Cleanflight has a battery monitoring feature.  The voltage of the main battery can be measured by the system and used to trigger a low-battery warning [buzzer](Buzzer.md), on-board status LED flashing and LED strip patterns.
5 Low battery warnings can:
7 * Help ensure you have time to safely land the aircraft
8 * Help maintain the life and safety of your LiPo/LiFe batteries, which should not be discharged below manufacturer recommendations
10 Minimum and maximum cell voltages can be set, and these voltages are used to auto-detect the number of cells in the battery when it is first connected.
12 Per-cell monitoring is not supported, as we only use one ADC to read the battery voltage.
13   
14 ## Supported targets
16 All targets support battery voltage monitoring unless status.
18 ## Connections
20 When dealing with batteries **ALWAYS CHECK POLARITY!**
22 Measure expected voltages **first** and then connect to the flight controller.  Powering the flight controller with
23 incorrect voltage or reversed polarity will likely fry your flight controller. Ensure your flight controller
24 has a voltage divider capable of measuring your particular battery voltage.
26 ### Naze32
28 The Naze32 has an on-board battery divider circuit; just connect your main battery to the VBAT connector.
30 **CAUTION:**  When installing the connection from main battery to the VBAT connector, be sure to first disconnect the main battery from the frame/power distribution board.  Check the wiring very carefully before connecting battery again.  Incorrect connections can immediately and completely destroy the flight controller and connected peripherals (ESC, GPS, Receiver etc.).
32 ### CC3D
34 The CC3D has no battery divider.  To use voltage monitoring, you must create a divider that gives a 3.3v 
35 MAXIMUM output when the main battery is fully charged.  Connect the divider output to S5_IN/PA0/RC5.
37 Notes:
39 * S5_IN/PA0/RC5 is Pin 7 on the 8 pin connector, second to last pin, on the opposite end from the 
40   GND/+5/PPM signal input.
42 * When battery monitoring is enabled on the CC3D, RC5 can no-longer be used for PWM input.
44 ### Sparky
46 See the [Sparky board chapter](Board - Sparky.md).
48 ## Configuration
50 Enable the `VBAT` feature.
52 Configure min/max cell voltages using the following CLI setting:
54 `vbat_scale` - Adjust this to match actual measured battery voltage to reported value.
56 `vbat_max_cell_voltage` - Maximum voltage per cell, used for auto-detecting battery voltage in 0.1V units, i.e. 43 = 4.3V
58 `set vbat_warning_cell_voltage` - Warning voltage per cell; this triggers battery-out alarms, in 0.1V units, i.e. 34 = 3.4V
60 `vbat_min_cell_voltage` - Minimum voltage per cell; this triggers battery-out alarms, in 0.1V units, i.e. 33 = 3.3V
62 e.g.
64 ```
65 set vbat_scale = 110
66 set vbat_max_cell_voltage = 43
67 set vbat_warning_cell_voltage = 34
68 set vbat_min_cell_voltage = 33
69 ```
71 # Current Monitoring
73 Current monitoring (amperage) is supported by connecting a current meter to the appropriate current meter ADC input (see the documentation for your particular board).
75 When enabled, the following values calculated and used by the telemetry and OLED display subsystems:
76 * Amps
77 * mAh used
78 * Capacity remaining
80 ## Configuration
82 Enable current monitoring using the CLI command:
84 ```
85 feature CURRENT_METER
86 ```
88 Configure the current meter type using the `current_meter_type` settings here:
90 | Value | Sensor Type            |
91 | ----- | ---------------------- | 
92 | 0     | None                   |
93 | 1     | ADC/hardware sensor    |
94 | 2     | Virtual sensor         |
96 Configure capacity using the `battery_capacity` setting, in mAh units.
98 If you're using an OSD that expects the multiwii current meter output value, then set `multiwii_current_meter_output` to `1` (this multiplies amperage sent to MSP by 10).
100 ### ADC Sensor
102 The current meter may need to be configured so the value read at the ADC input matches actual current draw.  Just like you need a voltmeter to correctly calibrate your voltage reading you also need an ammeter to calibrate the current sensor.
104 Use the following settings to adjust calibration:
106 `current_meter_scale`
107 `current_meter_offset`
109 ### Virtual Sensor
111 The virtual sensor uses the throttle position to calculate an estimated current value. This is useful when a real sensor is not available. The following settings adjust the virtual sensor calibration:
113 | Setting                       | Description                                              |
114 | ----------------------------- | -------------------------------------------------------- | 
115 | `current_meter_scale`      | The throttle scaling factor [centiamps, i.e. 1/100th A]  |
116 | `current_meter_offset`     | The current at zero throttle (while disarmed) [centiamps, i.e. 1/100th A] |
118 There are two simple methods to tune these parameters:  one uses a battery charger and another depends on actual current measurements.
120 #### Tuning Using Actual Current Measurements
121 If you know your craft's current draw while disarmed (Imin) and at maximum throttle while armed (Imax), calculate the scaling factors as follows:
123 current_meter_scale = (Imax - Imin) * 100000 / (Tmax + (Tmax * Tmax / 50))
124 current_meter_offset = Imin * 100
126 Note: Tmax is maximum throttle offset (i.e. for `max_throttle` = 1850, Tmax = 1850 - 1000 = 850)
128 For example, assuming a maximum current of 34.2A, a minimum current of 2.8A, and a Tmax `max_throttle` = 1850:
130 current_meter_scale = (Imax - Imin) * 100000 / (Tmax + (Tmax * Tmax / 50))
131                     = (34.2 - 2.8) * 100000 / (850 + (850 * 850 / 50))
132                     = 205
133 current_meter_offset = Imin * 100 = 280
135 #### Tuning Using Battery Charger Measurement
136 If you cannot measure current draw directly, you can approximate it indirectly using your battery charger.  
137 However, note it may be difficult to adjust `current_meter_offset` using this method unless you can 
138 measure the actual current draw with the craft disarmed.
140 Note:
141 + This method depends on the accuracy of your battery charger; results may vary.
142 + If you add or replace equipment that changes the in-flight current draw (e.g. video transmitter, 
143   camera, gimbal, motors, prop pitch/sizes, ESCs, etc.), you should recalibrate.
145 The general method is:
147 1. Fully charge your flight battery
148 2. Fly your craft, using >50% of your battery pack capacity (estimated)
149 3. Note Cleanflight's reported mAh draw
150 4. Re-charge your flight battery, noting the mAh charging data needed to restore the pack to fully charged
151 5. Adjust `current_meter_scale` to according to the formula given below
152 6. Repeat and test
154 Given (a) the reported mAh draw and the (b) mAh charging data, calculate a new `current_meter_scale` value as follows:
156 current_meter_scale = (charging_data_mAh / reported_draw_mAh) * old_current_meter_scale
158 For example, assuming:
159 + A Cleanflight reported current draw of 1260 mAh
160 + Charging data to restore full charge of 1158 mAh
161 + A existing `current_meter_scale` value of 400 (the default)
163 Then the updated `current_meter_scale` is:
165 current_meter_scale = (charging_data_mAh / reported_draw_mAh) * old_current_meter_scale
166                     = (1158 / 1260) * 400
167                     = 368