Skip to content

Commit

Permalink
adbms add chips to acc_data_t and make functions compatible with new …
Browse files Browse the repository at this point in the history
…datastructure
  • Loading branch information
Sabramz committed Dec 25, 2024
1 parent f0a2a60 commit e611107
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 180 deletions.
4 changes: 4 additions & 0 deletions Core/Inc/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bmsConfig.h"
#include "timer.h"
#include "cmsis_os2.h"
#include "adBms6830Data.h"

/**
* @brief Individual chip data
Expand Down Expand Up @@ -84,6 +85,9 @@ typedef struct {
/* Array of data from all chips in the system */
chipdata_t chip_data[NUM_CHIPS];

/* Array of structs containing raw data from and configurations for the ADBMS6830 chips */
cell_asic chips[NUM_CHIPS];

int fault_status;

int16_t pack_current; /* this value is multiplied by 10 to account for decimal precision */
Expand Down
15 changes: 9 additions & 6 deletions Core/Inc/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ void segment_init();
*
* @todo make sure that retrieving cell data doesn't block code too much
*/
void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]);
void segment_retrieve_data(acc_data_t *bmsdata);

/**
* @brief Enables/disables balancing for all cells
*
* @param balance_enable
* @param chips Array of ADBMS6830 data structs.
* @param balance_enable False to disable balancing, true to enable.
*/
void segment_enable_balancing(bool balance_enable);
void segment_enable_balancing(cell_asic chips[NUM_CHIPS], bool balance_enable);

/**
* @brief Enables/disables balancing for a specific cell
Expand All @@ -35,11 +36,13 @@ void cell_enable_balancing(uint8_t chip_num, uint8_t cell_num,
bool balance_enable);

/**
* @brief Sets each cell to whatever state is passed in the boolean config area
*
* @param discharge_config
* @brief Set the cell balancing configuration and send it to the segments.
*
* @param chips Array of ADBMS6830 data structs.
* @param discharge_config Configuration for which cells to discharge.
*/
void segment_configure_balancing(
cell_asic chips[NUM_CHIPS],
bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP]);

/**
Expand Down
64 changes: 25 additions & 39 deletions Core/Src/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,6 @@ const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS] =
{6 + MUX_OFFSET, 8 + MUX_OFFSET, NO_THERM},
};

uint8_t THERM_DISABLE[NUM_CHIPS][NUM_THERMS_PER_CHIP] =
{
{1,0,1,0,0,1,0,1,1,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,1,0 },
{1,0,1,0,0,1,0,0,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1 },
{1,0,1,0,0,1,0,0,1,0,0,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0 },
{1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,0,0,0,1,1,1,0,1,0,0,1,0,0,0,0 },
{1,0,1,0,0,1,0,1,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1 },
{1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0 },
{1,0,1,0,0,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,0,0,0,0,0,1,0 },
{1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,1,1,1,1 },
{1,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{1,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0 },
{1,1,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{1,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0 }
};

/*
* List of therms that we actually read from, NOT reordered by cell
*/
Expand Down Expand Up @@ -225,9 +209,11 @@ void calc_pack_temps(acc_data_t *bmsdata)
bmsdata->min_temp.val = MAX_TEMP;
bmsdata->min_temp.cellNum = 0;
bmsdata->min_temp.chipIndex = 0;

int total_temp = 0;
int total_seg_temp = 0;
int total_accepted = 0;

for (uint8_t c = 0; c < NUM_CHIPS; c++) {
for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) {
/* finds out the maximum cell temp and location */
Expand Down Expand Up @@ -638,29 +624,29 @@ uint8_t analyzer_calc_fan_pwm(acc_data_t *bmsdata)
(2 * 5);
}

void disable_therms(acc_data_t *bmsdata)
{
int8_t tmp_temp =
25; /* Iniitalize to room temp (necessary to stabilize when the BMS first boots up/has null values) */
if (!is_first_reading_)
tmp_temp =
bmsdata->avg_temp; /* Set to actual average temp of the pack */

for (uint8_t c = 0; c < NUM_CHIPS; c++) {
for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) {
/* If 2D LUT shows therm should be disable */
if (THERM_DISABLE[c][therm]) {
/* Nullify thermistor by setting to pack average */
bmsdata->chip_data[c].thermistor_value[therm] =
tmp_temp;
} else {
bmsdata->chip_data[c].thermistor_value[therm] =
bmsdata->chip_data[c]
.thermistor_reading[therm];
}
}
}
}
// void disable_therms(acc_data_t *bmsdata)
// {
// int8_t tmp_temp =
// 25; /* Iniitalize to room temp (necessary to stabilize when the BMS first boots up/has null values) */
// if (!is_first_reading_)
// tmp_temp =
// bmsdata->avg_temp; /* Set to actual average temp of the pack */

// for (uint8_t c = 0; c < NUM_CHIPS; c++) {
// for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) {
// /* If 2D LUT shows therm should be disable */
// if (THERM_DISABLE[c][therm]) {
// /* Nullify thermistor by setting to pack average */
// bmsdata->chip_data[c].thermistor_value[therm] =
// tmp_temp;
// } else {
// bmsdata->chip_data[c].thermistor_value[therm] =
// bmsdata->chip_data[c]
// .thermistor_reading[therm];
// }
// }
// }
// }

void calc_state_of_charge(acc_data_t *bmsdata)
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ int main(void)

HAL_Delay(500);
init_both_can(&hcan1, &hcan2);
segment_init();
segment_init(acc_data->chip_data);
compute_init();
printf("Init passed\n");
/* USER CODE END 2 */
Expand Down
Loading

0 comments on commit e611107

Please sign in to comment.