From a600307a2e060cd92bdaee4ec3b3ca04f07e038f Mon Sep 17 00:00:00 2001 From: wfox5812 Date: Sun, 5 Nov 2023 19:08:32 -0500 Subject: [PATCH 1/2] Created sht30 internal temp fault monitoring --- Core/Inc/analyzer.h | 11 +++++++++++ Core/Inc/bmsConfig.h | 2 ++ Core/Src/analyzer.c | 9 ++++++++- Core/Src/main.c | 2 ++ Core/Src/stateMachine.c | 5 +++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Core/Inc/analyzer.h b/Core/Inc/analyzer.h index b5b02007..702f8f04 100644 --- a/Core/Inc/analyzer.h +++ b/Core/Inc/analyzer.h @@ -4,6 +4,7 @@ //#include Replace #include "datastructs.h" #include "segment.h" +#include "Core/Drivers/Embedded-Base/general/include/sht30.h" /* We want to make sure we aren't doing useless analysis on the same set of data since we are * backfilling segment data */ @@ -33,4 +34,14 @@ AccumulatorData_t* bmsdata; AccumulatorData_t* prevbmsdata; +/** + * @brief Create a new object to store the most recent data point for the temp sensor + */ +sht30_t* sht30data; + +/** + * @brief Create a new object to store the most recent data point for the temp sensor + */ +void sht30_init(); + #endif \ No newline at end of file diff --git a/Core/Inc/bmsConfig.h b/Core/Inc/bmsConfig.h index f92a969b..04bc19c9 100644 --- a/Core/Inc/bmsConfig.h +++ b/Core/Inc/bmsConfig.h @@ -12,6 +12,7 @@ #define MIN_TEMP -15 // deg C #define MAX_VOLT_MEAS 65535 #define MIN_VOLT_MEAS 0 +#define MAX_INTERNAL_TEMP 0 // needs to be set // Boosting Parameters #define BOOST_TIME 5 // seconds @@ -48,6 +49,7 @@ #define LOW_CELL_TIME 15000 #define HIGH_TEMP_TIME 60000 #define CURR_ERR_MARG 50 // in A * 10 +#define HIGH_INT_TEMP_TIME 0 // to be determined #define DCDC_CURRENT_DRAW 2 // in A, this is generous diff --git a/Core/Src/analyzer.c b/Core/Src/analyzer.c index 00a35318..d1fcbdbc 100644 --- a/Core/Src/analyzer.c +++ b/Core/Src/analyzer.c @@ -115,7 +115,7 @@ Timer ocvTimer; bool is_first_reading_ = true; -void push(AccumulatorData_t* data) +void push(AccumulatorData_t* data, sht30_t* sht30data) { if (prevbmsdata != nullptr) delete prevbmsdata; @@ -123,6 +123,8 @@ void push(AccumulatorData_t* data) prevbmsdata = bmsdata; bmsdata = data; + sht30_get_temp_humid(sht30data) + disable_therms(); high_curr_therm_check(); /* = prev if curr > 50 */ @@ -525,3 +527,8 @@ void diff_curr_therm_check() } } } + +void sht30_init(sht30_t* sht30data) +{ + sht30data->i2c_handle = &hi2c1; +} \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 014651c4..d6d75bb5 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -200,6 +200,8 @@ int main(void) // NERduino.begin(); compute.compute_set_fault(NOT_FAULTED); segment.init(); + + analyzer.sht30_init(); /* USER CODE END Init */ /* Configure the system clock */ diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index a6a45ac7..9e3089bf 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -13,6 +13,7 @@ tristate_timer over_voltcharge_tmr; tristate_timer overVolt_tmr; tristate_timer lowCell_tmr; tristate_timer highTemp_tmr; +tristate_timer internalTemp_tmr; tristate_timer prefaultOverCurr_tmr; tristate_timer prefaultLowCell_tmr; @@ -189,7 +190,7 @@ void request_transition(BMSState_t next_state) current_state = next_state; } -uint32_t sm_fault_return(AccumulatorData_t* accData) +uint32_t sm_fault_return(AccumulatorData_t* accData, sht30_t* sht30_data) { /* FAULT CHECK (Check for fuckies) */ @@ -204,7 +205,7 @@ uint32_t sm_fault_return(AccumulatorData_t* accData) {.id = "High Cell Voltage", .timer = overVolt_tmr, .data_1 = accData->max_voltage.val, .optype_1 = GT, .lim_1 = MAX_VOLT * 10000, .timeout = OVER_VOLT_TIME, .code = CELL_VOLTAGE_TOO_HIGH, .data_2 = accData->is_charger_connected, .optype_2 = EQ, .lim_2 = false }, {.id = "High Temp", .timer = highTemp_tmr, .data_1 = accData->max_temp.val, .optype_1 = GT, .lim_1 = MAX_CELL_TEMP, .timeout = LOW_CELL_TIME, .code = PACK_TOO_HOT /* -----------------------------------UNUSED---------------------------------*/ }, {.id = "Extremely Low Voltage", .timer = lowCell_tmr, .data_1 = accData->min_voltage.val, .optype_1 = LT, .lim_1 = 900, .timeout = HIGH_TEMP_TIME, .code = LOW_CELL_VOLTAGE /* -----------------------------------UNUSED---------------------------------*/ }, - + {.id = "High Internal Temp", .timer = internalTemp_tmr, .data_1 = sht30_data->temp .optype_1 = GT, .lim_1 = MAX_INTERNAL_TEMP, .timeout = HIGH_INT_TEMP_TIME, .code = INTERNAL_THERMAL_ERROR /* -----------------------------------UNUSED---------------------------------*/ }, NULL // clang-format on }; From 7b51c6d1537a64717ae0fb8ccb80d44a270c8754 Mon Sep 17 00:00:00 2001 From: wfox5812 Date: Sun, 12 Nov 2023 17:48:02 -0500 Subject: [PATCH 2/2] small fixes --- Core/Inc/analyzer.h | 2 +- Core/Src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Inc/analyzer.h b/Core/Inc/analyzer.h index 702f8f04..754d5d9d 100644 --- a/Core/Inc/analyzer.h +++ b/Core/Inc/analyzer.h @@ -4,7 +4,7 @@ //#include Replace #include "datastructs.h" #include "segment.h" -#include "Core/Drivers/Embedded-Base/general/include/sht30.h" +#include "sht30.h" /* We want to make sure we aren't doing useless analysis on the same set of data since we are * backfilling segment data */ diff --git a/Core/Src/main.c b/Core/Src/main.c index d6d75bb5..86a57302 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -238,7 +238,7 @@ int main(void) acc_data->pack_current = compute.compute_get_pack_current(); //Perform calculations on the data in the frame - analyzer.push(acc_data); + analyzer.push(acc_data, sht30data); stateMachine_sm_handle_state(acc_data);