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

Merged
merged 34 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
60650d1
133 adbms submodule
Sabramz Nov 18, 2024
89b9d97
133 more copying
Sabramz Nov 18, 2024
004e83d
133 it works
Sabramz Nov 18, 2024
fe7b35e
133 debugging
Sabramz Nov 18, 2024
331f9dd
133 working prints
Sabramz Nov 18, 2024
a7bff61
adbms functions for config registers, get rid of some LTC code, start…
Sabramz Nov 21, 2024
ccff5e0
adbms reworking code for daisy chaining
Sabramz Nov 27, 2024
d1b4701
adbms wrapper written **untested**
Sabramz Dec 8, 2024
c671679
adbms cleaning up old functions
Sabramz Dec 8, 2024
f0a2a60
adbms balancing config changes
Sabramz Dec 14, 2024
e611107
adbms add chips to acc_data_t and make functions compatible with new …
Sabramz Dec 25, 2024
6791c57
adbms changing GPIO modes and integrating balancing functions with adbms
Sabramz Dec 26, 2024
93379f0
adbms cleaning up balancing and removing LTC driver from make file
Sabramz Dec 26, 2024
5a42a6b
adbms more cleanup of 22A code and starting on analyzer for alpha and…
Sabramz Jan 1, 2025
61e424e
adbms therms cleanup and changes for alpha and beta stacks
Sabramz Jan 6, 2025
540f19b
adbms functions for configuring chips
Sabramz Jan 6, 2025
591fe50
forgot to build
Sabramz Jan 6, 2025
a0e9240
adbms debugging volts and therms
Sabramz Jan 11, 2025
8a7b085
adbms therms mapping and temperature calculation, cleanup legacy code
Sabramz Jan 14, 2025
a3d12bc
adbms cleanup, add TODOs for future work
Sabramz Jan 14, 2025
5becce5
adbms cleanup, add TODOs for future work
Sabramz Jan 14, 2025
74ae15d
Set up task and send function for debug mode per cell data
Sabramz Jan 14, 2025
a44b476
debug mode create task and CAN message functions
Sabramz Jan 17, 2025
6e34ff5
adbms S vs C ADC comparison and PEC error count
Sabramz Jan 18, 2025
eda79ab
Merge branch 'per-cell-CAN' into 133-adbms-integration
Sabramz Jan 18, 2025
0c881b1
adbms debug mode stuff
Sabramz Jan 18, 2025
6f56377
adbms change debug mode CAN messages to use bit fields
Sabramz Jan 20, 2025
3dafe3b
General changes/improvements (#151)
jr1221 Jan 25, 2025
7e75f6a
Merge branch 'develop' into 133-adbms-integration
jr1221 Jan 25, 2025
b9218f2
fixups
jr1221 Jan 25, 2025
3426aaa
fmt
jr1221 Jan 25, 2025
89db8b6
segment reboot every 45 seconds
jr1221 Jan 25, 2025
a189aa7
fmt
jr1221 Jan 25, 2025
d02da4a
fmt
jr1221 Jan 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Sabramz marked this conversation as resolved.
Show resolved Hide resolved

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]);
Sabramz marked this conversation as resolved.
Show resolved Hide resolved
}
}

/* 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