2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
20 #define VBAT_SCALE_DEFAULT 110
21 #define VBAT_RESDIVVAL_DEFAULT 10
22 #define VBAT_RESDIVMULTIPLIER_DEFAULT 1
23 #define VBAT_SCALE_MIN 0
24 #define VBAT_SCALE_MAX 255
26 #define VBATT_LPF_FREQ 1.0f
28 #ifndef MAX_VOLTAGE_METERS
29 #define MAX_VOLTAGE_METERS 1 // VBAT - some boards have external, 12V and 5V meters.
32 typedef struct voltageMeterConfig_s
{
33 uint8_t vbatscale
; // adjust this to match battery voltage to reported value
34 uint8_t vbatresdivval
; // resistor divider R2 (default NAZE 10(K))
35 uint8_t vbatresdivmultiplier
; // multiplier for scale (e.g. 2.5:1 ratio with multiplier of 4 can use '100' instead of '25' in ratio) to get better precision
36 } voltageMeterConfig_t
;
38 PG_DECLARE_ARR(voltageMeterConfig_t
, MAX_VOLTAGE_METERS
, voltageMeterConfig
);
40 typedef struct voltageMeterState_s
{
41 uint16_t vbat
; // battery voltage in 0.1V steps (filtered)
43 uint16_t vbatLatestADC
; // most recent unsmoothed raw reading from vbat ADC
44 biquadFilter_t vbatFilterState
;
45 } voltageMeterState_t
;
47 extern voltageMeterState_t voltageMeterStates
[MAX_VOLTAGE_METERS
];
50 void voltageMeterInit(void);
51 void voltageMeterUpdate(void);
53 voltageMeterState_t
*getVoltageMeter(uint8_t index
);
54 uint16_t getVoltageForADCChannel(uint8_t channel
);
55 uint16_t getLatestVoltageForADCChannel(uint8_t channel
);
57 voltageMeterConfig_t
*getVoltageMeterConfig(const uint8_t channel
);