From 17e8cee0ac89767d5d3b621dd0740c27c45b1afb Mon Sep 17 00:00:00 2001 From: hamza Date: Mon, 8 Jul 2024 14:44:01 +0300 Subject: [PATCH] V1.6 --- CHANGELOG.txt | 8 ++++++++ Core/Inc/state_machine.h | 10 +++++----- Core/Src/AMS_HighLevel.c | 2 +- Core/Src/PWM_control.c | 1 + Core/Src/TMP1075.c | 2 +- Core/Src/can.c | 14 +++++++++++--- Core/Src/state_machine.c | 19 +++++++++---------- 7 files changed, 36 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e717648..ff2eb0d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -29,3 +29,11 @@ V1.5 - int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES] to float - errors out when no messages are recieved for CAN_TIMEOUT messages - void set_error_source(int source); -> void set_error_source(SlaveErrorKind source); + +V1.6 +- set temperature limit to 59 +- precharge and discharge durations are now 5 seconds +- RELAY_BAT/ESC_SIDE and CURRENT_MEASUREMENT to int32_t +- CAN messages are now correctly formated +- minimum cell voltage is now set to 3200 mV +- powerground calibration is now done in STATE_PRECHARGE (well yes but actually no) diff --git a/Core/Inc/state_machine.h b/Core/Inc/state_machine.h index 891b5b2..3e54708 100644 --- a/Core/Inc/state_machine.h +++ b/Core/Inc/state_machine.h @@ -18,9 +18,9 @@ // Time to wait after reaching 95% of battery voltage before exiting precharge // Set this to 1000 in scruti to demonstrate the voltage on the multimeter -#define PRECHARGE_DURATION 3000 // ms +#define PRECHARGE_DURATION 5000 // ms // Time to wait for discharge -#define DISCHARGE_DURATION 3000 // ms +#define DISCHARGE_DURATION 5000 // ms // Time to wait for charger voltage before going to TS_ERROR #define MAX_CHARGING_CHECK_DURATION 2000 // ms // Time to wait between closing relays @@ -62,9 +62,9 @@ typedef struct { } StateHandle; extern StateHandle state; -extern int16_t RELAY_BAT_SIDE_VOLTAGE; -extern int16_t RELAY_ESC_SIDE_VOLTAGE; -extern int16_t CURRENT_MEASUREMENT; +extern int32_t RELAY_BAT_SIDE_VOLTAGE; +extern int32_t RELAY_ESC_SIDE_VOLTAGE; +extern int32_t CURRENT_MEASUREMENT; extern uint8_t powerground_status; diff --git a/Core/Src/AMS_HighLevel.c b/Core/Src/AMS_HighLevel.c index ec1a2aa..3978263 100755 --- a/Core/Src/AMS_HighLevel.c +++ b/Core/Src/AMS_HighLevel.c @@ -136,7 +136,7 @@ uint8_t AMS_Idle_Loop() { int any_voltage_error = 0; for (size_t i = 0; i < numberofCells; i++) { - if (module.cellVoltages[i] < 2500) { + if (module.cellVoltages[i] < 3200) { any_voltage_error = 1; error_data.data_kind = SEK_UNDERVOLT; error_data.data[0] = i; diff --git a/Core/Src/PWM_control.c b/Core/Src/PWM_control.c index abe38ba..2165c7e 100644 --- a/Core/Src/PWM_control.c +++ b/Core/Src/PWM_control.c @@ -51,6 +51,7 @@ void PWM_powerground_control(uint8_t percent){ if (percent > 100){ //something went wrong __HAL_TIM_SET_COMPARE(powerground, TIM_CHANNEL_3, 0); __HAL_TIM_SET_COMPARE(powerground, TIM_CHANNEL_4, 0); + powerground_status = 0; return; } powerground_status = percent; diff --git a/Core/Src/TMP1075.c b/Core/Src/TMP1075.c index ee86e9d..fcb1d50 100644 --- a/Core/Src/TMP1075.c +++ b/Core/Src/TMP1075.c @@ -1,6 +1,6 @@ #include "TMP1075.h" -#define MAX_TEMP ((int16_t)(30 / 0.0625f)) +#define MAX_TEMP ((int16_t)(59 / 0.0625f)) #define MAX_FAILED_TEMP 2 //TODO: change value for compliance with the actual number of sensors #warning "change value for compliance with the actual number of sensors" diff --git a/Core/Src/can.c b/Core/Src/can.c index ee87a05..593c7e0 100644 --- a/Core/Src/can.c +++ b/Core/Src/can.c @@ -67,10 +67,10 @@ void can_handle_send_status() { data[0] = ((state.current_state << 4) | (powerground_status >> 4)); // 1 bit emptyy | 3 bit state | 4 bit powerground data[1] = ((powerground_status << 4) | (state.error_source >> 4)); // 4 bit powerground | 4 bit error data[2] = ((state.error_source << 4) | (0)); // 4 bit error | 4 bit state of charge - data[3] = ((0) + (RELAY_BAT_SIDE_VOLTAGE >> 12)); // 4 bit state of charge | 4 bit battery voltage - data[4] = ((RELAY_BAT_SIDE_VOLTAGE >> 4)); + data[3] = ((RELAY_BAT_SIDE_VOLTAGE >> 8)); // 4 bit state of charge | 4 bit battery voltage + data[4] = ((RELAY_BAT_SIDE_VOLTAGE >> 0)); data[5] = ((CURRENT_MEASUREMENT >> 8)); - data[6] = ((CURRENT_MEASUREMENT & 0x00F0) | (highest_temp >> 12)); + data[6] = ((CURRENT_MEASUREMENT & 0x000F) | (highest_temp >> 12)); data[7] = ((highest_temp) >> 4); //data[7] = state.error_source; ftcan_transmit(CAN_ID_OUT, data, sizeof(data)); @@ -110,6 +110,14 @@ void can_handle_send_status() { data[7] = 0; ftcan_transmit(CAN_ID_OUT, data, sizeof(data)); + + 021E 30 + 0232 50 + 0238 60 + 0246 70 + 0250 80 + 025A 90 + 0264 100 */ } diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 916629b..3017f26 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -16,10 +16,11 @@ #include StateHandle state; -int16_t RELAY_BAT_SIDE_VOLTAGE; -int16_t RELAY_ESC_SIDE_VOLTAGE; -int16_t CURRENT_MEASUREMENT; +int32_t RELAY_BAT_SIDE_VOLTAGE; +int32_t RELAY_ESC_SIDE_VOLTAGE; +int32_t CURRENT_MEASUREMENT; bool CURRENT_MEASUREMENT_ON; +float base_offset = 0; uint8_t powerground_status; uint32_t precharge_timer; @@ -44,15 +45,14 @@ void sm_update(){ sm_check_errors(); sm_precharge_discharge_manager(); sm_calibrate_powerground(); - if (CAN_timer < HAL_GetTick()) - state.current_state = state.target_state = STATE_ERROR; + //if (CAN_timer < HAL_GetTick()) + // state.current_state = state.target_state = STATE_ERROR; - int16_t base_offset = 0; if (state.current_state == STATE_INACTIVE){ base_offset = module.auxVoltages[0]; } - CURRENT_MEASUREMENT = (module.auxVoltages[0] - base_offset) * 300; + CURRENT_MEASUREMENT = roundf((module.auxVoltages[0] - base_offset) * 350); CURRENT_MEASUREMENT_ON = (module.auxVoltages[1] > 2400); RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[2] * 11.711; RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[3] * 11.711; // the calculation says the factor is 11. 11.711 yields the better result @@ -120,7 +120,6 @@ State sm_update_ready(){ case STATE_DISCHARGE: // if CAN Signal 0000 0000 then shutdown return STATE_DISCHARGE; default: - sm_calibrate_powerground(); return STATE_READY; } } @@ -266,7 +265,7 @@ void sm_calibrate_powerground(){ if (powerground_calibration_stage != 4 && state.current_state == STATE_READY){ switch (powerground_calibration_stage) { case 0: - powerground_calibration_timer = HAL_GetTick() + 5000; + powerground_calibration_timer = HAL_GetTick() + 0; powerground_calibration_stage = 1; return; case 1: @@ -348,7 +347,7 @@ void sm_check_errors(){ state.error_type.bms_timeout = (error_data.error_sources & (1 << 7)) ? 1 : 0; state.error_type.bms_fault = (error_data.error_sources & (1 << 8) || error_data.error_sources & (1 << 10) || error_data.error_sources & (1 << 9)) ? 1 : 0; //SEK_EEPROM_ERR: state.error_type.eeprom_error = 1; - state.error_type.current_error = (powerground_status > 10 && CURRENT_MEASUREMENT < 1000) ? 1 : 0; + //state.error_type.current_error = (powerground_status > 10 && CURRENT_MEASUREMENT < 500) ? 1 : 0; state.error_type.current_sensor_missing = (!CURRENT_MEASUREMENT_ON) ? 1 : 0; state.error_type.voltage_missing = (RELAY_BAT_SIDE_VOLTAGE < 1000) ? 1 : 0;