From 5a52b3757c3c7663610b19ec2fafb6ca99a08470 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 28 Jan 2024 23:26:53 +0200 Subject: [PATCH 1/2] Tesla: Improve accuracy on temperature --- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index a6d620d6..66c3c6de 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -32,8 +32,8 @@ static uint16_t volts = 0; // V static int16_t amps = 0; // A static int16_t power = 0; // W static uint16_t raw_amps = 0; // A -static int16_t max_temp = 6; // C* -static int16_t min_temp = 5; // C* +static int16_t max_temp = 60; // C* +static int16_t min_temp = 50; // C* static uint16_t energy_buffer = 0; static uint16_t energy_to_charge_complete = 0; static uint16_t expected_energy_remaining = 0; @@ -209,10 +209,8 @@ void update_values_tesla_model_3_battery() { //This function maps all the value power = ((volts / 10) * amps); stat_batt_power = convert2unsignedInt16(power); - min_temp = (min_temp * 10); temperature_min = convert2unsignedInt16(min_temp); - max_temp = (max_temp * 10); temperature_max = convert2unsignedInt16(max_temp); cell_max_voltage = cell_max_v; @@ -443,11 +441,8 @@ void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame) { } if (mux == 0) //Temperature sensors { - temp = rx_frame.data.u8[2]; - max_temp = (temp * 0.5) - 40; //in celcius, Example 24 - - temp = rx_frame.data.u8[3]; - min_temp = (temp * 0.5) - 40; //in celcius , Example 24 + max_temp = (rx_frame.data.u8[2] * 5) - 400; //40.0*C offset, value for instance 85 = 8.5*C + min_temp = (rx_frame.data.u8[3] * 5) - 400; //40.0*C offset, value for instance 85 = 8.5*C } break; case 0x2d2: From 7f3c6adbcdd431d1277d7f58cd71b952c01149d7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 29 Jan 2024 20:23:24 +0200 Subject: [PATCH 2/2] Init to 0, update comment --- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 66c3c6de..35d54535 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -32,8 +32,8 @@ static uint16_t volts = 0; // V static int16_t amps = 0; // A static int16_t power = 0; // W static uint16_t raw_amps = 0; // A -static int16_t max_temp = 60; // C* -static int16_t min_temp = 50; // C* +static int16_t max_temp = 0; // C* +static int16_t min_temp = 0; // C* static uint16_t energy_buffer = 0; static uint16_t energy_to_charge_complete = 0; static uint16_t expected_energy_remaining = 0; @@ -441,8 +441,8 @@ void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame) { } if (mux == 0) //Temperature sensors { - max_temp = (rx_frame.data.u8[2] * 5) - 400; //40.0*C offset, value for instance 85 = 8.5*C - min_temp = (rx_frame.data.u8[3] * 5) - 400; //40.0*C offset, value for instance 85 = 8.5*C + max_temp = (rx_frame.data.u8[2] * 5) - 400; //Temperature values have 40.0*C offset, 0.5*C /bit + min_temp = (rx_frame.data.u8[3] * 5) - 400; //Multiply by 5 and remove offset to get C+1 (0x61*5=485-400=8.5*C) } break; case 0x2d2: