70 #ifndef BATTERY_MONITOR_H
71 #define BATTERY_MONITOR_H
79 #if BATTERY_MONITOR_REV4
81 #define BATTERY_MONITOR_BIT_RES 10 // define bit resolution: 12 for AD7998 (rev4)
84 #define BATTERY_MONITOR_BIT_RES 12 // define bit resolution: 10 for AD7997 (rev5)
88 #define BATTERY_MONITOR_VREF 5000 //mV
91 #define BATTERY_MONITOR_VREF_MULT BATTERY_MONITOR_VREF/(1<<BATTERY_MONITOR_BIT_RES)
94 #define BATTERY_CELLS_NB 6
97 #define TEMP_SENSORS_NB 6
103 #if BATTERY_MONITOR_REV4
105 #define GAIN_CELL_1 1.001
106 #define GAIN_CELL_2 2.011
107 #define GAIN_CELL_3 3.027
108 #define GAIN_CELL_4 4.063
109 #define GAIN_CELL_5 4.217
110 #define GAIN_CELL_6 4.973
113 #define GAIN_CELL_1 1.0
114 #define GAIN_CELL_2 2.0
115 #define GAIN_CELL_3 3.0
116 #define GAIN_CELL_4 4.03
117 #define GAIN_CELL_5 5.0
118 #define GAIN_CELL_6 6.0
134 #define BATTERY_MONITOR_BUS_CURRENT_CHANNEL 2
135 #define BATTERY_MONITOR_BUS_VOLTAGE_CHANNEL 4
147 #if BATTERY_MONITOR_REV4
161 #ifndef BATTERY_MONITOR_CURRENT_OFFSET //mV
162 #ifdef BATTERY_MONITOR_REV4
164 #define BATTERY_MONITOR_CURRENT_OFFSET -120
167 #define BATTERY_MONITOR_CURRENT_OFFSET -657
171 #ifndef BATTERY_MONITOR_CURRENT_SENSITIVITY //mV/A
172 #define BATTERY_MONITOR_CURRENT_SENSITIVITY 25.6
180 #ifndef BATTERY_MONITOR_TEMP_OFFSET //mV
181 #define BATTERY_MONITOR_TEMP_OFFSET 250
183 #ifndef BATTERY_MONITOR_TEMP_SENSITIVITY //mV/C
184 #define BATTERY_MONITOR_TEMP_SENSITIVITY 10
void battery_monitor_read_balance_ports(struct BatMonBal *)
Read balance ADC.
uint8_t battery_monitor_get_address(uint8_t channel)
Translates the channel number to the value for address pointer register Channels are numbered from 1 ...
void battery_monitor_read_balance_ports_1(void)
Read Balance ADC 1.
int16_t batmon_current_offset
struct BatMonBal batmonbal1
struct i2c_transaction bus_trans
void battery_monitor_init_bus(void)
Initializes bus ADC.
float bus_temp[TEMP_SENSORS_NB]
void battery_monitor_read_bus(void)
Read bus (current, voltage and temperature sensors)
static const float battery_monitor_cellgains[]
Battery monitor Bus ADC struct.
Battery monitor Balance ADC struct.
void battery_monitor_check_i2c_transaction(struct i2c_transaction *t)
Complete i2c transactions once they succeed or fail.
float batmon_current_sensitivity
uint16_t bus_current_mvolts
void battery_monitor_read_balance_ports_2(void)
Read Balance ADC 2.
uint16_t bus_voltage_mvolts
enum BatmonBusStatus bus_status
Interface for electrical status: supply voltage, current, battery status, etc.
Architecture independent timing functions.
void battery_monitor_init(void)
Init variables.
uint16_t bat_cell_mvolts[BATTERY_CELLS_NB]
I2C transaction structure.
BatmonBusStatus
Status for Bus ADC.
struct BatMonBus batmonbus
static const uint8_t battery_monitor_tempmap[]
static const uint8_t battery_monitor_cellmap[]
Cell map - which cell is which channel Channels are 1-indexed, ie.e.
int16_t batmon_temp_offset
void battery_monitor_event(void)
Event function Check i2c transaction status for each device.
struct BatMonBal batmonbal2
static const float BatmonVbusGain
struct i2c_transaction bus_trans
float batmon_temp_sensitivity
void battery_monitor_init_balance(struct BatMonBal *)
Initalizes balance ADC.
uint16_t bus_tempsensors_mvolts[TEMP_SENSORS_NB]
Architecture independent I2C (Inter-Integrated Circuit Bus) API.