diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 436398a7b2..04d078b106 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -69,6 +69,13 @@ public: IgnitionEventList ignitionEvents[2]; }; +class ThermistorMath { +public: + ThermistorMath(); + thermistor_conf_s currentConfig; + thermistor_curve_s curve; + void init(thermistor_conf_s currentConfig); +}; class EngineState { public: @@ -81,6 +88,9 @@ public: float iat; float clt; + ThermistorMath iatCurve; + ThermistorMath cltCurve; + angle_t mapAveragingStart; angle_t mapAveragingDuration; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 030264c53a..45f92614da 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated by config_definition.jar on Fri May 22 07:17:51 EDT 2015 +// this section was generated by config_definition.jar on Fri May 22 14:07:18 EDT 2015 // begin #include "rusefi_types.h" typedef struct { @@ -141,7 +141,7 @@ typedef struct { /** * offset 28 */ - thermistor_curve_s curve; + float unused[3]; /** total size 40*/ } ThermistorConf; @@ -1326,4 +1326,4 @@ typedef struct { } persistent_config_s; // end -// this section was generated by config_definition.jar on Fri May 22 07:17:51 EDT 2015 +// this section was generated by config_definition.jar on Fri May 22 14:07:18 EDT 2015 diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index 179a750294..e59c927398 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -87,12 +87,7 @@ #define clt_resistance_3_offset_hex 114 #define clt_bias_resistor_offset 280 #define clt_bias_resistor_offset_hex 118 -#define clt_curve_offset 284 -#define clt_s_h_a_offset 284 -#define clt_s_h_b_offset 288 -#define clt_s_h_b_offset_hex 120 -#define clt_s_h_c_offset 292 -#define clt_s_h_c_offset_hex 124 +#define clt_unused_offset 284 #define iat_offset 296 #define iat_offset_hex 128 #define iat_config_offset 296 @@ -109,13 +104,8 @@ #define iat_resistance_3_offset 316 #define iat_bias_resistor_offset 320 #define iat_bias_resistor_offset_hex 140 -#define iat_curve_offset 324 -#define iat_curve_offset_hex 144 -#define iat_s_h_a_offset 324 -#define iat_s_h_a_offset_hex 144 -#define iat_s_h_b_offset 328 -#define iat_s_h_b_offset_hex 148 -#define iat_s_h_c_offset 332 +#define iat_unused_offset 324 +#define iat_unused_offset_hex 144 #define sparkDwellBins_offset 336 #define sparkDwellBins_offset_hex 150 #define sparkDwell_offset 368 diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index 8909883bfb..1a1cc39ccb 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -45,13 +45,14 @@ float getVoutInVoltageDividor(float Vin, float r1, float r2) { return r2 * Vin / (r1 + r2); } -float convertResistanceToKelvinTemperature(float resistance, ThermistorConf *thermistor) { +float convertResistanceToKelvinTemperature(float resistance, thermistor_curve_s * curve) { + efiAssert(curve != NULL, "thermistor pointer is NULL", NAN); + if (resistance <= 0) { //warning("Invalid resistance in convertResistanceToKelvinTemperature=", resistance); return 0.0f; } float logR = logf(resistance); - thermistor_curve_s * curve = &thermistor->curve; return 1 / (curve->s_h_a + curve->s_h_b * logR + curve->s_h_c * logR * logR * logR); } @@ -68,14 +69,9 @@ float convertKelvinToFahrenheit(float kelvin) { return convertCelsiustoF(tempC); } -float getKelvinTemperature(float resistance, ThermistorConf *thermistor) { - if (thermistor == NULL) { - firmwareError("thermistor pointer is NULL"); - return NAN; - } - - float kelvinTemperature = convertResistanceToKelvinTemperature(resistance, thermistor); - return kelvinTemperature; +float getKelvinTemperature(float resistance, thermistor_curve_s * curve) { + // todo: inline thid method + return convertResistanceToKelvinTemperature(resistance, curve); } float getResistance(Thermistor *thermistor) { @@ -87,14 +83,14 @@ float getResistance(Thermistor *thermistor) { return resistance; } -float getTemperatureC(Thermistor *thermistor) { +float getTemperatureC(Thermistor *thermistor, thermistor_curve_s * curve) { if (!initialized) { firmwareError("thermstr not initialized"); return NAN; } float resistance = getResistance(thermistor); - float kelvinTemperature = getKelvinTemperature(resistance, thermistor->config); + float kelvinTemperature = getKelvinTemperature(resistance, curve); return convertKelvinToCelcius(kelvinTemperature); } @@ -112,7 +108,7 @@ bool isValidIntakeAirTemperature(float temperature) { * @return coolant temperature, in Celsius */ float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F) { - float temperature = getTemperatureC(&engine->clt); + float temperature = getTemperatureC(&engine->clt, &engine->engineState.cltCurve.curve); if (!isValidCoolantTemperature(temperature)) { efiAssert(engineConfiguration!=NULL, "NULL engineConfiguration", NAN); if (engineConfiguration->hasCltSensor) { @@ -136,7 +132,7 @@ void setThermistorConfiguration(ThermistorConf * thermistor, float tempC1, float tc->resistance_3 = r3; } -void prepareThermistorCurve(ThermistorConf * config) { +void prepareThermistorCurve(ThermistorConf * config, thermistor_curve_s * curve) { efiAssertVoid(config!=NULL, "therm config"); thermistor_conf_s *tc = &config->config; float T1 = tc->tempC_1 + KELV; @@ -165,22 +161,19 @@ void prepareThermistorCurve(ThermistorConf * config) { scheduleMsg(logger, "U2=%..100000f/U3=%..100000f", U2, U3); - thermistor_curve_s * curve = &config->curve; - curve->s_h_c = (U3 - U2) / (L3 - L2) * pow(L1 + L2 + L3, -1); curve->s_h_b = U2 - curve->s_h_c * (L1 * L1 + L1 * L2 + L2 * L2); curve->s_h_a = Y1 - (curve->s_h_b + L1 * L1 * curve->s_h_c) * L1; scheduleMsg(logger, "s_h_c=%..100000f/s_h_b=%..100000f/s_h_a=%..100000f", curve->s_h_c, curve->s_h_b, curve->s_h_a); - } /** * @return Celsius value */ float getIntakeAirTemperature(DECLARE_ENGINE_PARAMETER_F) { - float temperature = getTemperatureC(&engine->iat); + float temperature = getTemperatureC(&engine->iat, &engine->engineState.iatCurve.curve); if (!isValidIntakeAirTemperature(temperature)) { efiAssert(engineConfiguration!=NULL, "NULL engineConfiguration", NAN); if (engineConfiguration->hasIatSensor) { @@ -191,8 +184,9 @@ float getIntakeAirTemperature(DECLARE_ENGINE_PARAMETER_F) { return temperature; } -static void initThermistorCurve(Thermistor * t, ThermistorConf *config, adc_channel_e channel) { - prepareThermistorCurve(config); +static void initThermistorCurve(Thermistor * t, ThermistorConf *config, adc_channel_e channel, + thermistor_curve_s * curve) { + prepareThermistorCurve(config, curve); t->config = config; t->channel = channel; } @@ -215,10 +209,11 @@ void setCommonNTCSensor(ThermistorConf *thermistorConf) { #if EFI_PROD_CODE static void testCltByR(float resistance) { Thermistor *thermistor = &engine->clt; - float kTemp = getKelvinTemperature(resistance, thermistor->config); + float kTemp = getKelvinTemperature(resistance, &engine->engineState.cltCurve.curve); scheduleMsg(logger, "for R=%f we have %f", resistance, (kTemp - KELV)); - initThermistorCurve(&engine->clt, &engineConfiguration->clt, engineConfiguration->cltAdcChannel); + initThermistorCurve(&engine->clt, &engineConfiguration->clt, engineConfiguration->cltAdcChannel, + &engine->engineState.cltCurve.curve); } #endif @@ -227,8 +222,10 @@ void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { logger = sharedLogger; efiAssertVoid(engine!=NULL, "e NULL initThermistors"); efiAssertVoid(engine->engineConfiguration2!=NULL, "e2 NULL initThermistors"); - initThermistorCurve(&engine->clt, &engineConfiguration->clt, engineConfiguration->cltAdcChannel); - initThermistorCurve(&engine->iat, &engineConfiguration->iat, engineConfiguration->iatAdcChannel); + initThermistorCurve(&engine->clt, &engineConfiguration->clt, engineConfiguration->cltAdcChannel, + &engine->engineState.cltCurve.curve); + initThermistorCurve(&engine->iat, &engineConfiguration->iat, engineConfiguration->iatAdcChannel, + &engine->engineState.iatCurve.curve); #if EFI_PROD_CODE addConsoleActionF("test_clt_by_r", testCltByR); @@ -236,3 +233,11 @@ void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { initialized = true; } + +ThermistorMath::ThermistorMath() { + +} + +void ThermistorMath::init(thermistor_conf_s currentConfig) { + +} diff --git a/firmware/controllers/sensors/thermistors.h b/firmware/controllers/sensors/thermistors.h index 03bccae966..1c38c12c54 100644 --- a/firmware/controllers/sensors/thermistors.h +++ b/firmware/controllers/sensors/thermistors.h @@ -31,19 +31,19 @@ float getTempK(float resistance); float convertCelciustoF(float tempC); float convertFtoCelcius(float tempF); -float getKelvinTemperature(float resistance, ThermistorConf *thermistor); +float getKelvinTemperature(float resistance, thermistor_curve_s * curve); float getResistance(Thermistor *thermistor); -float getTemperatureC(Thermistor *thermistor); +float getTemperatureC(Thermistor *thermistor, thermistor_curve_s * curve); float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F); bool isValidCoolantTemperature(float temperature); float getIntakeAirTemperature(DECLARE_ENGINE_PARAMETER_F); bool isValidIntakeAirTemperature(float temperature); float convertResistanceToKelvinTemperature(float resistance, - ThermistorConf *thermistor); + thermistor_curve_s * curve); void setThermistorConfiguration(ThermistorConf * tc, float temp1, float r1, float temp2, float r2, float temp3, float r3); -void prepareThermistorCurve(ThermistorConf * config); +void prepareThermistorCurve(ThermistorConf * config, thermistor_curve_s * curve); class Engine; diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 4f70dae4ea..3625e60e29 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -367,12 +367,12 @@ static void setOM(int value) { static char pinNameBuffer[16]; -static void printThermistor(const char *msg, Thermistor *thermistor) { +static void printThermistor(const char *msg, Thermistor *thermistor, thermistor_curve_s * curve) { adc_channel_e adcChannel = thermistor->channel; float voltage = getVoltageDivided("term", adcChannel); float r = getResistance(thermistor); - float t = getTemperatureC(thermistor); + float t = getTemperatureC(thermistor, curve); thermistor_conf_s *tc = &thermistor->config->config; @@ -383,7 +383,6 @@ static void printThermistor(const char *msg, Thermistor *thermistor) { tc->tempC_2, tc->resistance_2, tc->tempC_3, tc->resistance_3); - thermistor_curve_s * curve = &thermistor->config->curve; scheduleMsg(&logger, "bias resistor=%fK A=%..100000f B=%..100000f C=%..100000f", tc->bias_resistor / 1000, curve->s_h_a, curve->s_h_b, curve->s_h_c); scheduleMsg(&logger, "=============================="); @@ -429,11 +428,11 @@ static void printTPSInfo(void) { static void printTemperatureInfo(void) { #if EFI_ANALOG_SENSORS || defined(__DOXYGEN__) - printThermistor("CLT", &engine->clt); + printThermistor("CLT", &engine->clt, &engine->engineState.cltCurve.curve); if (!isValidCoolantTemperature(getCoolantTemperature(PASS_ENGINE_PARAMETER_F))) { scheduleMsg(&logger, "CLT sensing error"); } - printThermistor("IAT", &engine->iat); + printThermistor("IAT", &engine->iat, &engine->engineState.iatCurve.curve); if (!isValidIntakeAirTemperature(getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F))) { scheduleMsg(&logger, "IAT sensing error"); } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index ec86889afe..0bc78b2426 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -119,7 +119,7 @@ end_struct struct ThermistorConf @brief Thermistor curve parameters thermistor_conf_s config; - thermistor_curve_s curve; + float[3] unused; end_struct custom engine_type_e 4 bits, S32, @OFFSET@, [0:2], "AUDI_AAN", "DODGE_NEON_1995", "FORD_ASPIRE_1996", "FORD_FIESTA", "NISSAN_PRIMERA", "HONDA_ACCORD", "FORD_INLINE_6_1995", "GY6_139QMB" diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index af304ffb8d..846366c811 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -291,5 +291,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20150521; + return 20150522; } diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 13a74c3e82..73f731542d 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -40,7 +40,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated by ConfigDefinition.jar on Fri May 22 06:40:33 EDT 2015 +; this section was generated by ConfigDefinition.jar on Fri May 22 14:07:20 EDT 2015 pageSize = 15288 page = 1 @@ -76,9 +76,7 @@ page = 1 clt_resistance_2 = scalar, F32, 272, "Ohm", 1, 0, 0, 200000, 1 clt_resistance_3 = scalar, F32, 276, "Ohm", 1, 0, 0, 200000, 1 clt_bias_resistor = scalar, F32, 280, "Ohm", 1, 0, 0, 200000, 1 -;skipping clt_s_h_a offset 284 -;skipping clt_s_h_b offset 288 -;skipping clt_s_h_c offset 292 +;skipping clt_unused offset 284 iat_tempC_1 = scalar, F32, 296, "*C", 1, 0, -40, 200, 1 iat_tempC_2 = scalar, F32, 300, "*C", 1, 0, -40, 200, 1 iat_tempC_3 = scalar, F32, 304, "*C", 1, 0, -40, 200, 1 @@ -86,9 +84,7 @@ page = 1 iat_resistance_2 = scalar, F32, 312, "Ohm", 1, 0, 0, 200000, 1 iat_resistance_3 = scalar, F32, 316, "Ohm", 1, 0, 0, 200000, 1 iat_bias_resistor = scalar, F32, 320, "Ohm", 1, 0, 0, 200000, 1 -;skipping iat_s_h_a offset 324 -;skipping iat_s_h_b offset 328 -;skipping iat_s_h_c offset 332 +;skipping iat_unused offset 324 sparkDwellBins = array, F32, 336, [8], "RPM", 1, 0.0, 0.0, 18000, 2 sparkDwell = array, F32, 368, [8], "ms", 1, 0.0, 0.0, 30.0, 2 displacement = scalar, F32, 400, "L", 1, 0, 0, 1000.0, 2 diff --git a/unit_tests/test_sensors.cpp b/unit_tests/test_sensors.cpp index 9c10ba2205..227b2c6f59 100644 --- a/unit_tests/test_sensors.cpp +++ b/unit_tests/test_sensors.cpp @@ -86,32 +86,31 @@ void testSensors(void) { testTpsRateOfChange(); testHip9011lookup(); + thermistor_curve_s c; + thermistor_curve_s *curve = &c; { setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000); - prepareThermistorCurve(&tc); - - thermistor_curve_s * curve = &tc.curve; + prepareThermistorCurve(&tc, curve); assertEquals(-0.003, curve->s_h_a); assertEquals(0.001, curve->s_h_b); assertEquals(0.0, curve->s_h_c); - float t = convertResistanceToKelvinTemperature(2100, &tc); + float t = convertResistanceToKelvinTemperature(2100, curve); assertEquals(75 + KELV, t); } { // 2003 Neon sensor setThermistorConfiguration(&tc, 0, 32500, 30, 7550, 100, 700); - prepareThermistorCurve(&tc); - thermistor_curve_s * curve = &tc.curve; + prepareThermistorCurve(&tc, curve); assertEqualsM("A", 0.0009, curve->s_h_a); assertEqualsM("B", 0.0003, curve->s_h_b); assertEquals(0.0, curve->s_h_c); - float t = convertResistanceToKelvinTemperature(38000, &tc); + float t = convertResistanceToKelvinTemperature(38000, curve); assertEquals(-2.7983, t - KELV); } }