Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADBMS Integration #138

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Drivers/Embedded-Base"]
path = Drivers/Embedded-Base
url = https://github.com/Northeastern-Electric-Racing/Embedded-Base.git
[submodule "Drivers/adbms"]
path = Drivers/adbms
url = [email protected]:Northeastern-Electric-Racing/adbms.git
6 changes: 3 additions & 3 deletions Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define BMS_CONFIG_H

// Hardware definition
#define NUM_SEGMENTS 6
#define NUM_CHIPS NUM_SEGMENTS * 2
#define NUM_CELLS_PER_CHIP 10
#define NUM_SEGMENTS 1
#define NUM_CHIPS 1 //NUM_SEGMENTS * 2
#define NUM_CELLS_PER_CHIP 16
#define NUM_THERMS_PER_CHIP 32
#define NUM_RELEVANT_THERMS 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the number of therms that we actually wanted to read on a segment. I think we'll be getting rid of this but i think its outside the scope of this.


Expand Down
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
39 changes: 15 additions & 24 deletions Core/Inc/segment.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SEGMENT_H
#define SEGMENT_H

#include "ltc68041.h"
#include "bmsConfig.h"
#include "datastructs.h"

Expand All @@ -15,31 +14,23 @@ 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
* @brief Disables balancing for all cells.
*
* @param balance_enable
* @param chips Array of ADBMS6830 data structs.
*/
void segment_enable_balancing(bool balance_enable);
void segment_disable_balancing(cell_asic chips[NUM_CHIPS]);

/**
* @brief Enables/disables balancing for a specific cell
*
* @param chip_num
* @param cell_num
* @param balance_enable
*/
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 All @@ -52,12 +43,12 @@ void segment_configure_balancing(
bool cell_is_balancing(uint8_t chip_num, uint8_t cell_num);

/**
* @brief Returns if any cells are balancing
* @todo This should just be a state variable -Scott
*
* @return true
* @return false
* @brief Returns if any cells are balancing.
*
* @param chips Array of ADBMS6830 chips.
* @return true
* @return false
*/
bool segment_is_balancing();
bool segment_is_balancing(cell_asic chips[NUM_CHIPS]);

#endif
96 changes: 51 additions & 45 deletions Core/Src/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "compute.h"

#include "serialPrintResult.h"

// clang-format off
/**
* @brief Mapping Cell temperature to the cell resistance based on the
Expand Down Expand Up @@ -120,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 @@ -223,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 @@ -310,10 +298,13 @@ void calc_pack_voltage_stats(acc_data_t *bmsdata)
for (uint8_t c = 0; c < NUM_CHIPS; c++) {
for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) {
/* fings out the maximum cell voltage and location */
if (bmsdata->chip_data[c].voltage[cell] >
if (getVoltage(bmsdata->chip_data[c].voltage[cell]) *
10000 >
bmsdata->max_voltage.val) {
bmsdata->max_voltage.val =
bmsdata->chip_data[c].voltage[cell];
getVoltage(bmsdata->chip_data[c]
.voltage[cell]) *
10000;
bmsdata->max_voltage.chipIndex = c;
bmsdata->max_voltage.cellNum = cell;
}
Expand All @@ -328,10 +319,13 @@ void calc_pack_voltage_stats(acc_data_t *bmsdata)
}

/* finds out the minimum cell voltage and location */
if (bmsdata->chip_data[c].voltage[cell] <
if (getVoltage(bmsdata->chip_data[c].voltage[cell]) *
10000 <
bmsdata->min_voltage.val) {
bmsdata->min_voltage.val =
bmsdata->chip_data[c].voltage[cell];
getVoltage(bmsdata->chip_data[c]
.voltage[cell]) *
10000;
bmsdata->min_voltage.chipIndex = c;
bmsdata->min_voltage.cellNum = cell;
}
Expand All @@ -351,9 +345,21 @@ void calc_pack_voltage_stats(acc_data_t *bmsdata)
}
}

float real_total_volt = 0;
for (int chip = 0; chip < NUM_CHIPS; chip++) {
for (int i = 0; i < NUM_CELLS_PER_CHIP; i++) {
real_total_volt +=
getVoltage(bmsdata->chip_data[chip].voltage[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my questions in slack about chip_data. We shouldnt call getVoltage on a struct field outside of adbms, that feels wierd and takes their specific register format to the rest of the code. Imo we should either remove chipdata_t and call stuff on cell_asic or store the cell_asic stuff as floats post-conversion.

}
}

/* calculate some voltage stats */
bmsdata->avg_voltage = total_volt / (NUM_CELLS_PER_CHIP * NUM_CHIPS);
bmsdata->pack_voltage = total_volt / 1000; /* convert to voltage * 10 */
bmsdata->avg_voltage =
10000 * (real_total_volt / (NUM_CELLS_PER_CHIP * NUM_CHIPS));

bmsdata->pack_voltage =
real_total_volt * 10; /* convert to voltage * 10 */

bmsdata->delt_voltage =
bmsdata->max_voltage.val - bmsdata->min_voltage.val;

Expand Down Expand Up @@ -618,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/compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void compute_send_bms_status_message(acc_data_t *bmsdata, int bms_state,
bms_status_msg_data.fault = bmsdata->fault_code;
bms_status_msg_data.temp_internal = (uint8_t)(0);
bms_status_msg_data.balance =
(uint8_t)(balance); // segment_is_balancing()
(uint8_t)(balance);

/* convert to big endian */
endian_swap(&bms_status_msg_data.fault,
Expand Down
Loading
Loading