rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
ThermistorFunc Class Referencefinal

#include <thermistor_func.h>

Inheritance diagram for ThermistorFunc:
Inheritance graph
[legend]
Collaboration diagram for ThermistorFunc:
Collaboration graph
[legend]

Public Member Functions

SensorResult convert (float ohms) const override
 
void configure (thermistor_conf_s &cfg)
 
void showInfo (float testRawValue) const override
 
- Public Member Functions inherited from SensorConverter
 SensorConverter (const SensorConverter &)=delete
 
 SensorConverter ()=default
 

Data Fields

float m_a = 0
 
float m_b = 0
 
float m_c = 0
 

Detailed Description

Author
Matthew Kennedy, (c) 2019

A function to convert resistance to thermistor temperature (NTC). Uses the Steinhart-Hart equation to avoid having to compute many logarithms at runtime.

Definition at line 15 of file thermistor_func.h.

Member Function Documentation

◆ configure()

void ThermistorFunc::configure ( thermistor_conf_s cfg)

Definition at line 42 of file thermistor_func.cpp.

42 {
43 // https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
44 float l1 = logf(cfg.resistance_1);
45 float l2 = logf(cfg.resistance_2);
46 float l3 = logf(cfg.resistance_3);
47
48 float y1 = 1 / convertCelsiusToKelvin(cfg.tempC_1);
49 float y2 = 1 / convertCelsiusToKelvin(cfg.tempC_2);
50 float y3 = 1 / convertCelsiusToKelvin(cfg.tempC_3);
51
52 float u2 = (y2 - y1) / (l2 - l1);
53 float u3 = (y3 - y1) / (l3 - l1);
54
55 m_c = ((u3 - u2) / (l3 - l2)) / (l1 + l2 + l3);
56 m_b = u2 - m_c * (l1 * l1 + l1 * l2 + l2 * l2);
57 m_a = y1 - (m_b + l1 * l1 * m_c) * l1;
58
59 float resistance10percent = cfg.resistance_1 + 0.1 * (cfg.resistance_2 - cfg.resistance_1);
60 float tempAt10percentPoint = convert(resistance10percent).Value;
61
62 if (tempAt10percentPoint < cfg.tempC_1) {
63#if EFI_UNIT_TEST
64 throw std::logic_error("Bad thermistor configuration at the left");
65#endif
66 criticalError("Thermistor configuration has failed 10% test");
67 }
68
69 float resistance90percent = cfg.resistance_2 + 0.9 * (cfg.resistance_3 - cfg.resistance_2);
70 float tempAt90percentPoint = convert(resistance90percent).Value;
71 if (tempAt90percentPoint > cfg.tempC_3) {
72#if EFI_UNIT_TEST
73 throw std::logic_error("Bad thermistor configuration at the right");
74#endif
75 criticalError("Thermistor configuration has failed 90% test");
76 }
77}
SensorResult convert(float ohms) const override
Here is the call graph for this function:

◆ convert()

SensorResult ThermistorFunc::convert ( float  ohms) const
overridevirtual
Author
Matthew Kennedy, (c) 2019

Implements SensorConverter.

Definition at line 11 of file thermistor_func.cpp.

11 {
12 // This resistance should have already been validated - only
13 // thing we can check is that it's non-negative
14 if (ohms <= 0) {
15 return UnexpectedCode::Low;
16 }
17
18 float lnR = logf(ohms);
19
20 float lnR3 = lnR * lnR * lnR;
21
22 float recip = m_a + m_b * lnR + m_c * lnR3;
23
24 float kelvin = 1 / recip;
25
26 float celsius = convertKelvinToCelcius(kelvin);
27
28 // bounds check result - please don't try to run rusEfi when colder than -50C
29 // high end limit is required as this could be an oil temp sensor on an
30 // air cooled engine
31 if (celsius < -50) {
32 return UnexpectedCode::Low;
33 }
34
35 if (celsius > 250) {
36 return UnexpectedCode::High;
37 }
38
39 return celsius;
40}

Referenced by configure(), and showInfo().

Here is the caller graph for this function:

◆ showInfo()

void ThermistorFunc::showInfo ( float  testRawValue) const
overridevirtual

Reimplemented from SensorConverter.

Definition at line 98 of file sensor_info_printing.cpp.

98 {
99 const auto value = convert(testInputValue);
100 efiPrintf(" %.1f ohms -> valid: %s. %.1f deg C", testInputValue, boolToString(value.Valid), value.Value);
101}
const char * boolToString(bool value)
Definition efilib.cpp:19
Here is the call graph for this function:

Field Documentation

◆ m_a

float ThermistorFunc::m_a = 0

Definition at line 24 of file thermistor_func.h.

Referenced by configure(), and convert().

◆ m_b

float ThermistorFunc::m_b = 0

Definition at line 25 of file thermistor_func.h.

Referenced by configure(), and convert().

◆ m_c

float ThermistorFunc::m_c = 0

Definition at line 26 of file thermistor_func.h.

Referenced by configure(), and convert().


The documentation for this class was generated from the following files: