diff --git a/cellboard/Core/Lib/can b/cellboard/Core/Lib/can index 9b363e76..61fbdd9e 160000 --- a/cellboard/Core/Lib/can +++ b/cellboard/Core/Lib/can @@ -1 +1 @@ -Subproject commit 9b363e76ce7c631785ee21e477733fa6b8fcea13 +Subproject commit 61fbdd9e7d6dd3af0443c600836c9b59ee652188 diff --git a/cellboard/Core/Lib/micro-libs b/cellboard/Core/Lib/micro-libs index 42a6e7c5..43ea4b62 160000 --- a/cellboard/Core/Lib/micro-libs +++ b/cellboard/Core/Lib/micro-libs @@ -1 +1 @@ -Subproject commit 42a6e7c5fe588b7dc5eed7296e9493e7198d0d50 +Subproject commit 43ea4b62235f6eb8f63ea4f7f8a21ce55cbc42a0 diff --git a/cellboard/Core/Src/can_comms.c b/cellboard/Core/Src/can_comms.c index 03b47508..117f6c38 100644 --- a/cellboard/Core/Src/can_comms.c +++ b/cellboard/Core/Src/can_comms.c @@ -232,7 +232,7 @@ void can_send(uint16_t id) { conv_version.canlib_build_time = CANLIB_BUILD_TIME; conv_version.cellboard_id = cellboard_index; - conv_version.component_build_hash = 1; + conv_version.component_version = 1; bms_cellboard_version_conversion_to_raw_struct(&raw_version, &conv_version); diff --git a/fenice_config.h b/fenice_config.h index f08710cb..881a6590 100644 --- a/fenice_config.h +++ b/fenice_config.h @@ -161,33 +161,25 @@ static const uint8_t TEMP_SENSOR_ADDRESS_CODING[TEMP_SENSORS_PER_STRIP] = {000, */ #define PACK_ENERGY_NOMINAL (CELL_ENERGY_NOMINAL * PACK_CELL_COUNT) -// @section Balancing +#define AIRN_CHECK_TIMEOUT 1000 +#define PRECHARGE_TIMEOUT 13000 +#define AIRP_CHECK_TIMEOUT 1000 +#define CELLBOARD_COMM_TIMEOUT 500 -/** - * Maximum voltage delta between cells (mV * 10) - */ -#define BAL_MAX_VOLTAGE_THRESHOLD 500 +// Default voltage delta between cells (mV * 10) +#define BAL_DEFAULT_VOLTAGE_THRESHOLD 300 +// Maximum voltage delta between cells (mV * 10) +#define BAL_MAX_VOLTAGE_THRESHOLD 2000 -/** - * How much does a balancing cycle last (ms) - */ -#define BAL_CYCLE_LENGTH 30000 -#define BAL_TIME_ON 1000 -#define BAL_TIME_OFF 1000 +// How much does a balancing cycle last (ms) +#define BAL_CYCLE_LENGTH 30000 +#define BAL_TIME_ON 1000 +#define BAL_TIME_OFF 1000 -/** - * How much to wait for voltages to stabilize after a balancing cycle [ms] - */ +// How much to wait for voltages to stabilize after a balancing cycle [ms] #define BAL_COOLDOWN_DELAY 5000 - #define DISCHARGE_DUTY_CYCLE (((float)BAL_CYCLE_LENGTH*BAL_TIME_ON/(BAL_TIME_ON+BAL_TIME_OFF))/(BAL_CYCLE_LENGTH+BAL_COOLDOWN_DELAY)) -// @section Pre-charge - -#define AIRN_CHECK_TIMEOUT 1000 -#define PRECHARGE_TIMEOUT 13000 -#define AIRP_CHECK_TIMEOUT 1000 -#define CELLBOARD_COMM_TIMEOUT 500 /** @brief Multiplexer feedbacks */ typedef enum { diff --git a/mainboard/STM32Make.make b/mainboard/STM32Make.make index 849d4cfc..94575dcc 100644 --- a/mainboard/STM32Make.make +++ b/mainboard/STM32Make.make @@ -102,6 +102,7 @@ lib/micro-libs/llist/llist.c \ lib/micro-libs/m95256/m95256.c \ lib/micro-libs/priority-queue/priority_queue.c \ lib/micro-libs/priority-queue/priority_queue_fast_insert.c \ +lib/micro-libs/priority-queue/priority_queue_heap.c \ lib/micro-libs/pwm/pwm.c \ lib/micro-libs/timer-utils/timer_utils.c diff --git a/mainboard/Src/bal.c b/mainboard/Src/bal.c index 770db164..fd9caa9b 100644 --- a/mainboard/Src/bal.c +++ b/mainboard/Src/bal.c @@ -28,7 +28,7 @@ typedef struct { voltage_t threshold; } bal_params; -bal_params bal_params_default = { BAL_MAX_VOLTAGE_THRESHOLD }; +bal_params bal_params_default = { BAL_DEFAULT_VOLTAGE_THRESHOLD }; config_t config; uint8_t is_balancing; diff --git a/mainboard/Src/peripherals/can_comm.c b/mainboard/Src/peripherals/can_comm.c index a9f34a0e..5219aff4 100644 --- a/mainboard/Src/peripherals/can_comm.c +++ b/mainboard/Src/peripherals/can_comm.c @@ -135,8 +135,6 @@ HAL_StatusTypeDef can_car_send(uint16_t id) { conv_volts.bus_voltage = CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltage_get_tsp()); conv_volts.pack_voltage = CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltage_get_bat()); - conv_volts.max_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_max()); - conv_volts.min_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_min()); primary_hv_voltage_conversion_to_raw_struct(&raw_volts, &conv_volts); @@ -145,6 +143,22 @@ HAL_StatusTypeDef can_car_send(uint16_t id) { return HAL_ERROR; tx_header.DLC = data_len; } + else if (id == PRIMARY_HV_CELL_VOLTAGE_FRAME_ID) { + primary_hv_cell_voltage_t raw_volts = { 0 }; + primary_hv_cell_voltage_converted_t conv_volts = { 0 }; + + conv_volts.max_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_max()); + conv_volts.min_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_min()); + conv_volts.sum_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_sum()); + conv_volts.avg_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_avg()); + + primary_hv_cell_voltage_conversion_to_raw_struct(&raw_volts, &conv_volts); + + int data_len = primary_hv_cell_voltage_pack(buffer, &raw_volts, PRIMARY_HV_CELL_VOLTAGE_BYTE_SIZE); + if (data_len < 0) + return HAL_ERROR; + tx_header.DLC = data_len; + } else if (id == PRIMARY_HV_CURRENT_FRAME_ID) { primary_hv_current_t raw_curr = { 0 }; primary_hv_current_converted_t conv_curr = { 0 }; @@ -908,7 +922,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) { conv_fwd_version.canlib_build_time = conv_version.canlib_build_time; conv_fwd_version.cellboard_id = conv_version.cellboard_id; - conv_fwd_version.component_build_time = conv_version.component_build_hash; + conv_fwd_version.component_version = conv_version.component_version; primary_cellboard_version_conversion_to_raw_struct(&raw_fwd_version, &conv_fwd_version); @@ -983,6 +997,10 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) { } primary_set_cell_balancing_status_raw_to_conversion_struct(&conv_bal_status, &raw_bal_status); + // Set threshold + uint16_t thr = conv_bal_status.balancing_threshold; // Received threshold is in mV + bal_set_threshold(thr * 10); // Expected threshold is in mV * 10 + // Request for balancing start or stop switch(conv_bal_status.set_balancing_status) { case PRIMARY_SET_CELL_BALANCING_STATUS_SET_BALANCING_STATUS_ON_CHOICE: diff --git a/mainboard/lib/can b/mainboard/lib/can index 9b363e76..61fbdd9e 160000 --- a/mainboard/lib/can +++ b/mainboard/lib/can @@ -1 +1 @@ -Subproject commit 9b363e76ce7c631785ee21e477733fa6b8fcea13 +Subproject commit 61fbdd9e7d6dd3af0443c600836c9b59ee652188 diff --git a/mainboard/lib/micro-libs b/mainboard/lib/micro-libs index 42a6e7c5..43ea4b62 160000 --- a/mainboard/lib/micro-libs +++ b/mainboard/lib/micro-libs @@ -1 +1 @@ -Subproject commit 42a6e7c5fe588b7dc5eed7296e9493e7198d0d50 +Subproject commit 43ea4b62235f6eb8f63ea4f7f8a21ce55cbc42a0