70 #ifndef BATTERY_MONITOR_H
71 #define BATTERY_MONITOR_H
79 #if BATTERY_MONITOR_REV4
81 #define BATTERY_MONITOR_BIT_RES 10
84 #define BATTERY_MONITOR_BIT_RES 12
88 #define BATTERY_MONITOR_VREF 5000
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
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
172 #define BATTERY_MONITOR_CURRENT_SENSITIVITY 25.6
180 #ifndef BATTERY_MONITOR_TEMP_OFFSET
181 #define BATTERY_MONITOR_TEMP_OFFSET 250
183 #ifndef BATTERY_MONITOR_TEMP_SENSITIVITY
184 #define BATTERY_MONITOR_TEMP_SENSITIVITY 10
enum BatmonBusStatus bus_status
int16_t batmon_current_offset
static const float BatmonVbusGain
void battery_monitor_event(void)
Event function Check i2c transaction status for each device.
void battery_monitor_read_balance_ports_1(void)
Read Balance ADC 1.
struct i2c_transaction bus_trans
void battery_monitor_read_balance_ports_2(void)
Read Balance ADC 2.
void battery_monitor_init_balance(struct BatMonBal *)
Initalizes 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 ...
struct i2c_transaction bus_trans
BatmonBusStatus
Status for Bus ADC.
@ BATTERY_MONITOR_BUS_VOLTAGE_REQ
@ BATTERY_MONITOR_BUS_VOLTAGE_READ
@ BATTERY_MONITOR_BUS_CURRENT_REQ
@ BATTERY_MONITOR_BUS_TEMPERATURE_READ
@ BATTERY_MONITOR_BUS_CURRENT_READ
@ BATTERY_MONITOR_BUS_TEMPERATURE_REQ
float batmon_current_sensitivity
float batmon_temp_sensitivity
void battery_monitor_check_i2c_transaction(struct i2c_transaction *t)
Complete i2c transactions once they succeed or fail.
struct BatMonBal batmonbal2
static const uint8_t battery_monitor_tempmap[]
uint16_t bus_voltage_mvolts
static const uint8_t battery_monitor_cellmap[]
Cell map - which cell is which channel Channels are 1-indexed, ie.e.
void battery_monitor_read_balance_ports(struct BatMonBal *)
Read balance ADC.
void battery_monitor_init_bus(void)
Initializes bus ADC.
int16_t batmon_temp_offset
static const float battery_monitor_cellgains[]
uint16_t bus_current_mvolts
void battery_monitor_read_bus(void)
Read bus (current, voltage and temperature sensors)
void battery_monitor_init(void)
Init variables.
struct BatMonBal batmonbal1
float bus_temp[TEMP_SENSORS_NB]
uint16_t bus_tempsensors_mvolts[TEMP_SENSORS_NB]
struct BatMonBus batmonbus
uint16_t bat_cell_mvolts[BATTERY_CELLS_NB]
Battery monitor Balance ADC struct.
Battery monitor Bus ADC struct.
Interface for electrical status: supply voltage, current, battery status, etc.
I2C transaction structure.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.