Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
battery_monitor.h File Reference

driver for ADC AD7997 on a custom made power board version 4.0 and 5.0 More...

#include "std.h"
#include "mcu_periph/i2c.h"
#include "mcu_periph/sys_time.h"
#include "modules/energy/electrical.h"
+ Include dependency graph for battery_monitor.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BatMonBus
 Battery monitor Bus ADC struct. More...
 
struct  BatMonBal
 Battery monitor Balance ADC struct. More...
 

Macros

#define BATTERY_MONITOR_BIT_RES   12
 
#define BATTERY_MONITOR_VREF   5000
 
#define BATTERY_MONITOR_VREF_MULT   BATTERY_MONITOR_VREF/(1<<BATTERY_MONITOR_BIT_RES)
 
#define BATTERY_CELLS_NB   6
 
#define TEMP_SENSORS_NB   6
 
#define GAIN_CELL_1   1.0
 
#define GAIN_CELL_2   2.0
 
#define GAIN_CELL_3   3.0
 
#define GAIN_CELL_4   4.03
 
#define GAIN_CELL_5   5.0
 
#define GAIN_CELL_6   6.0
 
#define BATTERY_MONITOR_BUS_CURRENT_CHANNEL   2
 
#define BATTERY_MONITOR_BUS_VOLTAGE_CHANNEL   4
 
#define BATTERY_MONITOR_CURRENT_OFFSET   -657
 
#define BATTERY_MONITOR_CURRENT_SENSITIVITY   25.6
 
#define BATTERY_MONITOR_TEMP_OFFSET   250
 
#define BATTERY_MONITOR_TEMP_SENSITIVITY   10
 

Enumerations

enum  BatmonBusStatus {
  BATTERY_MONITOR_BUS_CURRENT_REQ , BATTERY_MONITOR_BUS_CURRENT_READ , BATTERY_MONITOR_BUS_VOLTAGE_REQ , BATTERY_MONITOR_BUS_VOLTAGE_READ ,
  BATTERY_MONITOR_BUS_TEMPERATURE_REQ , BATTERY_MONITOR_BUS_TEMPERATURE_READ
}
 Status for Bus ADC. More...
 

Functions

void battery_monitor_init (void)
 Init variables. More...
 
void battery_monitor_init_bus (void)
 Initializes bus ADC. More...
 
void battery_monitor_init_balance (struct BatMonBal *)
 Initalizes balance ADC. More...
 
void battery_monitor_read_bus (void)
 Read bus (current, voltage and temperature sensors) More...
 
void battery_monitor_read_balance_ports_1 (void)
 Read Balance ADC 1. More...
 
void battery_monitor_read_balance_ports_2 (void)
 Read Balance ADC 2. More...
 
void battery_monitor_read_balance_ports (struct BatMonBal *)
 Read balance ADC. More...
 
void battery_monitor_event (void)
 Event function Check i2c transaction status for each device. More...
 
void battery_monitor_check_i2c_transaction (struct i2c_transaction *t)
 Complete i2c transactions once they succeed or fail. More...
 
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 to 8. More...
 

Variables

static const float battery_monitor_cellgains []
 
static const uint8_t battery_monitor_cellmap [] = {2,4,6,8,5,7}
 Cell map - which cell is which channel Channels are 1-indexed, ie.e. More...
 
static const uint8_t battery_monitor_tempmap [] = {1,3,5,6,7,8}
 
static const float BatmonVbusGain = 6.0
 
int16_t batmon_current_offset
 
float batmon_current_sensitivity
 
int16_t batmon_temp_offset
 
float batmon_temp_sensitivity
 
struct BatMonBus batmonbus
 
struct BatMonBal batmonbal1
 
struct BatMonBal batmonbal2
 

Detailed Description

driver for ADC AD7997 on a custom made power board version 4.0 and 5.0

Power board has:

BUS_ADC two possible addresses: 010 0001 (AD7997-0) = 0x21 (pprz: 0x42) 010 0011 (AD7997-1) = 0x23 (pprz: 0x46) channels: VIN1 - Temp_1 VIN2 - Current sensor VIN3 - PWR_BRD_Temp VIN4 - Vin VIN5 - Temp_2 VIN6 - Batt_Temp1 VIN7 - Temp_3 VIN8 - Batt_temp_2

BALANCE_ADC_1 (battery 1) address: 010 0000 (AD7997-1 or AD7997-0) = 0x20 (pprz: 0x40) channels: VIN1 - NC VIN2 - Cell_1 VIN3 - NC VIN4 - Cell_2 VIN5 - Cell_5 VIN6 - Cell_3 VIN7 - Cell_6 VIN8 - Cell_4

BALANCE_ADC_2 (battery 2) address: 010 0010 (AD7997-0) = 0x22 (pprz: 0x44) 010 0100 (AD7997-1) = 0x24 (pprz: 0x48) channels: VIN1 - NC VIN2 - Cell_1 VIN3 - NC VIN4 - Cell_2 VIN5 - NC VIN6 - Cell_3 VIN7 - NC VIN8 - Cell_4

Definition in file battery_monitor.h.


Data Structure Documentation

◆ BatMonBus

struct BatMonBus

Battery monitor Bus ADC struct.

Definition at line 210 of file battery_monitor.h.

+ Collaboration diagram for BatMonBus:
Data Fields
uint8_t addr
float bus_brd_tmp
float bus_current
uint16_t bus_current_mvolts
enum BatmonBusStatus bus_status
float bus_temp[TEMP_SENSORS_NB]
uint16_t bus_tempsensors_mvolts[TEMP_SENSORS_NB]
struct i2c_transaction bus_trans
uint16_t bus_voltage_mvolts
uint16_t data
uint8_t t_idx

◆ BatMonBal

struct BatMonBal

Battery monitor Balance ADC struct.

Definition at line 235 of file battery_monitor.h.

+ Collaboration diagram for BatMonBal:
Data Fields
uint8_t addr
uint16_t bat_cell_mvolts[BATTERY_CELLS_NB]
struct i2c_transaction bus_trans
uint8_t cell_index
uint16_t data

Macro Definition Documentation

◆ BATTERY_CELLS_NB

#define BATTERY_CELLS_NB   6

Definition at line 94 of file battery_monitor.h.

◆ BATTERY_MONITOR_BIT_RES

#define BATTERY_MONITOR_BIT_RES   12

Definition at line 84 of file battery_monitor.h.

◆ BATTERY_MONITOR_BUS_CURRENT_CHANNEL

#define BATTERY_MONITOR_BUS_CURRENT_CHANNEL   2

Definition at line 134 of file battery_monitor.h.

◆ BATTERY_MONITOR_BUS_VOLTAGE_CHANNEL

#define BATTERY_MONITOR_BUS_VOLTAGE_CHANNEL   4

Definition at line 135 of file battery_monitor.h.

◆ BATTERY_MONITOR_CURRENT_OFFSET

#define BATTERY_MONITOR_CURRENT_OFFSET   -657

Definition at line 167 of file battery_monitor.h.

◆ BATTERY_MONITOR_CURRENT_SENSITIVITY

#define BATTERY_MONITOR_CURRENT_SENSITIVITY   25.6

Definition at line 172 of file battery_monitor.h.

◆ BATTERY_MONITOR_TEMP_OFFSET

#define BATTERY_MONITOR_TEMP_OFFSET   250

Definition at line 181 of file battery_monitor.h.

◆ BATTERY_MONITOR_TEMP_SENSITIVITY

#define BATTERY_MONITOR_TEMP_SENSITIVITY   10

Definition at line 184 of file battery_monitor.h.

◆ BATTERY_MONITOR_VREF

#define BATTERY_MONITOR_VREF   5000

Definition at line 88 of file battery_monitor.h.

◆ BATTERY_MONITOR_VREF_MULT

#define BATTERY_MONITOR_VREF_MULT   BATTERY_MONITOR_VREF/(1<<BATTERY_MONITOR_BIT_RES)

Definition at line 91 of file battery_monitor.h.

◆ GAIN_CELL_1

#define GAIN_CELL_1   1.0

Definition at line 113 of file battery_monitor.h.

◆ GAIN_CELL_2

#define GAIN_CELL_2   2.0

Definition at line 114 of file battery_monitor.h.

◆ GAIN_CELL_3

#define GAIN_CELL_3   3.0

Definition at line 115 of file battery_monitor.h.

◆ GAIN_CELL_4

#define GAIN_CELL_4   4.03

Definition at line 116 of file battery_monitor.h.

◆ GAIN_CELL_5

#define GAIN_CELL_5   5.0

Definition at line 117 of file battery_monitor.h.

◆ GAIN_CELL_6

#define GAIN_CELL_6   6.0

Definition at line 118 of file battery_monitor.h.

◆ TEMP_SENSORS_NB

#define TEMP_SENSORS_NB   6

Definition at line 97 of file battery_monitor.h.

Enumeration Type Documentation

◆ BatmonBusStatus

Status for Bus ADC.

Enumerator
BATTERY_MONITOR_BUS_CURRENT_REQ 
BATTERY_MONITOR_BUS_CURRENT_READ 
BATTERY_MONITOR_BUS_VOLTAGE_REQ 
BATTERY_MONITOR_BUS_VOLTAGE_READ 
BATTERY_MONITOR_BUS_TEMPERATURE_REQ 
BATTERY_MONITOR_BUS_TEMPERATURE_READ 

Definition at line 197 of file battery_monitor.h.

Function Documentation

◆ battery_monitor_check_i2c_transaction()

void battery_monitor_check_i2c_transaction ( struct i2c_transaction t)

Complete i2c transactions once they succeed or fail.

Definition at line 170 of file battery_monitor.c.

References I2CTransDone, I2CTransFailed, I2CTransPending, I2CTransRunning, I2CTransSuccess, and i2c_transaction::status.

Referenced by battery_monitor_event().

+ Here is the caller graph for this function:

◆ battery_monitor_event()

void battery_monitor_event ( void  )

Event function Check i2c transaction status for each device.

Definition at line 161 of file battery_monitor.c.

References batmonbal1, batmonbal2, batmonbus, battery_monitor_check_i2c_transaction(), BatMonBal::bus_trans, and BatMonBus::bus_trans.

+ Here is the call graph for this function:

◆ battery_monitor_get_address()

uint8_t battery_monitor_get_address ( uint8_t  chan)

Translates the channel number to the value for address pointer register Channels are numbered from 1 to 8.

Parameters
chan- desired channel
Returns
addres pointer Byte (see AD7997/8 datasheet)

Definition at line 91 of file battery_monitor.c.

Referenced by battery_monitor_read_balance_ports(), and battery_monitor_read_bus().

+ Here is the caller graph for this function:

◆ battery_monitor_init()

void battery_monitor_init ( void  )

Init variables.

Definition at line 140 of file battery_monitor.c.

References BatMonBal::addr, batmonbal1, batmonbal2, battery_monitor_init_balance(), battery_monitor_init_bus(), DefaultPeriodic, register_periodic_telemetry(), and send_batmon().

+ Here is the call graph for this function:

◆ battery_monitor_init_balance()

void battery_monitor_init_balance ( struct BatMonBal batmonbal)

Initalizes balance ADC.

Definition at line 130 of file battery_monitor.c.

References BatMonBal::bat_cell_mvolts, BatMonBal::bus_trans, BatMonBal::cell_index, BatMonBal::data, I2CTransDone, and i2c_transaction::status.

Referenced by battery_monitor_init().

+ Here is the caller graph for this function:

◆ battery_monitor_init_bus()

◆ battery_monitor_read_balance_ports()

◆ battery_monitor_read_balance_ports_1()

void battery_monitor_read_balance_ports_1 ( void  )

Read Balance ADC 1.

Definition at line 340 of file battery_monitor.c.

References batmonbal1, and battery_monitor_read_balance_ports().

+ Here is the call graph for this function:

◆ battery_monitor_read_balance_ports_2()

void battery_monitor_read_balance_ports_2 ( void  )

Read Balance ADC 2.

Definition at line 347 of file battery_monitor.c.

References batmonbal2, and battery_monitor_read_balance_ports().

+ Here is the call graph for this function:

◆ battery_monitor_read_bus()

Variable Documentation

◆ batmon_current_offset

int16_t batmon_current_offset
extern

Definition at line 39 of file battery_monitor.c.

Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().

◆ batmon_current_sensitivity

float batmon_current_sensitivity
extern

Definition at line 40 of file battery_monitor.c.

Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().

◆ batmon_temp_offset

int16_t batmon_temp_offset
extern

Definition at line 41 of file battery_monitor.c.

Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().

◆ batmon_temp_sensitivity

float batmon_temp_sensitivity
extern

Definition at line 42 of file battery_monitor.c.

Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().

◆ batmonbal1

struct BatMonBal batmonbal1
extern

◆ batmonbal2

struct BatMonBal batmonbal2
extern

◆ batmonbus

struct BatMonBus batmonbus
extern

◆ BatmonVbusGain

const float BatmonVbusGain = 6.0
static

Definition at line 152 of file battery_monitor.h.

Referenced by battery_monitor_read_bus().

◆ battery_monitor_cellgains

const float battery_monitor_cellgains[]
static
Initial value:
#define GAIN_CELL_4
#define GAIN_CELL_1
#define GAIN_CELL_2
#define GAIN_CELL_6
#define GAIN_CELL_5
#define GAIN_CELL_3

Definition at line 120 of file battery_monitor.h.

Referenced by battery_monitor_read_balance_ports().

◆ battery_monitor_cellmap

const uint8_t battery_monitor_cellmap[] = {2,4,6,8,5,7}
static

Cell map - which cell is which channel Channels are 1-indexed, ie.e.

Channel 1 - Channel 8 Cells are 0-indexed (because of their position in the array) So cell at battery_monitor_cellmap[0] is the first cell etc.

Definition at line 129 of file battery_monitor.h.

Referenced by battery_monitor_read_balance_ports().

◆ battery_monitor_tempmap

const uint8_t battery_monitor_tempmap[] = {1,3,5,6,7,8}
static

Definition at line 140 of file battery_monitor.h.

Referenced by battery_monitor_read_bus().