Better validation of thermistor configuration fix #6724
This commit is contained in:
parent
7013090136
commit
4434b691fd
|
@ -55,4 +55,23 @@ void ThermistorFunc::configure(thermistor_conf_s &cfg) {
|
|||
m_c = ((u3 - u2) / (l3 - l2)) / (l1 + l2 + l3);
|
||||
m_b = u2 - m_c * (l1 * l1 + l1 * l2 + l2 * l2);
|
||||
m_a = y1 - (m_b + l1 * l1 * m_c) * l1;
|
||||
|
||||
float resistance10percent = cfg.resistance_1 + 0.1 * (cfg.resistance_2 - cfg.resistance_1);
|
||||
float tempAt10percentPoint = convert(resistance10percent).Value;
|
||||
|
||||
if (tempAt10percentPoint < cfg.tempC_1) {
|
||||
#if EFI_UNIT_TEST
|
||||
throw std::logic_error("Bad thermistor configuration at the left");
|
||||
#endif
|
||||
criticalError("Thermistor configuration has failed 10% test");
|
||||
}
|
||||
|
||||
float resistance90percent = cfg.resistance_2 + 0.9 * (cfg.resistance_3 - cfg.resistance_2);
|
||||
float tempAt90percentPoint = convert(resistance90percent).Value;
|
||||
if (tempAt90percentPoint > cfg.tempC_3) {
|
||||
#if EFI_UNIT_TEST
|
||||
throw std::logic_error("Bad thermistor configuration at the right");
|
||||
#endif
|
||||
criticalError("Thermistor configuration has failed 90% test");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ TEST(thermistor, Thermistor1) {
|
|||
|
||||
SensorResult t = tf.convert(2100);
|
||||
ASSERT_TRUE(t.Valid);
|
||||
ASSERT_FLOAT_EQ(75, t.Value);
|
||||
ASSERT_NEAR(75, t.Value, EPS2D);
|
||||
|
||||
ASSERT_NEAR(-0.003, tf.m_a, EPS4D);
|
||||
ASSERT_NEAR(0.001, tf.m_b, EPS4D);
|
||||
|
@ -83,7 +83,25 @@ TEST(Thermistor, Option2) {
|
|||
|
||||
|
||||
setAtSensor(&engineConfiguration->auxTempSensor1, /*temp low*/-13.9, 73300, /*temp mid*/23.5, 53100 , /*temp high*/ 60, 2280);
|
||||
initNewSensors();
|
||||
|
||||
EXPECT_FATAL_ERROR(
|
||||
initNewSensors()
|
||||
);
|
||||
|
||||
FunctionalSensor * aatSensor = (FunctionalSensor*)Sensor::getSensorOfType(SensorType::AuxTemp1);
|
||||
ASSERT_TRUE(aatSensor == nullptr);
|
||||
}
|
||||
|
||||
|
||||
TEST(Thermistor, Option3) {
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE, [](engine_configuration_s* engineConfiguration) {
|
||||
engineConfiguration->auxTempSensor1.adcChannel = EFI_ADC_12;; // arbitrary
|
||||
});
|
||||
|
||||
|
||||
setAtSensor(&engineConfiguration->auxTempSensor1, /*temp low*/-13.9, 73300, /*temp mid*/45, 3810, /*temp high*/ 90, 952);
|
||||
|
||||
initNewSensors();
|
||||
|
||||
FunctionalSensor * aatSensor = (FunctionalSensor*)Sensor::getSensorOfType(SensorType::AuxTemp1);
|
||||
ASSERT_TRUE(aatSensor != nullptr);
|
||||
|
@ -91,9 +109,8 @@ TEST(Thermistor, Option2) {
|
|||
|
||||
ThermistorFunc *thermistorFuncAat = tFuncAat->getPtr<ThermistorFunc>();
|
||||
|
||||
ASSERT_NEAR(60, thermistorFuncAat->convert(2280).Value, EPS2D);
|
||||
// WOW! how cool is this issue - resistance between mid and high temps gives us a temperature way above high point!
|
||||
// fun fact: java script version is not broken https://rusefi.com/Steinhart-Hart.html is this about loss of precision?
|
||||
ASSERT_NEAR(104.094, thermistorFuncAat->convert(3413).Value, EPS2D);
|
||||
ASSERT_NEAR(23.5, thermistorFuncAat->convert(53100).Value, EPS2D);
|
||||
ASSERT_NEAR(59.9064, thermistorFuncAat->convert(2280).Value, EPS2D);
|
||||
ASSERT_NEAR(48.043, thermistorFuncAat->convert(3413).Value, EPS2D);
|
||||
ASSERT_NEAR(-9.17, thermistorFuncAat->convert(53100).Value, EPS2D);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue