Skip to content

Commit

Permalink
voltage calculations in chip_data, make intermediate values floats
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Jan 31, 2025
1 parent cd1e4d2 commit 909fa1c
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 176 deletions.
7 changes: 7 additions & 0 deletions Core/Inc/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ void calc_cell_temps(acc_data_t *bmsdata);
*/
void calc_pack_temps(acc_data_t *bmsdata);

/**
* @brief Calclaute the voltage of every cell in the pack.
*
* @param bmsdata Pointer to BMS data struct.
*/
void calc_cell_voltages(acc_data_t* bmsdata);

/**
* @brief Calculate statistics about pack voltage, such as min and max cell volt, pack and avg voltage, pack and avg OCV, and deltas.
*
Expand Down
40 changes: 21 additions & 19 deletions Core/Inc/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ typedef struct {
/* These are calculated during the analysis of data */

/* Cell temperature in celsius */
int8_t cell_temp[NUM_CELLS_ALPHA];
float cell_temp[NUM_CELLS_ALPHA];
float cell_resistance[NUM_CELLS_ALPHA];
uint16_t open_cell_voltage[NUM_CELLS_ALPHA];
float open_cell_voltage[NUM_CELLS_ALPHA];

float cell_voltages[NUM_CELLS_ALPHA];

uint8_t noise_reading
[NUM_CELLS_ALPHA]; /* bool representing noise ignored read */
Expand All @@ -30,7 +32,7 @@ typedef struct {
/* True if chip is alpha, False if Chip is Beta */
bool alpha;

/* For temperatures of on-board therms. Length 1 if Alpha, length 2 if Beta. */
/* For temperatures of on-board therms. */
int8_t on_board_temp;
} chipdata_t;

Expand Down Expand Up @@ -73,7 +75,7 @@ enum {
*
*/
typedef struct {
int32_t val;
float val;
uint8_t chipIndex;
uint8_t cellNum;
} crit_cellval_t;
Expand All @@ -95,18 +97,18 @@ typedef struct {

int fault_status; // FIXME: this field is unused

int16_t pack_current; /* this value is multiplied by 10 to account for decimal precision */
uint16_t pack_voltage;
uint16_t pack_ocv;
uint16_t pack_res;
float pack_current; /* this value is multiplied by 10 to account for decimal precision */
float pack_voltage;
float pack_ocv;
float pack_res;

uint16_t discharge_limit;
uint16_t charge_limit;
uint16_t cont_DCL;
uint16_t cont_CCL;
uint8_t soc;
float discharge_limit;
float charge_limit;
float cont_DCL;
float cont_CCL;
float soc;

int8_t segment_average_temps[NUM_SEGMENTS];
float segment_average_temps[NUM_SEGMENTS];
uint8_t segment_noise_percentage[NUM_SEGMENTS];

/**
Expand All @@ -119,7 +121,7 @@ typedef struct {
/* Max, min, and avg thermistor readings */
crit_cellval_t max_temp;
crit_cellval_t min_temp;
int8_t avg_temp;
float avg_temp;

/* Max and min cell resistances */
crit_cellval_t max_res;
Expand All @@ -128,13 +130,13 @@ typedef struct {
/* Max, min, and avg voltage of the cells */
crit_cellval_t max_voltage;
crit_cellval_t min_voltage;
uint16_t avg_voltage;
uint16_t delt_voltage;
float avg_voltage;
float delt_voltage;

crit_cellval_t max_ocv;
crit_cellval_t min_ocv;
uint16_t avg_ocv;
uint16_t delt_ocv;
float avg_ocv;
float delt_ocv;

uint16_t boost_setting;

Expand Down
Loading

0 comments on commit 909fa1c

Please sign in to comment.