diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 83eb4a7..a8f6f90 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -88,4 +88,7 @@ V1.14 - removed void status_led_blink_sequence(uint8_t blinks, color color) and added proper blinking - fixed the bit shift of temperature in the can message - moved tmp1075_measure() and can_handle_send_status() to the state_machine -- + +V1.15 +- changed max temperature to 55 from 60 according to the data sheet of the cell +- changed ocv_soc_pairs to something close to the curve of other swaytronics batteries diff --git a/Core/Inc/soc_estimation.h b/Core/Inc/soc_estimation.h index 07033d7..bf3f036 100644 --- a/Core/Inc/soc_estimation.h +++ b/Core/Inc/soc_estimation.h @@ -1,6 +1,9 @@ #ifndef INC_SOC_ESTIMATION_H #define INC_SOC_ESTIMATION_H +#include "state_machine.h" +#include "stm32f3xx_hal.h" +#include #include extern float current_soc; diff --git a/Core/Inc/state_machine.h b/Core/Inc/state_machine.h index 1463596..bf8d7e1 100644 --- a/Core/Inc/state_machine.h +++ b/Core/Inc/state_machine.h @@ -85,7 +85,9 @@ State sm_update_error(); void sm_set_relay_positions(State state); void sm_set_relay(Relay relay, bool closed); -void sm_check_battery_temperature(int8_t* id, int16_t* temp); + +void sm_check_battery_temperature(uint8_t* id, uint16_t* temp); +void sm_check_battery_voltage(uint8_t* id, uint16_t* voltage); int16_t sm_return_cell_temperature(int id); int16_t sm_return_cell_voltage(int id); diff --git a/Core/Src/AMS_HighLevel.c b/Core/Src/AMS_HighLevel.c index 4421eef..56fd2bc 100755 --- a/Core/Src/AMS_HighLevel.c +++ b/Core/Src/AMS_HighLevel.c @@ -24,8 +24,8 @@ uint8_t packetChecksumFails = 0; uint8_t deviceSleeps = 0; #define MAX_DEVICE_SLEEP 3 //TODO: change to correct value -#define MAX_CELL_VOLTAGE 4100 //change to 4200 -#define MIN_CELL_VOLTAGE 3100 //change to 3000 +#define MAX_CELL_VOLTAGE 4200 //change to 4200 +#define MIN_CELL_VOLTAGE 3000 //change to 3000 #define CELL_VOLTAGE_DIFF_BALANCING 20 //max difference between lowest cell and any other cell amsState currentAMSState = AMSDEACTIVE; @@ -81,10 +81,10 @@ void AMS_Loop() { case AMSDEACTIVE: break; case AMSCHARGING: - AMS_Balancing_Loop(); + AMS_Idle_Loop(); break; case AMSIDLEBALANCING: - AMS_Balancing_Loop(); + AMS_Idle_Loop(); break; case AMSDISCHARGING: break; @@ -185,6 +185,7 @@ uint8_t AMS_Charging_Loop() { return 0; } uint8_t AMS_Discharging_Loop() { return 0; } uint8_t AMS_Balancing_Loop() { + AMS_Idle_Loop(); uint8_t id_cell_lowest_voltage = 0; uint8_t num_of_cells_to_balance = 0; for (int i = 0; i < 13; i++) { diff --git a/Core/Src/TMP1075.c b/Core/Src/TMP1075.c index 26a9ef1..6dc54d6 100644 --- a/Core/Src/TMP1075.c +++ b/Core/Src/TMP1075.c @@ -1,6 +1,6 @@ #include "TMP1075.h" -#define MAX_TEMP ((int16_t)(59 / 0.0625f)) +#define MAX_TEMP ((int16_t)(55 / 0.0625f)) #define MAX_FAILED_TEMP 2 //TODO: change value for compliance with the actual number of sensors // TODO: "change value for compliance with the actual number of sensors", change temps to float diff --git a/Core/Src/can.c b/Core/Src/can.c index 922ffc9..af3d11e 100644 --- a/Core/Src/can.c +++ b/Core/Src/can.c @@ -73,8 +73,8 @@ void can_handle_send_status() { can_delay_manager = HAL_GetTick() + CAN_STATUS_FREQ; uint8_t data[8] = {}; - int8_t id_highest_temp = -1; - int16_t highest_temp = INT16_MIN; + uint8_t id_highest_temp = 0; + uint16_t highest_temp = 0; sm_check_battery_temperature(&id_highest_temp, &highest_temp); @@ -86,8 +86,6 @@ void can_handle_send_status() { data[5] = ((RELAY_ESC_SIDE_VOLTAGE / 1000)); // 8 bit Inverter voltage data[6] = ((CURRENT_MEASUREMENT / 1000)); // 8 bit Current data[7] = ((highest_temp) >> 4); // 8 bit highest cell temperature - //data[6] = (module.cellVoltages[7] >> 8); - //data[7] = (module.cellVoltages[7]); //data[7] = state.error_source; ftcan_transmit(CAN_ID_OUT, data, sizeof(data)); @@ -129,6 +127,10 @@ void can_handle_recieve_command(const uint8_t *data){ sm_handle_ams_in(data); } else if (data[0] == 0xF1 && data[1] == 0x00) { sm_handle_ams_in(data); + } else if (data[0] == 0xF2 && data[1] == 0x00) { + sm_handle_ams_in(data); + } else if (data[0] == 0xFA && data[1] == 0x00) { + sm_handle_ams_in(data); } else if (data[0] == 0xFF && data[1] == 0x00) { sm_handle_ams_in(data); } diff --git a/Core/Src/soc_estimation.c b/Core/Src/soc_estimation.c index 015ed87..ca26474 100644 --- a/Core/Src/soc_estimation.c +++ b/Core/Src/soc_estimation.c @@ -1,25 +1,21 @@ #include "soc_estimation.h" -#include "state_machine.h" -#include "stm32f3xx_hal.h" - -#include -#include - -#define SOC_ESTIMATION_NO_CURRENT_THRESH 500 // mA -#define SOC_ESTIMATION_NO_CURRENT_TIME 100000 // ms -#define SOC_ESTIMATION_BATTERY_CAPACITY 70300800 // mAs +#define SOC_ESTIMATION_NO_CURRENT_THRESH 1000 // mA +#define SOC_ESTIMATION_NO_CURRENT_TIME 100000 // ms +#define SOC_ESTIMATION_BATTERY_CAPACITY 28800 // mAs #define MIN_CELL_VOLTAGE 3000 -#define MAX_CELL_VOLTAGE 4200 +#define MAX_CELL_VOLTAGE 4130 #warning TODO +// https://www.desmos.com/calculator/mm22vmxl2x ocv_soc_pair_t OCV_SOC_PAIRS[] = { - {25000, 0.00f}, {29900, 3.97f}, {32300, 9.36f}, {33200, 12.60f}, - {33500, 13.68f}, {34100, 20.15f}, {35300, 32.01f}, {38400, 66.53f}, - {40100, 83.79f}, {40200, 90.26f}, {40400, 94.58f}, {41000, 98.89f}, - {42000, 100.00f}}; + {30000, 0.00f}, {33500, 10.00f}, {34500, 20.00f}, + {35000, 30.00f}, {35300, 40.00f}, {35700, 50.00f}, + {36000, 60.00f}, {36300, 70.00f}, {37000, 80.00f}, + {38000, 90.00f}, {41300, 100.00f} +}; float current_soc; @@ -51,7 +47,9 @@ void soc_update() { last_current_time == 0) { // Assume we're measuring OCV if there's been no current for a while (or // we've just turned on the battery). - //current_soc = soc_for_ocv(min_voltage); + uint16_t min_voltage = 0; + sm_check_battery_temperature(0, &min_voltage); + current_soc = soc_for_ocv(min_voltage); } else { // Otherwise, use the current counter to update SoC float as_delta = CURRENT_MEASUREMENT - mAs_before_current; diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 8250b03..555c10f 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -422,7 +422,7 @@ void sm_set_relay(Relay relay, bool closed){ } /* returns the ID and temperature of the hottest cell */ -void sm_check_battery_temperature(int8_t *id, int16_t *temp){ +void sm_check_battery_temperature(uint8_t *id, uint16_t *temp){ for (int i = 0; i < N_TEMP_SENSORS; i++) { if (tmp1075_temps[i] > *temp){ *id = i;