diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index 92f6da6338..a288083d7b 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -47,24 +47,24 @@ typedef struct { char crcReadBuffer[350]; } ts_channel_s; -#define TS_HELLO_COMMAND_DEPRECATED 'H' -#define TS_HELLO_COMMAND 'S' -#define TS_TEST_COMMAND 't' -#define TS_LEGACY_HELLO_COMMAND 'Q' -#define TS_OUTPUT_COMMAND 'O' -#define TS_READ_COMMAND 'R' -#define TS_PAGE_COMMAND 'P' -#define TS_COMMAND_F 'F' -#define TS_EXECUTE 'E' -#define TS_GET_TEXT 'G' +#define TS_HELLO_COMMAND_DEPRECATED 'H' // 0x48 +#define TS_HELLO_COMMAND 'S' // 0x53 +#define TS_TEST_COMMAND 't' // 0x74 +#define TS_LEGACY_HELLO_COMMAND 'Q' // 0x51 +#define TS_OUTPUT_COMMAND 'O' // 0x4F +#define TS_READ_COMMAND 'R' // 0x52 +#define TS_PAGE_COMMAND 'P' // 0x50 +#define TS_COMMAND_F 'F' // 0x46 +#define TS_EXECUTE 'E' // 0x45 +#define TS_GET_TEXT 'G' // 0x47 #define TS_GET_FILE_RANGE '2' -#define TS_SINGLE_WRITE_COMMAND 'W' -#define TS_CHUNK_WRITE_COMMAND 'C' -#define TS_BURN_COMMAND 'B' -#define TS_IO_TEST_COMMAND 'w' +#define TS_SINGLE_WRITE_COMMAND 'W' // 0x57 +#define TS_CHUNK_WRITE_COMMAND 'C' // 0x43 +#define TS_BURN_COMMAND 'B' // 0x42 +#define TS_IO_TEST_COMMAND 'w' // 0x77 -#define TS_CRC_CHECK_COMMAND 'k' +#define TS_CRC_CHECK_COMMAND 'k' // 0x6B #define CRC_VALUE_SIZE 4 // todo: double-check this diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index c797f84bb8..c25a1a91cf 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -56,8 +56,11 @@ private: class ThermistorMath { public: ThermistorMath(); - thermistor_curve_s curve; void setConfig(thermistor_conf_s *config); + void prepareThermistorCurve(thermistor_conf_s *tc); + float s_h_a; + float s_h_b; + float s_h_c; private: thermistor_conf_s currentConfig; }; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index fbae684855..74b2b4338a 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 automatically by ConfigDefinition.jar based on rusefi_config.txt Wed Dec 21 11:35:20 EST 2016 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Dec 22 13:03:39 EST 2016 // begin #ifndef ENGINE_CONFIGURATION_GENERATED_H_ #define ENGINE_CONFIGURATION_GENERATED_H_ @@ -134,26 +134,6 @@ typedef struct { /** total size 28*/ } thermistor_conf_s; -/** - * @brief Thermistor curve parameters - -*/ -typedef struct { - /** - * offset 0 - */ - float s_h_a; - /** - * offset 4 - */ - float s_h_b; - /** - * offset 8 - */ - float s_h_c; - /** total size 12*/ -} thermistor_curve_s; - /** * @brief Thermistor curve parameters @@ -2026,4 +2006,4 @@ typedef struct { #endif // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Wed Dec 21 11:35:20 EST 2016 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Dec 22 13:03:39 EST 2016 diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index 533da9940a..db6c693601 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -51,15 +51,13 @@ float getVoutInVoltageDividor(float Vin, float r1, float r2) { float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm) { tm->setConfig(&config->config); // implementation checks if config has changed or not - thermistor_curve_s * curve = &tm->curve; - efiAssert(curve != NULL, "thermistor pointer is NULL", NAN); if (resistance <= 0) { //warning("Invalid resistance in getKelvinTemperature=", resistance); return 0.0f; } float logR = logf(resistance); - return 1 / (curve->s_h_a + curve->s_h_b * logR + curve->s_h_c * logR * logR * logR); + return 1 / (tm->s_h_a + tm->s_h_b * logR + tm->s_h_c * logR * logR * logR); } float convertCelsiustoF(float tempC) { @@ -75,8 +73,7 @@ float convertKelvinToFahrenheit(float kelvin) { return convertCelsiustoF(tempC); } -float getResistance(ThermistorConf *config) { - float voltage = getVoltageDivided("term", config->adcChannel); +float getResistance(ThermistorConf *config, float voltage) { efiAssert(config != NULL, "thermistor config is null", NAN); thermistor_conf_s *tc = &config->config; @@ -89,7 +86,8 @@ float getTemperatureC(ThermistorConf *config, ThermistorMath *tm) { firmwareError(CUSTOM_ERR_THERM, "thermstr not initialized"); return NAN; } - float resistance = getResistance(config); + float voltage = getVoltageDivided("term", config->adcChannel); + float resistance = getResistance(config, voltage); float kelvinTemperature = getKelvinTemperature(config, resistance, tm); return convertKelvinToCelcius(kelvinTemperature); @@ -138,7 +136,7 @@ void setThermistorConfiguration(ThermistorConf * thermistor, float tempC1, float tc->resistance_3 = r3; } -static void prepareThermistorCurve(thermistor_conf_s *tc, thermistor_curve_s * curve) { +void ThermistorMath::prepareThermistorCurve(thermistor_conf_s *tc) { float T1 = tc->tempC_1 + KELV; float T2 = tc->tempC_2 + KELV; float T3 = tc->tempC_3 + KELV; @@ -167,9 +165,9 @@ static void prepareThermistorCurve(thermistor_conf_s *tc, thermistor_curve_s * c float U3 = (Y3 - Y1) / (L3 - L1); - 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; + s_h_c = (U3 - U2) / (L3 - L2) * pow(L1 + L2 + L3, -1); + s_h_b = U2 - s_h_c * (L1 * L1 + L1 * L2 + L2 * L2); + s_h_a = Y1 - (s_h_b + L1 * L1 * s_h_c) * L1; #if EXTREME_TERM_LOGGING || defined(__DOXYGEN__) scheduleMsg(logger, "Y1=%..100000f/Y2=%..100000f/Y3=%..100000f", Y1, Y2, Y3); @@ -234,7 +232,7 @@ void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { ThermistorMath::ThermistorMath() { memset(¤tConfig, 0, sizeof(currentConfig)); - memset(&curve, 0, sizeof(curve)); + s_h_a = s_h_b = s_h_c = 0; } void ThermistorMath::setConfig(thermistor_conf_s *config) { @@ -243,5 +241,5 @@ void ThermistorMath::setConfig(thermistor_conf_s *config) { return; } memcpy(¤tConfig, config, sizeof(currentConfig)); - prepareThermistorCurve(config, &curve); + prepareThermistorCurve(config); } diff --git a/firmware/controllers/sensors/thermistors.h b/firmware/controllers/sensors/thermistors.h index 759d506f6d..254db80d87 100644 --- a/firmware/controllers/sensors/thermistors.h +++ b/firmware/controllers/sensors/thermistors.h @@ -31,7 +31,7 @@ float convertCelciustoF(float tempC); float convertFtoCelcius(float tempF); float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm); -float getResistance(ThermistorConf *config); +float getResistance(ThermistorConf *config, float voltage); float getTemperatureC(ThermistorConf *config, ThermistorMath *tm); float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F); bool isValidCoolantTemperature(float temperature); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 2869e285ec..5ff98fc663 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -376,10 +376,9 @@ static void setOM(int value) { static char pinNameBuffer[16]; static void printThermistor(const char *msg, ThermistorConf *config, ThermistorMath *tm) { - thermistor_curve_s * curve = &tm->curve; adc_channel_e adcChannel = config->adcChannel; float voltage = getVoltageDivided("term", adcChannel); - float r = getResistance(config); + float r = getResistance(config, voltage); float t = getTemperatureC(config, tm); @@ -393,7 +392,7 @@ static void printThermistor(const char *msg, ThermistorConf *config, ThermistorM tc->tempC_3, tc->resistance_3); 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); + tm->s_h_a, tm->s_h_b, tm->s_h_c); scheduleMsg(&logger, "=============================="); } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 1e5cb477d2..3e114c6871 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -158,12 +158,6 @@ float resistance_3;;"Ohm", 1, 0, 0, 200000, 1 float bias_resistor;;"Ohm", 1, 0, 0, 200000, 1 end_struct -struct_no_prefix thermistor_curve_s @brief Thermistor curve parameters - float s_h_a; - float s_h_b; - float s_h_c; -end_struct - struct ThermistorConf @brief Thermistor curve parameters thermistor_conf_s config; adc_channel_e adcChannel; diff --git a/unit_tests/test_sensors.cpp b/unit_tests/test_sensors.cpp index a025bbdc2a..70c5d12c9f 100644 --- a/unit_tests/test_sensors.cpp +++ b/unit_tests/test_sensors.cpp @@ -89,15 +89,14 @@ void testSensors(void) { testHip9011lookup(); ThermistorMath tm; - thermistor_curve_s *curve = &tm.curve; { setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000); float t = getKelvinTemperature(&tc, 2100, &tm); assertEquals(75 + KELV, t); - assertEquals(-0.003, curve->s_h_a); - assertEquals(0.001, curve->s_h_b); - assertEquals(0.0, curve->s_h_c); + assertEquals(-0.003, tm.s_h_a); + assertEquals(0.001, tm.s_h_b); + assertEquals(0.0, tm.s_h_c); } @@ -108,9 +107,9 @@ void testSensors(void) { float t = getKelvinTemperature(&tc, 38000, &tm); assertEquals(-2.7983, t - KELV); - assertEqualsM("A", 0.0009, curve->s_h_a); - assertEqualsM("B", 0.0003, curve->s_h_b); - assertEquals(0.0, curve->s_h_c); + assertEqualsM("A", 0.0009, tm.s_h_a); + assertEqualsM("B", 0.0003, tm.s_h_b); + assertEquals(0.0, tm.s_h_c); } }