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 6 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
32 changes: 26 additions & 6 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 @@ -310,10 +312,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 +333,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 +359,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
139 changes: 96 additions & 43 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "assert.h"

#include "serialPrintResult.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand All @@ -38,7 +40,12 @@

//#ifdef DEBUG_EVERYTHING
//#define DEBUG_CHARGING
// #define DEBUG_STATS
#define DEBUG_STATS
#define DEBUG_VOLTAGES
// #define DEBUG_RAW_VOLTAGES
#define DEBUG_RAW_VOLTAGES_FORMATTED
// #define DEBUG_OCV
// #define DEBUG_OTHER
// etc etc
//#endif
/* USER CODE END PD */
Expand Down Expand Up @@ -77,7 +84,7 @@ PCD_HandleTypeDef hpcd_USB_OTG_FS;
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.stack_size = 128 * 8,
.priority = (osPriority_t) osPriorityNormal,
};
/* USER CODE BEGIN PV */
Expand Down Expand Up @@ -115,9 +122,25 @@ void StartDefaultTask(void *argument);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* the following reroutes printf to uart */
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
return ch;
}

int _write(int file, char* ptr, int len) {
HAL_UART_Transmit_DMA(&huart4, (uint8_t *)ptr, len);

int DataIdx;

for (DataIdx = 0; DataIdx < len; DataIdx++) {
__io_putchar( *ptr++ );
Copy link
Contributor

Choose a reason for hiding this comment

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

messed up diff this stuff was changed on main??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this cuz printing was broken and i think it was cuz of the usart dma changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm did u use \r? Also make sure to use ner serial or else it wont work.

}
return len;
}

Expand All @@ -126,56 +149,83 @@ int _write(int file, char* ptr, int len) {
const void print_bms_stats(acc_data_t *acc_data)
{
static nertimer_t debug_stat_timer;
static const uint16_t PRINT_STAT_WAIT = 500; //ms
static const uint16_t PRINT_STAT_WAIT = 1000; //ms

if(!is_timer_expired(&debug_stat_timer) && debug_stat_timer.active) return;
#ifdef DEBUG_OTHER
//TODO get this from eeprom once implemented
// question - should we read from eeprom here, or do that on loop and store locally?
// printf("Prev Fault: %#x", previousFault);
printf("CAN Error:\t%ld\r\n", HAL_CAN_GetError(&hcan1));
printf("Current * 10: %d\r\n", (acc_data->pack_current));
printf("Min, Max, Avg Temps: %ld, %ld, %d\r\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp);
printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\r\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage);
printf("DCL: %d\r\n", acc_data->discharge_limit);
printf("CCL: %d\r\n", acc_data->charge_limit);
printf("Cont CCL %d\r\n", acc_data->cont_CCL);
printf("SoC: %d\r\n", acc_data->soc);
printf("Is Balancing?: %d\r\n", segment_is_balancing());

printf("CAN Error:\t%ld\n", HAL_CAN_GetError(&hcan1));
printf("Current * 10: %d\n", (acc_data->pack_current));
printf("Min, Max, Avg Temps: %ld, %ld, %d\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp);
#endif

#ifdef DEBUG_VOLTAGES
printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage);
printf("Min, Max, Avg, Delta Voltages: %f, %f, %f, %f\n", acc_data->min_voltage.val / 10000.0, acc_data->max_voltage.val / 10000.0, acc_data->avg_voltage / 10000.0, acc_data->delt_voltage / 10000.0);
#endif

#ifdef DEBUG_OTHER
printf("DCL: %d\n", acc_data->discharge_limit);
printf("CCL: %d\n", acc_data->charge_limit);
printf("Cont CCL %d\n", acc_data->cont_CCL);
printf("SoC: %d\n", acc_data->soc);
printf("Is Balancing?: %d\n", segment_is_balancing());
printf("State: ");
if (current_state == 0) printf("BOOT\r\n");
else if (current_state == 1) printf("READY\r\n");
else if (current_state == 2) printf("CHARGING\r\n");
else if (current_state == 3) printf("FAULTED: %lX\r\n", acc_data->fault_code);

printf("Voltage Noise Percent:\r\n");
printf("Seg 1: %d\r\n", acc_data->segment_noise_percentage[0]);
printf("Seg 2: %d\r\n", acc_data->segment_noise_percentage[1]);
printf("Seg 3: %d\r\n", acc_data->segment_noise_percentage[2]);
printf("Seg 4: %d\r\n", acc_data->segment_noise_percentage[3]);
printf("Seg 5: %d\r\n", acc_data->segment_noise_percentage[4]);
printf("Seg 6: %d\r\n", acc_data->segment_noise_percentage[5]);

printf("Raw Cell Voltage:\r\n");
if (current_state == 0) printf("BOOT\n");
else if (current_state == 1) printf("READY\n");
else if (current_state == 2) printf("CHARGING\n");
else if (current_state == 3) printf("FAULTED: %lX\n", acc_data->fault_code);

printf("Voltage Noise Percent:\n");
printf("Seg 1: %d\n", acc_data->segment_noise_percentage[0]);
printf("Seg 2: %d\n", acc_data->segment_noise_percentage[1]);
printf("Seg 3: %d\n", acc_data->segment_noise_percentage[2]);
printf("Seg 4: %d\n", acc_data->segment_noise_percentage[3]);
printf("Seg 5: %d\n", acc_data->segment_noise_percentage[4]);
printf("Seg 6: %d\n", acc_data->segment_noise_percentage[5]);
#endif

#ifdef DEBUG_RAW_VOLTAGES
printf("Raw Cell Voltage:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
printf("%d\t", acc_data->chip_data[c].voltage[cell]);
}
printf("\r\n");
printf("\n");
}
#endif

printf("Open Cell Voltage:\r\n");
#ifdef DEBUG_RAW_VOLTAGES_FORMATTED
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
printf("%d\t", acc_data->chip_data[c].voltage[cell]);
}
printf("\n");
}
#endif

#ifdef DEBUG_OCV
printf("Open Cell Voltage:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
printf("%d\t", acc_data->chip_data[c].open_cell_voltage[cell]);
}
printf("\r\n");
printf("\n");
}
#endif

#ifdef DEBUG_OTHER

printf("Thermistors with Disabling:\r\n");
printf("Thermistors with Disabling:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
printf("Chip %d: ", c);
Expand All @@ -186,10 +236,10 @@ const void print_bms_stats(acc_data_t *acc_data)
printf("%d ", acc_data->chip_data[c].thermistor_value[cell]);
}

printf("\r\n");
printf("\n");
}

printf("UnFiltered Thermistor Temps:\r\n");
printf("UnFiltered Thermistor Temps:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
printf("Chip %d: ", c);
Expand All @@ -199,10 +249,10 @@ const void print_bms_stats(acc_data_t *acc_data)
printf("%d ", acc_data->chip_data[c].thermistor_reading[cell]);
}

printf("\r\n");
printf("\n");
}

printf("Cell Temps:\r\n");
printf("Cell Temps:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
printf("Chip %d: ", c);
Expand All @@ -212,8 +262,9 @@ const void print_bms_stats(acc_data_t *acc_data)
printf("%d ", acc_data->chip_data[c].cell_temp[cell]);
}

printf("\r\n");
printf("\n");
}
#endif

start_timer(&debug_stat_timer, PRINT_STAT_WAIT);
}
Expand Down Expand Up @@ -298,7 +349,7 @@ int main(void)
init_both_can(&hcan1, &hcan2);
segment_init();
compute_init();
printf("Init passed\r\n");
printf("Init passed\n");
/* USER CODE END 2 */

/* Init scheduler */
Expand All @@ -322,7 +373,7 @@ int main(void)

/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
defaultTaskHandle = osThreadNew(StartDefaultTask, acc_data, &defaultTask_attributes);

/* USER CODE BEGIN RTOS_THREADS */

Expand Down Expand Up @@ -754,7 +805,7 @@ static void MX_SPI3_Init(void)
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
Expand Down Expand Up @@ -1183,7 +1234,9 @@ void watchdog_pet(void)
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
acc_data_t *bmsdata = (acc_data_t *)argument;
#ifdef DEBUG_STATS
acc_data_t* bmsdata = (acc_data_t*) argument;
#endif

bool alt = true;

Expand All @@ -1195,9 +1248,9 @@ void StartDefaultTask(void *argument)
#endif

if (alt) {
printf(".\r\n");
printf(".\n");
} else {
printf("..\r\n");
printf("..\n");
}

alt = !alt;
Expand Down
Loading
Loading