From 406b8c013094b93920ce23c7fb91724ed4875d3d Mon Sep 17 00:00:00 2001 From: Federico Carbone Date: Tue, 6 Aug 2024 09:54:39 +0200 Subject: [PATCH] fix: increment sensing interval --- Core/Inc/errors.h | 9 +++++++++ Core/Src/can_send_timebase.c | 6 +++--- Core/Src/can_utils.c | 28 ++++++++++++++-------------- Core/Src/data_reading_timebase.c | 16 ++++++++++++---- Core/Src/errors.c | 21 +++++++++++++++++++++ Core/Src/lem.c | 4 ++++ Core/Src/main.c | 2 +- STM32Make.make | 1 - 8 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Core/Inc/errors.h b/Core/Inc/errors.h index 3546628..9f4d5cf 100644 --- a/Core/Inc/errors.h +++ b/Core/Inc/errors.h @@ -8,18 +8,27 @@ typedef enum { ERRORS_UNDERVOLTAGE, ERRORS_OVERVOLTAGE, ERRORS_OVERTEMPERATURE, + ERRORS_UNDERTEMPERATURE, ERRORS_NUM } ERRORS_TypeDef; void error_init(void); + void error_timerElapsed_irq(TIM_HandleTypeDef *htim); + void error_set_undervoltage(uint8_t index); void error_set_overvoltage(uint8_t index); void error_set_overtemp(uint8_t index); +void error_set_undertemp(uint8_t index); + void error_reset_undervoltage(uint8_t index); void error_reset_overvoltage(uint8_t index); void error_reset_overtemp(uint8_t index); +void error_reset_undertemp(uint8_t index); + uint8_t error_get_overvoltage(uint8_t index); uint8_t error_get_undervoltage(uint8_t index); uint8_t error_get_overtemp(uint8_t index); +uint8_t error_get_undertemp(uint8_t index); + #endif // ERRORS_H diff --git a/Core/Src/can_send_timebase.c b/Core/Src/can_send_timebase.c index a99e769..4bbddf3 100644 --- a/Core/Src/can_send_timebase.c +++ b/Core/Src/can_send_timebase.c @@ -30,12 +30,12 @@ void can_send_timebase_init(void) { TIMEBASE_init(&can_send_timebase_handle, &htim10, 1000); - TIMEBASE_add_interval(&can_send_timebase_handle, 1000, &interval); + TIMEBASE_add_interval(&can_send_timebase_handle, 10000, &interval); TIMEBASE_register_callback(&can_send_timebase_handle, interval, battery_pack_general_cb); + + TIMEBASE_add_interval(&can_send_timebase_handle, 200000, &interval); TIMEBASE_register_callback(&can_send_timebase_handle, interval, cell_voltage_cb); TIMEBASE_register_callback(&can_send_timebase_handle, interval, status_cb); - - TIMEBASE_add_interval(&can_send_timebase_handle, 20000, &interval); TIMEBASE_register_callback(&can_send_timebase_handle, interval, temp_cb); } diff --git a/Core/Src/can_utils.c b/Core/Src/can_utils.c index f6e37f6..5d9d5b9 100644 --- a/Core/Src/can_utils.c +++ b/Core/Src/can_utils.c @@ -90,22 +90,22 @@ void can_send_msg(uint32_t id) { tx_header.DLC = mcb_bmslv_helo_pack(buffer, &msgs.bmslv_helo, MCB_BMSLV_HELO_LENGTH); break; case MCB_BMSLV_TEMP1_FRAME_ID: - msgs.bmslv_temp2.ntc1_resistance = mcb_bmslv_temp2_ntc1_resistance_encode(ntc_get_ext_resistance(0)); - msgs.bmslv_temp2.ntc2_resistance = mcb_bmslv_temp2_ntc2_resistance_encode(ntc_get_ext_resistance(1)); - msgs.bmslv_temp2.ntc3_resistance = mcb_bmslv_temp2_ntc3_resistance_encode(ntc_get_ext_resistance(2)); - msgs.bmslv_temp2.ntc4_resistance = mcb_bmslv_temp2_ntc4_resistance_encode(ntc_get_ext_resistance(3)); - msgs.bmslv_temp2.ntc5_resistance = mcb_bmslv_temp2_ntc5_resistance_encode(ntc_get_ext_resistance(4)); - msgs.bmslv_temp2.ntc6_resistance = mcb_bmslv_temp2_ntc6_resistance_encode(ntc_get_ext_resistance(5)); + msgs.bmslv_temp1.ntc1_resistance = mcb_bmslv_temp1_ntc1_resistance_encode(ntc_get_ext_temp(0)*1000); + msgs.bmslv_temp1.ntc2_resistance = mcb_bmslv_temp1_ntc2_resistance_encode(ntc_get_ext_temp(1)*1000); + msgs.bmslv_temp1.ntc3_resistance = mcb_bmslv_temp1_ntc3_resistance_encode(ntc_get_ext_temp(2)*1000); + msgs.bmslv_temp1.ntc4_resistance = mcb_bmslv_temp1_ntc4_resistance_encode(ntc_get_ext_temp(3)*1000); + msgs.bmslv_temp1.ntc5_resistance = mcb_bmslv_temp1_ntc5_resistance_encode(ntc_get_ext_temp(4)*1000); + msgs.bmslv_temp1.ntc6_resistance = mcb_bmslv_temp1_ntc6_resistance_encode(ntc_get_ext_temp(5)*1000); tx_header.DLC = mcb_bmslv_temp1_pack(buffer, &msgs.bmslv_temp1, MCB_BMSLV_TEMP1_LENGTH); break; case MCB_BMSLV_TEMP2_FRAME_ID: - msgs.bmslv_temp2.ntc1_resistance = mcb_bmslv_temp2_ntc1_resistance_encode(ntc_get_ext_resistance(6)); - msgs.bmslv_temp2.ntc2_resistance = mcb_bmslv_temp2_ntc2_resistance_encode(ntc_get_int_resistance(0)); - msgs.bmslv_temp2.ntc3_resistance = mcb_bmslv_temp2_ntc3_resistance_encode(ntc_get_int_resistance(1)); - msgs.bmslv_temp2.ntc4_resistance = mcb_bmslv_temp2_ntc4_resistance_encode(ntc_get_int_resistance(2)); - msgs.bmslv_temp2.ntc5_resistance = mcb_bmslv_temp2_ntc5_resistance_encode(ntc_get_int_resistance(3)); - msgs.bmslv_temp2.ntc6_resistance = mcb_bmslv_temp2_ntc6_resistance_encode(ntc_get_int_resistance(4)); + msgs.bmslv_temp2.ntc1_resistance = mcb_bmslv_temp2_ntc1_resistance_encode(ntc_get_ext_temp(6)*1000); + msgs.bmslv_temp2.ntc2_resistance = mcb_bmslv_temp2_ntc2_resistance_encode(ntc_get_int_temp(0)*1000); + msgs.bmslv_temp2.ntc3_resistance = mcb_bmslv_temp2_ntc3_resistance_encode(ntc_get_int_temp(1)*1000); + msgs.bmslv_temp2.ntc4_resistance = mcb_bmslv_temp2_ntc4_resistance_encode(ntc_get_int_temp(2)*1000); + msgs.bmslv_temp2.ntc5_resistance = mcb_bmslv_temp2_ntc5_resistance_encode(ntc_get_int_temp(3)*1000); + msgs.bmslv_temp2.ntc6_resistance = mcb_bmslv_temp2_ntc6_resistance_encode(ntc_get_int_temp(4)*1000); tx_header.DLC = mcb_bmslv_temp2_pack(buffer, &msgs.bmslv_temp2, MCB_BMSLV_TEMP2_LENGTH); break; @@ -166,13 +166,13 @@ void can_send_msg(uint32_t id) { tx_header.DLC = mcb_bmslv_status_pack(buffer, &msgs.bmslv_status, MCB_BMSLV_STATUS_LENGTH); break; default: - break; + return; } can_send(&hcan1, buffer, &tx_header); } void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan) { - logger_log(LOGGER_ERROR, "sborato"); + // logger_log(LOGGER_ERROR, "sborato"); } void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { diff --git a/Core/Src/data_reading_timebase.c b/Core/Src/data_reading_timebase.c index eeca7b9..91833cf 100644 --- a/Core/Src/data_reading_timebase.c +++ b/Core/Src/data_reading_timebase.c @@ -21,7 +21,7 @@ STMLIBS_StatusTypeDef data_reading_l9963e_cb(void) { cells = L9963E_utils_get_cells(&cells_n); - for(uint8_t i=0; i 4.2 / 0.000089) error_set_overvoltage(i); else @@ -37,14 +37,22 @@ STMLIBS_StatusTypeDef data_reading_l9963e_cb(void) { for(uint8_t i=0; i 80) error_set_overtemp(i); - else + else if(ntc_get_int_temp(i) < -20) + error_set_undertemp(i); + else{ error_reset_overtemp(i); + error_reset_undertemp(i); + } } for(uint8_t i=0; i 80) error_set_overtemp(NTC_EXT_ADC_N+i); - else + else if(ntc_get_ext_temp(i) < -20) + error_set_undertemp(NTC_EXT_ADC_N+i); + else { error_reset_overtemp(NTC_EXT_ADC_N+i); + error_reset_undertemp(NTC_EXT_ADC_N+i); + } } } @@ -56,7 +64,7 @@ void data_reading_timebase_init(void) { TIMEBASE_init(&data_reading_timebase_handle, &htim6, 1000); - TIMEBASE_add_interval(&data_reading_timebase_handle, 1000, &interval); + TIMEBASE_add_interval(&data_reading_timebase_handle, 10000, &interval); TIMEBASE_register_callback(&data_reading_timebase_handle, interval, data_reading_l9963e_cb); } diff --git a/Core/Src/errors.c b/Core/Src/errors.c index b5af830..43b19be 100644 --- a/Core/Src/errors.c +++ b/Core/Src/errors.c @@ -12,16 +12,20 @@ void overvoltage_exp_cb(uint8_t error_index, uint8_t instance_index); void overvoltage_toggle_cb(uint8_t error_index, uint8_t instance_index); void overtemp_exp_cb(uint8_t error_index, uint8_t instance_index); void overtemp_toggle_cb(uint8_t error_index, uint8_t instance_index); +void undertemp_exp_cb(uint8_t error_index, uint8_t instance_index); +void undertemp_toggle_cb(uint8_t error_index, uint8_t instance_index); ERROR_UTILS_HandleTypeDef error_h; ERROR_UTILS_ErrorInstanceTypeDef undervoltage_instances[7]; ERROR_UTILS_ErrorInstanceTypeDef overvoltage_instances[7]; ERROR_UTILS_ErrorInstanceTypeDef overtemp_instances[12]; +ERROR_UTILS_ErrorInstanceTypeDef undertemp_instances[12]; ERROR_UTILS_ErrorTypeDef errors[] = { [ERRORS_UNDERVOLTAGE] = {.expiry_callback = undervoltage_exp_cb, .expiry_delay_ms = 500, .instances = undervoltage_instances, .instances_length = 7, .toggle_callback = undervoltage_toggle_cb}, [ERRORS_OVERVOLTAGE] = {.expiry_callback = overvoltage_exp_cb, .expiry_delay_ms = 500, .instances = overvoltage_instances, .instances_length = 7, .toggle_callback = overvoltage_toggle_cb}, [ERRORS_OVERTEMPERATURE] = {.expiry_callback = overtemp_exp_cb, .expiry_delay_ms = 1000, .instances = overtemp_instances, .instances_length = 12, .toggle_callback = overtemp_toggle_cb}, + [ERRORS_UNDERTEMPERATURE] = {.expiry_callback = undertemp_exp_cb, .expiry_delay_ms = 1000, .instances = undertemp_instances, .instances_length = 12, .toggle_callback = undertemp_toggle_cb}, }; ERROR_UTILS_ConfigTypeDef config = {.errors_array = errors, .errors_length = ERRORS_NUM}; @@ -54,6 +58,14 @@ uint8_t error_get_overtemp(uint8_t index) { return ERROR_UTILS_is_set(&error_h, ERRORS_OVERTEMPERATURE, index); } +void error_set_undertemp(uint8_t index) { + ERROR_UTILS_error_set(&error_h, ERRORS_UNDERTEMPERATURE, index); +} + +uint8_t error_get_undertemp(uint8_t index) { + return ERROR_UTILS_is_set(&error_h, ERRORS_UNDERTEMPERATURE, index); +} + void error_reset_undervoltage(uint8_t index) { ERROR_UTILS_error_reset(&error_h, ERRORS_UNDERVOLTAGE, index); } @@ -66,6 +78,10 @@ void error_reset_overtemp(uint8_t index) { ERROR_UTILS_error_reset(&error_h, ERRORS_OVERTEMPERATURE, index); } +void error_reset_undertemp(uint8_t index) { + ERROR_UTILS_error_reset(&error_h, ERRORS_UNDERTEMPERATURE, index); +} + void global_exp_cb(uint8_t error_index, uint8_t instance_index) { can_send_msg(MCB_BMSLV_STATUS_FRAME_ID); HAL_GPIO_WritePin(LV_CMD_GPIO_OUT_GPIO_Port, LV_CMD_GPIO_OUT_Pin, GPIO_PIN_RESET); @@ -89,6 +105,11 @@ void overtemp_exp_cb(uint8_t error_index, uint8_t instance_index) { } void overtemp_toggle_cb(uint8_t error_index, uint8_t instance_index) { } +void undertemp_exp_cb(uint8_t error_index, uint8_t instance_index) { + logger_log(LOGGER_ERROR, "undertemp on temp %d", instance_index); +} +void undertemp_toggle_cb(uint8_t error_index, uint8_t instance_index) { +} void error_timerElapsed_irq(TIM_HandleTypeDef *htim) { diff --git a/Core/Src/lem.c b/Core/Src/lem.c index 352785e..1bc60f5 100644 --- a/Core/Src/lem.c +++ b/Core/Src/lem.c @@ -37,6 +37,10 @@ void lem_new_value(uint16_t val) { } current = LEM_EXP_SMOOTH_ALPHA*val + (1-LEM_EXP_SMOOTH_ALPHA)*current; + + if(lem_get_current_ampere() > 50) { + HAL_GPIO_WritePin(LV_CMD_GPIO_OUT_GPIO_Port, LV_CMD_GPIO_OUT_Pin, GPIO_PIN_RESET); + } } void lem_adc_callback(ADC_HandleTypeDef *hadc) { diff --git a/Core/Src/main.c b/Core/Src/main.c index 59046f0..1dbd4f7 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -139,7 +139,7 @@ int main(void) data_reading_timebase_routine(); can_send_timebase_routine(); - logger_routine(); + // logger_routine(); // HAL_Delay(500); diff --git a/STM32Make.make b/STM32Make.make index 12cc67c..21b5616 100644 --- a/STM32Make.make +++ b/STM32Make.make @@ -233,7 +233,6 @@ vpath %.cpp $(sort $(dir $(CPP_SOURCES))) OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) vpath %.c $(sort $(dir $(C_SOURCES))) -# list of ASM program objects # list of ASM program objects UPPER_CASE_ASM_SOURCES = $(filter %.S,$(ASM_SOURCES)) LOWER_CASE_ASM_SOURCES = $(filter %.s,$(ASM_SOURCES))