mirror of
https://github.com/doppelhub/Honda_Insight_LiBCM.git
synced 2026-06-10 23:47:28 -04:00
First cut at re-mapping 5AhG3 thermistors to FoMoCo battery type.
This aligns firmware thermistor use with the hardware. For the FoMoCo
case, this is the thermistor use:
5AhG3 FoMoCo
OEM GRN: IMA Intake Top rear battery module
OEM YEL: IMA Exhaust Top middle battery module
OEM WHT: Ambient IMA Intake
With the change, the OEM GRN and YEL thermistors now participate in
temperature_measureBattery(), and no longer in temperature_measureOEM().
Additionally, in the FoMoCo case, there are no explicit Exhaust and
Ambient thermistors, so references to these are removved.
This commit is contained in:
@@ -10,12 +10,12 @@
|
||||
#define CPU_MAP_MEGA2560
|
||||
|
||||
#ifdef CPU_MAP_MEGA2560
|
||||
|
||||
|
||||
#define PIN_BATTCURRENT A0
|
||||
#define PIN_USER_SW A1
|
||||
#define PIN_VPIN_IN A2
|
||||
#define PIN_TEMP_YEL A3
|
||||
#define PIN_TEMP_GRN A4
|
||||
#define PIN_TEMP_YEL A3 // 5AhG3: Exhaust, FoMoCo Top middle battery module
|
||||
#define PIN_TEMP_GRN A4 // 5AhG3: Intake, FoMoCo Top rear battery module
|
||||
#define PIN_TEMP_WHT A5
|
||||
#define PIN_TEMP_BLU A6
|
||||
#define PIN_FANOEM_LOW A7
|
||||
@@ -48,7 +48,7 @@
|
||||
#define PIN_BATTSCI_DE 41
|
||||
#define PIN_COVER_SWITCH 42
|
||||
#define PIN_GPIO0_CS_MIMA 43
|
||||
#define PIN_GPIO3 44 //with daughterboard: 1500W charger current (if installed) //without daughterboard: heater (if installed)
|
||||
#define PIN_GPIO3 44 //with daughterboard: 1500W charger current (if installed) //without daughterboard: heater (if installed)
|
||||
#define PIN_BUZZER_PWM 45
|
||||
#define PIN_LED3 46
|
||||
#define PIN_SPI_EXT_CS 47
|
||||
|
||||
@@ -193,11 +193,19 @@ void debugUSB_printData_temperatures(void)
|
||||
Serial.print(F(", T_in:"));
|
||||
Serial.print(String(temperature_intake_getLatest()));
|
||||
Serial.print(F(", T_out:"));
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
Serial.print(String(temperature_exhaust_getLatest()));
|
||||
#else
|
||||
Serial.print(F("none"));
|
||||
#endif
|
||||
Serial.print(F(", T_charger:"));
|
||||
Serial.print(String(temperature_gridCharger_getLatest()));
|
||||
Serial.print(F(", T_bay:"));
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
Serial.print(String(temperature_ambient_getLatest()));
|
||||
#else
|
||||
Serial.print(F("none"));
|
||||
#endif
|
||||
Serial.print('C');
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void energy_integrate_centiJoules(void);
|
||||
void energy_integrate_centiJoules(void)
|
||||
{
|
||||
static uint32_t timestamp_lastCall_ms = 0;
|
||||
|
||||
|
||||
@@ -24,10 +24,14 @@ void runFansIfNeeded(void)
|
||||
else if (fan_getSpeed_now() == FAN_OFF ) { hysteresis_C = FAN_SPEED_HYSTERESIS_OFF_degC; }
|
||||
|
||||
if ( (temperature_intake_getLatest() < (GRID_CHARGING_FANS_OFF_BELOW_TEMP_C - hysteresis_C)) &&
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
(temperature_ambient_getLatest() < (GRID_CHARGING_FANS_OFF_BELOW_TEMP_C - hysteresis_C)) &&
|
||||
#endif
|
||||
(temperature_battery_getLatest() < (GRID_CHARGING_FANS_OFF_BELOW_TEMP_C - hysteresis_C)) ) { fan_requestSpeed(FAN_REQUESTOR_GRIDCHARGER, FAN_OFF); }
|
||||
else if ( (temperature_intake_getLatest() < (GRID_CHARGING_FANS_LOW_BELOW_TEMP_C - hysteresis_C)) &&
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
(temperature_ambient_getLatest() < (GRID_CHARGING_FANS_LOW_BELOW_TEMP_C - hysteresis_C)) &&
|
||||
#endif
|
||||
(temperature_battery_getLatest() < (GRID_CHARGING_FANS_LOW_BELOW_TEMP_C - hysteresis_C)) ) { fan_requestSpeed(FAN_REQUESTOR_GRIDCHARGER, FAN_LOW); }
|
||||
else { fan_requestSpeed(FAN_REQUESTOR_GRIDCHARGER, FAN_HIGH); }
|
||||
}
|
||||
@@ -61,7 +65,9 @@ uint8_t gridCharger_isAllowedNow(void)
|
||||
if (temperature_battery_getLatest() > DISABLE_GRIDCHARGING_ABOVE_BATTERY_TEMP_C) { return NO__BATTERY_IS_HOT; }
|
||||
if (temperature_intake_getLatest() > DISABLE_GRIDCHARGING_ABOVE_INTAKE_TEMP_C ) { return NO__AIRINTAKE_IS_HOT; }
|
||||
if (temperature_intake_getLatest() == TEMPERATURE_SENSOR_FAULT_LO ) { return NO__TEMP_UNPLUGGED_INTAKE; }
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
if (temperature_exhaust_getLatest() > DISABLE_GRIDCHARGING_ABOVE_EXHAUST_TEMP_C) { return NO__TEMP_EXHAUST_IS_HOT; }
|
||||
#endif
|
||||
//time checks
|
||||
if ((millis() ) < DISABLE_GRIDCHARGING_LIBCM_BOOT_DELAY_ms ) { return NO__LIBCM_JUST_BOOTED; }
|
||||
if ((millis() - latestPlugin_ms ) < DISABLE_GRIDCHARGING_PLUGIN_DELAY_ms ) { return NO__JUST_PLUGGED_IN; }
|
||||
|
||||
@@ -10,17 +10,21 @@
|
||||
|
||||
int8_t tempBattery = ROOM_TEMP_DEGC;
|
||||
int8_t tempIntake = ROOM_TEMP_DEGC;
|
||||
int8_t tempExhaust = ROOM_TEMP_DEGC;
|
||||
int8_t tempCharger = ROOM_TEMP_DEGC;
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo // No explicit exhaust nor ambient temp sensors in FoMoCo case
|
||||
int8_t tempExhaust = ROOM_TEMP_DEGC;
|
||||
int8_t tempAmbient = ROOM_TEMP_DEGC;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int8_t temperature_battery_getLatest(void) { return tempBattery; }
|
||||
int8_t temperature_intake_getLatest(void) { return tempIntake; } //GRN OEM temp sensor
|
||||
int8_t temperature_exhaust_getLatest(void) { return tempExhaust; } //YEL OEM temp sensor
|
||||
int8_t temperature_intake_getLatest(void) { return tempIntake; } //GRN (5AhG3 case) or WHT (FoMoCo case) OEM temp sensor
|
||||
int8_t temperature_gridCharger_getLatest(void){ return tempCharger; } //BLU OEM temp sensor
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo // No explicit exhaust nor ambient temp sensors in FoMoCo case
|
||||
int8_t temperature_exhaust_getLatest(void) { return tempExhaust; } //YEL OEM temp sensor
|
||||
int8_t temperature_ambient_getLatest(void) { return tempAmbient; } //WHT OEM temp sensor
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -34,9 +38,7 @@ void temperature_measureOEM(void)
|
||||
tempAmbient = temperature_measureOneSensor_degC(PIN_TEMP_WHT);
|
||||
#elif defined BATTERY_TYPE_47AhFoMoCo
|
||||
tempIntake = temperature_measureOneSensor_degC(PIN_TEMP_WHT);
|
||||
tempExhaust = temperature_measureOneSensor_degC(PIN_TEMP_GRN); //JTS2doNext: Actually top rear battery module
|
||||
tempCharger = temperature_measureOneSensor_degC(PIN_TEMP_BLU);
|
||||
tempAmbient = temperature_measureOneSensor_degC(PIN_TEMP_YEL); //JTS2doNext: Acutually top middle battery module
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -45,7 +47,6 @@ void temperature_measureOEM(void)
|
||||
//only call inside handler (to ensure sensors powered)
|
||||
//stores the most extreme battery temperature (from room temp) in tempBattery
|
||||
//LiBCM has QTY3 battery temperature sensors
|
||||
//JTS2doNext: Add FoMoCo hardware configuration
|
||||
void temperature_measureBattery(void)
|
||||
{
|
||||
int8_t batteryTemps[NUM_BATTERY_TEMP_SENSORS + 1] = {0}; //1-indexed ([1] = bay1 temp)
|
||||
@@ -53,6 +54,11 @@ void temperature_measureBattery(void)
|
||||
batteryTemps[1] = temperature_measureOneSensor_degC(PIN_TEMP_BAY1);
|
||||
batteryTemps[2] = temperature_measureOneSensor_degC(PIN_TEMP_BAY2);
|
||||
batteryTemps[3] = temperature_measureOneSensor_degC(PIN_TEMP_BAY3);
|
||||
#ifdef BATTERY_TYPE_47AhFoMoCo
|
||||
batteryTemps[4] = temperature_measureOneSensor_degC(PIN_TEMP_GRN); //Top rear battery module
|
||||
batteryTemps[5] = temperature_measureOneSensor_degC(PIN_TEMP_YEL); //Top middle battery module
|
||||
#endif
|
||||
|
||||
|
||||
//stores hottest and coldest temp sensor value
|
||||
int8_t tempHi = TEMPERATURE_SENSOR_FAULT_LO; //highest measured temp is initially set to the lowest possible temp
|
||||
@@ -63,8 +69,29 @@ void temperature_measureBattery(void)
|
||||
if ((batteryTemps[ii] == TEMPERATURE_SENSOR_FAULT_HI) ||
|
||||
(batteryTemps[ii] == TEMPERATURE_SENSOR_FAULT_LO) )
|
||||
{
|
||||
#ifdef BATTERY_TYPE_5AhG3
|
||||
Serial.print(F("\nCheck Batt Temp Sensor! Bay: "));
|
||||
Serial.print(String(ii,DEC));
|
||||
#elif defined BATTERY_TYPE_47AhFoMoCo
|
||||
Serial.print(F("\nCheck Batt Temp Sensor!"));
|
||||
switch (ii) {
|
||||
case 1:
|
||||
Serial.print(F(" Middle tray rail, driver side")); //BAY1
|
||||
break;
|
||||
case 2:
|
||||
Serial.print(F(" Bottom tray, middle")); //BAY2
|
||||
break;
|
||||
case 3:
|
||||
Serial.print(F(" Middle tray rail, passenger side")); //BAY3
|
||||
break;
|
||||
case 4:
|
||||
Serial.print(F(" Top rear battery module"));
|
||||
break;
|
||||
case 5:
|
||||
Serial.print(F(" Top middle battery module"));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -85,7 +112,7 @@ void temperature_measureBattery(void)
|
||||
if (tempLo > ROOM_TEMP_DEGC) { tempLoDelta = tempLo - ROOM_TEMP_DEGC; }
|
||||
else { tempLoDelta = ROOM_TEMP_DEGC - tempLo; }
|
||||
|
||||
//figure out which magnitude is further from ROOM_TEMP_DEGC
|
||||
//figure out which magnitude is further from ROOM_TEMP_DEGC
|
||||
if (tempHiDelta > tempLoDelta) { tempBattery = tempHi; }
|
||||
else { tempBattery = tempLo; }
|
||||
}
|
||||
@@ -99,10 +126,12 @@ void temperature_printAll_latest(void)
|
||||
Serial.print(temperature_gridCharger_getLatest());
|
||||
Serial.print(F("\nIn: "));
|
||||
Serial.print(temperature_intake_getLatest());
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
Serial.print(F("\nAmb: "));
|
||||
Serial.print(temperature_ambient_getLatest());
|
||||
Serial.print(F("\nOut: "));
|
||||
Serial.print(temperature_exhaust_getLatest());
|
||||
#endif
|
||||
Serial.print(F("\nBatt: "));
|
||||
Serial.print(temperature_battery_getLatest());
|
||||
}
|
||||
@@ -113,22 +142,37 @@ void temperature_printAll_latest(void)
|
||||
void temperature_measureAndPrintAll(void)
|
||||
{
|
||||
if (gpio_getPinState(PIN_TEMP_EN) == PIN_OUTPUT_HIGH)
|
||||
{
|
||||
{
|
||||
Serial.print(F("\nTemperatures(C):"));
|
||||
Serial.print(F("\nBLU: "));
|
||||
Serial.print(F("\nBLU (Charger): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BLU));
|
||||
Serial.print(F("\nGRN: "));
|
||||
#ifdef BATTERY_TYPE_5AhG3
|
||||
Serial.print(F("\nGRN (Intake): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_GRN));
|
||||
Serial.print(F("\nWHT: "));
|
||||
Serial.print(F("\nWHT (Ambient): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_WHT));
|
||||
Serial.print(F("\nYEL: "));
|
||||
Serial.print(F("\nYEL (Exhaust): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_YEL));
|
||||
Serial.print(F("\nBAY1: "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY1));
|
||||
Serial.print(F("\nBAY2: "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY2));
|
||||
Serial.print(F("\nBAY3: "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY3));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY3));
|
||||
#elif defined BATTERY_TYPE_47AhFoMoCo
|
||||
Serial.print(F("\nGRN (Top rear battery module): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_GRN));
|
||||
Serial.print(F("\nWHT (Intake): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_WHT));
|
||||
Serial.print(F("\nYEL (Top middle battery module): "));
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_YEL));
|
||||
Serial.print(F("\nMiddle tray rail, driver side: ")); //BAY1
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY1));
|
||||
Serial.print(F("\nBottom tray, middle: ")); //BAY2
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY2));
|
||||
Serial.print(F("\nMiddle tray rail, passenger side: ")); //BAY3
|
||||
Serial.print(temperature_measureOneSensor_degC(PIN_TEMP_BAY3));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -207,18 +251,18 @@ void temperature_handler(void)
|
||||
uint8_t keyState_Now = key_getSampledState(); //prevent mid-loop key state change
|
||||
|
||||
keyState_Now = turnSensorsOff_whenKeyStateChanges(keyState_Now); //JTS2doNow: function returns value meant for tempSensorState //writing to wrong variable?
|
||||
|
||||
|
||||
static uint32_t latestTempMeasurement_ms = 0;
|
||||
static uint32_t latestSensorTurnon_ms = 0;
|
||||
|
||||
if (tempSensorState == TEMPSENSORSTATE_TURNON)
|
||||
{
|
||||
gpio_turnTemperatureSensors_on();
|
||||
gpio_turnTemperatureSensors_on();
|
||||
latestSensorTurnon_ms = millis();
|
||||
tempSensorState = TEMPSENSORSTATE_POWERUP;
|
||||
}
|
||||
|
||||
else if (tempSensorState == TEMPSENSORSTATE_POWERUP)
|
||||
else if (tempSensorState == TEMPSENSORSTATE_POWERUP)
|
||||
{
|
||||
uint32_t timeSinceSensorTurnedOn = (millis() - latestSensorTurnon_ms);
|
||||
|
||||
@@ -234,14 +278,14 @@ void temperature_handler(void)
|
||||
|
||||
if ((keyState_Now == KEYSTATE_ON) || (gpio_isGridChargerPluggedInNow() == YES)) { tempSensorState = TEMPSENSORSTATE_STAYON; }
|
||||
else { tempSensorState = TEMPSENSORSTATE_TURNOFF; }
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempSensorState == TEMPSENSORSTATE_TURNOFF)
|
||||
{
|
||||
//sensors only turn off when key is off and grid charger is unplugged
|
||||
Serial.print(F("\nTemp(C): ")); //print temp when key is off
|
||||
Serial.print(String(tempBattery));
|
||||
gpio_turnTemperatureSensors_off();
|
||||
gpio_turnTemperatureSensors_off();
|
||||
tempSensorState = TEMPSENSORSTATE_OFF;
|
||||
}
|
||||
|
||||
@@ -262,14 +306,14 @@ void temperature_handler(void)
|
||||
|
||||
//JTS2doLater: Need to differentiate between TEMPERATURE_SENSOR_FAULT_LO and actually being below -30 degC
|
||||
int8_t temperature_measureOneSensor_degC(uint8_t thermistorPin)
|
||||
{
|
||||
{
|
||||
uint16_t countsADC = analogRead(thermistorPin); //measure ADC counts
|
||||
|
||||
//This commented out section is quite math intensive:
|
||||
// -QTY3 floating point divisions
|
||||
// -QTY1 natural log (+5kB to load library)
|
||||
// -QTY3 multiplies
|
||||
// -QTY3 add/subtract
|
||||
// -QTY3 add/subtract
|
||||
// #define TEMP_BALANCE_RESISTANCE_OHMS 10000
|
||||
// if (countsADC > 887) { countsADC = 887; } //prevent overflowing uint16_t in the next equation
|
||||
|
||||
@@ -282,7 +326,7 @@ int8_t temperature_measureOneSensor_degC(uint8_t thermistorPin)
|
||||
// #define ADC_COUNTS_AT_VCC 1023
|
||||
// // resistanceThermistor_ohms = ( countsADC * TEMP_BALANCE_RESISTANCE_OHMS) / (counts_VCC - countsADC )
|
||||
// uint16_t resistanceThermistor_ohms = ( countsADC * TEMP_BALANCE_RESISTANCE_OHMS) / (ADC_COUNTS_AT_VCC - countsADC); //if countsADC exceeds 887 this will overflow
|
||||
|
||||
|
||||
// //Steinhart-Hart Beta Equation:
|
||||
// #define THERMISTOR_BETA 3982 //from datasheet
|
||||
// #define THERMISTOR_RESISTANCE_23DEGC 10000 // half ADC range since both resistors are 10kOhm at room temperature
|
||||
@@ -417,7 +461,7 @@ int8_t temperature_measureOneSensor_degC(uint8_t thermistorPin)
|
||||
//correct for OEM temperature sensor's (unknown) k-coefficients
|
||||
//empirical data: ~/GitHub/Honda_Insight_LiBCM/Firmware/MVP/Calculations/OEM thermistor scaling.ods
|
||||
if ( ((tempMeasured_celsius > TEMPERATURE_SENSOR_FAULT_LO ) && (tempMeasured_celsius < TEMPERATURE_SENSOR_FAULT_HI )) &&
|
||||
((thermistorPin == PIN_TEMP_GRN) || (thermistorPin == PIN_TEMP_BLU) || (thermistorPin == PIN_TEMP_YEL) || (thermistorPin == PIN_TEMP_WHT)) )
|
||||
((thermistorPin == PIN_TEMP_GRN) || (thermistorPin == PIN_TEMP_BLU) || (thermistorPin == PIN_TEMP_YEL) || (thermistorPin == PIN_TEMP_WHT)) )
|
||||
{
|
||||
tempMeasured_celsius = ((tempMeasured_celsius * 5) >> 2) - 5; //actual: countsADC = countsADC * 1.225 - 4;
|
||||
}
|
||||
|
||||
@@ -6,15 +6,17 @@
|
||||
|
||||
int8_t temperature_battery_getLatest(void);
|
||||
int8_t temperature_intake_getLatest(void);
|
||||
int8_t temperature_exhaust_getLatest(void);
|
||||
int8_t temperature_gridCharger_getLatest(void);
|
||||
#ifndef BATTERY_TYPE_47AhFoMoCo
|
||||
int8_t temperature_exhaust_getLatest(void);
|
||||
int8_t temperature_ambient_getLatest(void); //IMA bay temperature
|
||||
#endif
|
||||
|
||||
int8_t temperature_measureOneSensor_degC(uint8_t thermistorPin);
|
||||
|
||||
void temperature_measureAndPrintAll(void);
|
||||
void temperature_printAll_latest(void);
|
||||
|
||||
|
||||
int8_t temperature_coolBatteryAbove_C(void);
|
||||
int8_t temperature_heatBatteryBelow_C(void);
|
||||
|
||||
@@ -25,7 +27,7 @@
|
||||
#define TEMPERATURE_PACK_IN_THERMAL_RUNAWAY 70
|
||||
|
||||
#define TEMPSENSORSTATE_OFF 1
|
||||
#define TEMPSENSORSTATE_TURNON 2
|
||||
#define TEMPSENSORSTATE_TURNON 2
|
||||
#define TEMPSENSORSTATE_POWERUP 4
|
||||
#define TEMPSENSORSTATE_MEASURE 8
|
||||
#define TEMPSENSORSTATE_STAYON 16
|
||||
@@ -34,7 +36,12 @@
|
||||
#define ROOM_TEMP_DEGC 23
|
||||
#define TEMP_FREEZING_DEGC 0
|
||||
|
||||
#ifdef BATTERY_TYPE_5AhG3
|
||||
#define NUM_BATTERY_TEMP_SENSORS 3
|
||||
#elif defined BATTERY_TYPE_47AhFoMoCo
|
||||
// what were 2 OEM temp sensors (PIN_TEMP_GRN, PIN_TEMP_YEL) are now on battery modules
|
||||
#define NUM_BATTERY_TEMP_SENSORS 5
|
||||
#endif
|
||||
|
||||
#define TEMP_POWERUP_DELAY_ms 100
|
||||
|
||||
|
||||
Reference in New Issue
Block a user