|  | Paparazzi UAS v7.0_unstable
    Paparazzi is a free software Unmanned Aircraft System. | 
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:
 Include dependency graph for battery_monitor.h: This graph shows which files directly or indirectly include this file:
 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... | |
| 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. | |
| void | battery_monitor_init_bus (void) | 
| Initializes bus ADC. | |
| void | battery_monitor_init_balance (struct BatMonBal *) | 
| Initalizes balance ADC. | |
| void | battery_monitor_read_bus (void) | 
| Read bus (current, voltage and temperature sensors) | |
| void | battery_monitor_read_balance_ports_1 (void) | 
| Read Balance ADC 1. | |
| void | battery_monitor_read_balance_ports_2 (void) | 
| Read Balance ADC 2. | |
| void | battery_monitor_read_balance_ports (struct BatMonBal *) | 
| Read balance ADC. | |
| void | battery_monitor_event (void) | 
| Event function Check i2c transaction status for each device. | |
| void | battery_monitor_check_i2c_transaction (struct i2c_transaction *t) | 
| Complete i2c transactions once they succeed or fail. | |
| 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. | |
| 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. | |
| 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 | 
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.
| struct BatMonBus | 
Battery monitor Bus ADC struct.
Definition at line 210 of file battery_monitor.h.
 Collaboration diagram for BatMonBus:
 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 | |
| struct BatMonBal | 
Battery monitor Balance ADC struct.
Definition at line 235 of file battery_monitor.h.
 Collaboration diagram for BatMonBal:
 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 | |
| #define BATTERY_CELLS_NB 6 | 
Definition at line 94 of file battery_monitor.h.
| #define BATTERY_MONITOR_BIT_RES 12 | 
Definition at line 84 of file battery_monitor.h.
| #define BATTERY_MONITOR_BUS_CURRENT_CHANNEL 2 | 
Definition at line 134 of file battery_monitor.h.
| #define BATTERY_MONITOR_BUS_VOLTAGE_CHANNEL 4 | 
Definition at line 135 of file battery_monitor.h.
| #define BATTERY_MONITOR_CURRENT_OFFSET -657 | 
Definition at line 167 of file battery_monitor.h.
| #define BATTERY_MONITOR_CURRENT_SENSITIVITY 25.6 | 
Definition at line 172 of file battery_monitor.h.
| #define BATTERY_MONITOR_TEMP_OFFSET 250 | 
Definition at line 181 of file battery_monitor.h.
| #define BATTERY_MONITOR_TEMP_SENSITIVITY 10 | 
Definition at line 184 of file battery_monitor.h.
| #define BATTERY_MONITOR_VREF 5000 | 
Definition at line 88 of file battery_monitor.h.
| #define BATTERY_MONITOR_VREF_MULT BATTERY_MONITOR_VREF/(1<<BATTERY_MONITOR_BIT_RES) | 
Definition at line 91 of file battery_monitor.h.
| #define GAIN_CELL_1 1.0 | 
Definition at line 113 of file battery_monitor.h.
| #define GAIN_CELL_2 2.0 | 
Definition at line 114 of file battery_monitor.h.
| #define GAIN_CELL_3 3.0 | 
Definition at line 115 of file battery_monitor.h.
| #define GAIN_CELL_4 4.03 | 
Definition at line 116 of file battery_monitor.h.
| #define GAIN_CELL_5 5.0 | 
Definition at line 117 of file battery_monitor.h.
| #define GAIN_CELL_6 6.0 | 
Definition at line 118 of file battery_monitor.h.
| #define TEMP_SENSORS_NB 6 | 
Definition at line 97 of file battery_monitor.h.
Status for Bus ADC.
Definition at line 197 of file battery_monitor.h.
| 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 foo, I2CTransDone, I2CTransFailed, I2CTransPending, I2CTransRunning, and I2CTransSuccess.
Referenced by battery_monitor_event().
 Here is the caller graph for this function:
 Here is the caller graph for this function: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(), BatMonBus::bus_trans, and BatMonBal::bus_trans.
 Here is the call graph for this function:
 Here is the call graph for this function:Translates the channel number to the value for address pointer register Channels are numbered from 1 to 8.
| chan | - desired channel | 
Definition at line 91 of file battery_monitor.c.
References foo.
Referenced by battery_monitor_read_balance_ports(), and battery_monitor_read_bus().
 Here is the caller graph for this function:
 Here is the caller graph for this function: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, foo, register_periodic_telemetry(), and send_batmon().
 Here is the call graph for this function:
 Here is the call graph for this function:Initalizes balance ADC.
Definition at line 130 of file battery_monitor.c.
References foo, and I2CTransDone.
Referenced by battery_monitor_init().
 Here is the caller graph for this function:
 Here is the caller graph for this function:Initializes bus ADC.
Definition at line 102 of file battery_monitor.c.
References BatMonBus::addr, batmon_current_offset, batmon_current_sensitivity, batmon_temp_offset, batmon_temp_sensitivity, batmonbus, BATTERY_MONITOR_BUS_CURRENT_REQ, BATTERY_MONITOR_CURRENT_OFFSET, BATTERY_MONITOR_CURRENT_SENSITIVITY, BATTERY_MONITOR_TEMP_OFFSET, BATTERY_MONITOR_TEMP_SENSITIVITY, BatMonBus::bus_brd_tmp, BatMonBus::bus_current, BatMonBus::bus_current_mvolts, BatMonBus::bus_status, BatMonBus::bus_temp, BatMonBus::bus_tempsensors_mvolts, BatMonBus::bus_trans, BatMonBus::bus_voltage_mvolts, BatMonBus::data, foo, I2CTransDone, i2c_transaction::status, and BatMonBus::t_idx.
Referenced by battery_monitor_init().
 Here is the caller graph for this function:
 Here is the caller graph for this function:Read balance ADC.
Definition at line 354 of file battery_monitor.c.
References BATTERY_CELLS_NB, BATTERY_MONITOR_BIT_RES, battery_monitor_cellgains, battery_monitor_cellmap, battery_monitor_get_address(), BATTERY_MONITOR_VREF_MULT, foo, i2c_transceive(), and I2CTransDone.
Referenced by battery_monitor_read_balance_ports_1(), and battery_monitor_read_balance_ports_2().
 Here is the call graph for this function:
 Here is the call graph for this function: Here is the caller graph for this function:
 Here is the caller graph for this function: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:
 Here is the call graph for this function: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:
 Here is the call graph for this function:Read bus (current, voltage and temperature sensors)
Definition at line 197 of file battery_monitor.c.
References BatMonBus::addr, batmon_current_offset, batmon_current_sensitivity, batmon_temp_offset, batmon_temp_sensitivity, batmonbus, BatmonVbusGain, BATTERY_MONITOR_BIT_RES, BATTERY_MONITOR_BUS_CURRENT_CHANNEL, BATTERY_MONITOR_BUS_CURRENT_READ, BATTERY_MONITOR_BUS_CURRENT_REQ, BATTERY_MONITOR_BUS_TEMPERATURE_READ, BATTERY_MONITOR_BUS_TEMPERATURE_REQ, BATTERY_MONITOR_BUS_VOLTAGE_CHANNEL, BATTERY_MONITOR_BUS_VOLTAGE_READ, BATTERY_MONITOR_BUS_VOLTAGE_REQ, battery_monitor_get_address(), battery_monitor_tempmap, BATTERY_MONITOR_VREF_MULT, i2c_transaction::buf, BatMonBus::bus_current, BatMonBus::bus_current_mvolts, BatMonBus::bus_status, BatMonBus::bus_temp, BatMonBus::bus_tempsensors_mvolts, BatMonBus::bus_trans, BatMonBus::bus_voltage_mvolts, Electrical::current, BatMonBus::data, electrical, foo, i2c_transceive(), I2CTransDone, i2c_transaction::status, BatMonBus::t_idx, TEMP_SENSORS_NB, and Electrical::vsupply.
 Here is the call graph for this function:
 Here is the call graph for this function:| 
 | extern | 
Definition at line 39 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
| 
 | extern | 
Definition at line 40 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
| 
 | extern | 
Definition at line 41 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
| 
 | extern | 
Definition at line 42 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
| 
 | extern | 
Definition at line 35 of file battery_monitor.c.
Referenced by battery_monitor_event(), battery_monitor_init(), battery_monitor_read_balance_ports_1(), and send_batmon().
| 
 | extern | 
Definition at line 36 of file battery_monitor.c.
Referenced by battery_monitor_event(), battery_monitor_init(), battery_monitor_read_balance_ports_2(), and send_batmon().
| 
 | extern | 
Definition at line 34 of file battery_monitor.c.
Referenced by battery_monitor_event(), battery_monitor_init_bus(), battery_monitor_read_bus(), and send_batmon().
Definition at line 152 of file battery_monitor.h.
Referenced by battery_monitor_read_bus().
Definition at line 120 of file battery_monitor.h.
Referenced by battery_monitor_read_balance_ports().
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().
Definition at line 140 of file battery_monitor.h.
Referenced by battery_monitor_read_bus().