Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
#include "std.h"
#include "mcu_periph/i2c.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/electrical.h"
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 |
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 |
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.
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.
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.
enum BatmonBusStatus |
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 I2CTransDone, I2CTransFailed, I2CTransPending, I2CTransRunning, I2CTransSuccess, and i2c_transaction::status.
Referenced by 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.
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.
Referenced by battery_monitor_read_balance_ports(), and battery_monitor_read_bus().
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().
void battery_monitor_init_balance | ( | struct 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().
void battery_monitor_init_bus | ( | void | ) |
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, I2CTransDone, i2c_transaction::status, and BatMonBus::t_idx.
Referenced by battery_monitor_init().
void battery_monitor_read_balance_ports | ( | struct BatMonBal * | ) |
Read balance ADC.
Definition at line 354 of file battery_monitor.c.
References BatMonBal::addr, BatMonBal::bat_cell_mvolts, BATTERY_CELLS_NB, BATTERY_MONITOR_BIT_RES, battery_monitor_cellgains, battery_monitor_cellmap, battery_monitor_get_address(), BATTERY_MONITOR_VREF_MULT, i2c_transaction::buf, BatMonBal::bus_trans, BatMonBal::cell_index, BatMonBal::data, i2c_transceive(), I2CTransDone, and i2c_transaction::status.
Referenced by battery_monitor_read_balance_ports_1(), and battery_monitor_read_balance_ports_2().
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().
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().
void battery_monitor_read_bus | ( | void | ) |
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, i2c_transceive(), I2CTransDone, i2c_transaction::status, BatMonBus::t_idx, TEMP_SENSORS_NB, and Electrical::vsupply.
int16_t batmon_current_offset |
Definition at line 39 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
float batmon_current_sensitivity |
Definition at line 40 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
int16_t batmon_temp_offset |
Definition at line 41 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
float batmon_temp_sensitivity |
Definition at line 42 of file battery_monitor.c.
Referenced by battery_monitor_init_bus(), and battery_monitor_read_bus().
struct BatMonBal batmonbal1 |
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().
struct BatMonBal batmonbal2 |
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().
struct BatMonBus batmonbus |
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().
|
static |
Definition at line 152 of file battery_monitor.h.
Referenced by battery_monitor_read_bus().
|
static |
Definition at line 120 of file battery_monitor.h.
Referenced by battery_monitor_read_balance_ports().
|
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().
|
static |
Definition at line 140 of file battery_monitor.h.
Referenced by battery_monitor_read_bus().