NTC Thermistor Driver
API reference
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
NTC Namespace Reference

Namespaces

namespace  Constants
 
namespace  DefaultConfig
 Default NTC configuration constants.
 

Classes

struct  ntc_lookup_entry_t
 Lookup table entry structure. More...
 
struct  ntc_lookup_table_t
 Lookup table structure. More...
 

Functions

bool ConvertResistanceToTemperatureBeta (float resistance_ohms, float resistance_at_25c, float beta_value, float *temperature_celsius) noexcept
 Convert resistance to temperature using beta parameter.
 
bool ConvertTemperatureToResistanceBeta (float temperature_celsius, float resistance_at_25c, float beta_value, float *resistance_ohms) noexcept
 Convert temperature to resistance using beta parameter.
 
bool ConvertResistanceToTemperatureSteinhartHart (float resistance_ohms, float coeff_a, float coeff_b, float coeff_c, float *temperature_celsius) noexcept
 Convert resistance to temperature using Steinhart-Hart equation.
 
bool ConvertTemperatureToResistanceSteinhartHart (float temperature_celsius, float coeff_a, float coeff_b, float coeff_c, float *resistance_ohms) noexcept
 Convert temperature to resistance using Steinhart-Hart equation.
 
bool ConvertResistanceToTemperatureDefault (float resistance_ohms, float *temperature_celsius) noexcept
 Convert resistance to temperature using default Steinhart-Hart coefficients.
 
bool ConvertTemperatureToResistanceDefault (float temperature_celsius, float *resistance_ohms) noexcept
 Convert temperature to resistance using default Steinhart-Hart coefficients.
 
bool CalculateThermistorResistance (float voltage_thermistor, float reference_voltage, float series_resistance, float *resistance_ohms) noexcept
 Calculate thermistor resistance from voltage divider.
 
bool CalculateThermistorVoltage (float resistance_ohms, float reference_voltage, float series_resistance, float *voltage_thermistor) noexcept
 Calculate voltage across thermistor from resistance.
 
bool CalculateVoltageDividerRatio (float resistance_ohms, float series_resistance, float *ratio) noexcept
 Calculate voltage divider ratio.
 
bool ValidateResistance (float resistance_ohms, float min_resistance, float max_resistance) noexcept
 Validate resistance value.
 
bool ValidateTemperature (float temperature_celsius, float min_temperature, float max_temperature) noexcept
 Validate temperature value.
 
bool ValidateVoltage (float voltage_volts, float min_voltage, float max_voltage) noexcept
 Validate voltage value.
 
bool ValidateBetaValue (float beta_value) noexcept
 Validate beta value.
 
bool ValidateSteinhartHartCoefficients (float coeff_a, float coeff_b, float coeff_c) noexcept
 Validate Steinhart-Hart coefficients.
 
bool CalculateBetaValue (float temp1_celsius, float resistance1_ohms, float temp2_celsius, float resistance2_ohms, float *beta_value) noexcept
 Calculate beta value from two temperature-resistance pairs.
 
bool CalculateSteinhartHartCoefficients (float temp1_celsius, float resistance1_ohms, float temp2_celsius, float resistance2_ohms, float temp3_celsius, float resistance3_ohms, float *coeff_a, float *coeff_b, float *coeff_c) noexcept
 Calculate Steinhart-Hart coefficients from three temperature-resistance pairs.
 
bool CalculateTemperatureAccuracy (float resistance_ohms, float resistance_at_25c, float beta_value, float resistance_tolerance, float beta_tolerance, float *accuracy_celsius) noexcept
 Worst-case temperature error from the R25 and B tolerances.
 
bool CalculateTemperatureAccuracy (float resistance_ohms, float resistance_tolerance, float beta_tolerance, float *accuracy_celsius) noexcept
 Temperature error estimate for the default part (R25 = 10 kOhm, B = 3435 K)
 
bool CalculateOptimalSeriesResistance (float thermistor_resistance_at_25c, float beta_value, float min_temperature, float max_temperature, float *optimal_resistance) noexcept
 Calculate optimal series resistance for voltage divider.
 
bool CalculateOptimalSeriesResistance (float thermistor_resistance_at_25c, float min_temperature, float max_temperature, float *optimal_resistance) noexcept
 Optimal series resistance assuming B = 3435 K.
 
const ntc_lookup_table_t * GetNtcLookupTable (int ntc_type) noexcept
 Get lookup table for NTC type.
 
bool FindTemperatureFromLookupTable (const ntc_lookup_table_t *table, float resistance_ohms, float *temperature_celsius) noexcept
 Find temperature using lookup table.
 
bool FindResistanceFromLookupTable (const ntc_lookup_table_t *table, float temperature_celsius, float *resistance_ohms) noexcept
 Find resistance using lookup table.
 
bool InterpolateLookupEntries (const ntc_lookup_entry_t &entry1, const ntc_lookup_entry_t &entry2, float resistance_ohms, float *temperature_celsius) noexcept
 Interpolate between two lookup table entries.
 
bool BinarySearchLookupTable (const ntc_lookup_table_t *table, float resistance_ohms, size_t *lower_index, size_t *upper_index) noexcept
 Binary search in lookup table.
 
bool ValidateLookupTable (const ntc_lookup_table_t *table) noexcept
 Validate lookup table.
 
void GetLookupTableStats (const ntc_lookup_table_t *table, float *min_resistance, float *max_resistance, float *min_temperature, float *max_temperature, size_t *entry_count) noexcept
 Get lookup table statistics.
 
const ntc_lookup_table_t * GetNtcG163Jft103Ft1sLookupTable () noexcept
 Get NTCG163JFT103FT1S lookup table.
 
const ntc_lookup_table_t * GetNtcG164Jf103Ft1sLookupTable () noexcept
 Get NTCG164JF103FT1S lookup table.
 
const ntc_lookup_table_t * GetNtcG163Jf103Ft1sLookupTable () noexcept
 Get NTCG163JF103FT1S lookup table.
 

Function Documentation

◆ BinarySearchLookupTable()

bool NTC::BinarySearchLookupTable ( const ntc_lookup_table_t *  table,
float  resistance_ohms,
size_t *  lower_index,
size_t *  upper_index 
)
noexcept

Binary search in lookup table.

Parameters
tableLookup table
resistance_ohmsTarget resistance
lower_indexPointer to store lower index
upper_indexPointer to store upper index
Returns
true if found, false otherwise

◆ CalculateBetaValue()

bool NTC::CalculateBetaValue ( float  temp1_celsius,
float  resistance1_ohms,
float  temp2_celsius,
float  resistance2_ohms,
float *  beta_value 
)
noexcept

Calculate beta value from two temperature-resistance pairs.

Parameters
temp1_celsiusFirst temperature (°C)
resistance1_ohmsFirst resistance (ohms)
temp2_celsiusSecond temperature (°C)
resistance2_ohmsSecond resistance (ohms)
beta_valuePointer to store calculated beta value
Returns
true if successful, false otherwise

◆ CalculateOptimalSeriesResistance() [1/2]

bool NTC::CalculateOptimalSeriesResistance ( float  thermistor_resistance_at_25c,
float  beta_value,
float  min_temperature,
float  max_temperature,
float *  optimal_resistance 
)
noexcept

Calculate optimal series resistance for voltage divider.

The geometric mean of R at the two ends of the range, from the Beta equation with the given R25 and B.

Parameters
thermistor_resistance_at_25cThermistor resistance at 25°C (ohms)
beta_valueB (K), e.g. ntc_config_t::beta_value
min_temperatureMinimum temperature (°C)
max_temperatureMaximum temperature (°C)
optimal_resistancePointer to store optimal series resistance (ohms)
Returns
true if successful, false otherwise

◆ CalculateOptimalSeriesResistance() [2/2]

bool NTC::CalculateOptimalSeriesResistance ( float  thermistor_resistance_at_25c,
float  min_temperature,
float  max_temperature,
float *  optimal_resistance 
)
noexcept

Optimal series resistance assuming B = 3435 K.

Calculate optimal series resistance for voltage divider.

Deprecated:
Pass B: use the overload that takes beta_value.
Parameters
thermistor_resistance_at_25cThermistor resistance at 25°C (ohms)
min_temperatureMinimum temperature (°C)
max_temperatureMaximum temperature (°C)
optimal_resistancePointer to store optimal series resistance (ohms)
Returns
true if successful, false otherwise

◆ CalculateSteinhartHartCoefficients()

bool NTC::CalculateSteinhartHartCoefficients ( float  temp1_celsius,
float  resistance1_ohms,
float  temp2_celsius,
float  resistance2_ohms,
float  temp3_celsius,
float  resistance3_ohms,
float *  coeff_a,
float *  coeff_b,
float *  coeff_c 
)
noexcept

Calculate Steinhart-Hart coefficients from three temperature-resistance pairs.

Solves 1/T = A + B*ln(R) + C*ln(R)^3 through the three points (in double precision), so the returned equation passes through all three. Pick points across the range you need, e.g. -40, 25 and 125 C from the datasheet table.

Parameters
temp1_celsiusFirst temperature (°C)
resistance1_ohmsFirst resistance (ohms)
temp2_celsiusSecond temperature (°C)
resistance2_ohmsSecond resistance (ohms)
temp3_celsiusThird temperature (°C)
resistance3_ohmsThird resistance (ohms)
coeff_aPointer to store coefficient A
coeff_bPointer to store coefficient B
coeff_cPointer to store coefficient C
Returns
true if successful, false otherwise

◆ CalculateTemperatureAccuracy() [1/2]

bool NTC::CalculateTemperatureAccuracy ( float  resistance_ohms,
float  resistance_at_25c,
float  beta_value,
float  resistance_tolerance,
float  beta_tolerance,
float *  accuracy_celsius 
)
noexcept

Worst-case temperature error from the R25 and B tolerances.

Converts R to T with the Beta equation, then adds the two worst-case errors: R25 tolerance, T^2/B * tol_R, and B tolerance, |T * (1 - T/T25)| * tol_B. For the NTCG163JF103FT1S (R25 +/- 1 %, B25/85 +/- 1 %) this reproduces the spec sheet's Table 3 Min/Max band: 0.26 C at 25 C, 1.1 C at 85 C.

Parameters
resistance_ohmsThermistor resistance (ohms)
resistance_at_25cR25 (ohms), e.g. ntc_config_t::resistance_at_25c
beta_valueB (K), e.g. ntc_config_t::beta_value
resistance_toleranceR25 tolerance (fraction, 0.01 for 1 %)
beta_toleranceB tolerance (fraction)
accuracy_celsiusPointer to store the error bound (°C)
Returns
true if successful, false otherwise

◆ CalculateTemperatureAccuracy() [2/2]

bool NTC::CalculateTemperatureAccuracy ( float  resistance_ohms,
float  resistance_tolerance,
float  beta_tolerance,
float *  accuracy_celsius 
)
noexcept

Temperature error estimate for the default part (R25 = 10 kOhm, B = 3435 K)

Calculate temperature accuracy estimate.

Deprecated:
Pass R25 and B: use the six-argument overload.
Parameters
resistance_ohmsThermistor resistance (ohms)
resistance_toleranceResistance tolerance (fraction)
beta_toleranceBeta tolerance (fraction)
accuracy_celsiusPointer to store accuracy estimate (°C)
Returns
true if successful, false otherwise

◆ CalculateThermistorResistance()

bool NTC::CalculateThermistorResistance ( float  voltage_thermistor,
float  reference_voltage,
float  series_resistance,
float *  resistance_ohms 
)
noexcept

Calculate thermistor resistance from voltage divider.

Parameters
voltage_thermistorVoltage across thermistor (V)
reference_voltageReference voltage (V)
series_resistanceSeries resistance (ohms)
resistance_ohmsPointer to store thermistor resistance (ohms)
Returns
true if successful, false otherwise

◆ CalculateThermistorVoltage()

bool NTC::CalculateThermistorVoltage ( float  resistance_ohms,
float  reference_voltage,
float  series_resistance,
float *  voltage_thermistor 
)
noexcept

Calculate voltage across thermistor from resistance.

Parameters
resistance_ohmsThermistor resistance (ohms)
reference_voltageReference voltage (V)
series_resistanceSeries resistance (ohms)
voltage_thermistorPointer to store voltage across thermistor (V)
Returns
true if successful, false otherwise

◆ CalculateVoltageDividerRatio()

bool NTC::CalculateVoltageDividerRatio ( float  resistance_ohms,
float  series_resistance,
float *  ratio 
)
noexcept

Calculate voltage divider ratio.

Parameters
resistance_ohmsThermistor resistance (ohms)
series_resistanceSeries resistance (ohms)
ratioPointer to store voltage ratio
Returns
true if successful, false otherwise

◆ ConvertResistanceToTemperatureBeta()

bool NTC::ConvertResistanceToTemperatureBeta ( float  resistance_ohms,
float  resistance_at_25c,
float  beta_value,
float *  temperature_celsius 
)
noexcept

Convert resistance to temperature using beta parameter.

Uses the beta parameter equation to calculate temperature from resistance. This is a simplified model that assumes a linear relationship in the temperature-resistance curve around the reference temperature.

Note
The beta parameter method is faster but less accurate than Steinhart-Hart, especially at temperature extremes.
Parameters
resistance_ohmsThermistor resistance (ohms)
resistance_at_25cResistance at 25°C (ohms)
beta_valueBeta value (K), typically 3000-4000K for NTC thermistors
temperature_celsiusPointer to store temperature (°C)
Returns
true if successful, false otherwise
Warning
Input resistance must be positive and non-zero. Beta value should be within valid range (1000-5000K).

◆ ConvertResistanceToTemperatureDefault()

bool NTC::ConvertResistanceToTemperatureDefault ( float  resistance_ohms,
float *  temperature_celsius 
)
noexcept

Convert resistance to temperature using default Steinhart-Hart coefficients.

The defaults (STEINHART_HART_A_/B_/C_) are fitted to the TDK NTCG163JF103FT1S; use ConvertResistanceToTemperatureSteinhartHart() with your own coefficients for any other part.

Parameters
resistance_ohmsThermistor resistance (ohms)
temperature_celsiusPointer to store temperature (°C)
Returns
true if successful, false otherwise

◆ ConvertResistanceToTemperatureSteinhartHart()

bool NTC::ConvertResistanceToTemperatureSteinhartHart ( float  resistance_ohms,
float  coeff_a,
float  coeff_b,
float  coeff_c,
float *  temperature_celsius 
)
noexcept

Convert resistance to temperature using Steinhart-Hart equation.

Uses the Steinhart-Hart equation for high-accuracy temperature calculation. This method provides better accuracy across a wider temperature range compared to the beta parameter method.

The Steinhart-Hart equation: 1/T = A + B*ln(R) + C*ln(R)³

Note
This method is more computationally expensive but provides superior accuracy, especially at temperature extremes.
Parameters
resistance_ohmsThermistor resistance (ohms)
coeff_aSteinhart-Hart coefficient A (about 0.9e-3 for a 10 kOhm part)
coeff_bSteinhart-Hart coefficient B (about 2.5e-4)
coeff_cSteinhart-Hart coefficient C (about 1e-7 to 2e-7)
temperature_celsiusPointer to store temperature (°C)
Returns
true if successful, false otherwise
See also
ValidateSteinhartHartCoefficients() to validate coefficients

◆ ConvertTemperatureToResistanceBeta()

bool NTC::ConvertTemperatureToResistanceBeta ( float  temperature_celsius,
float  resistance_at_25c,
float  beta_value,
float *  resistance_ohms 
)
noexcept

Convert temperature to resistance using beta parameter.

Parameters
temperature_celsiusTemperature (°C)
resistance_at_25cResistance at 25°C (ohms)
beta_valueBeta value (K)
resistance_ohmsPointer to store resistance (ohms)
Returns
true if successful, false otherwise

◆ ConvertTemperatureToResistanceDefault()

bool NTC::ConvertTemperatureToResistanceDefault ( float  temperature_celsius,
float *  resistance_ohms 
)
noexcept

Convert temperature to resistance using default Steinhart-Hart coefficients.

Parameters
temperature_celsiusTemperature (°C)
resistance_ohmsPointer to store resistance (ohms)
Returns
true if successful, false otherwise

◆ ConvertTemperatureToResistanceSteinhartHart()

bool NTC::ConvertTemperatureToResistanceSteinhartHart ( float  temperature_celsius,
float  coeff_a,
float  coeff_b,
float  coeff_c,
float *  resistance_ohms 
)
noexcept

Convert temperature to resistance using Steinhart-Hart equation.

Solves C*x^3 + B*x + (A - 1/T) = 0 for x = ln(R) exactly (the C term included), so it is the inverse of ConvertResistanceToTemperatureSteinhartHart().

Parameters
temperature_celsiusTemperature (°C)
coeff_aSteinhart-Hart coefficient A
coeff_bSteinhart-Hart coefficient B
coeff_cSteinhart-Hart coefficient C
resistance_ohmsPointer to store resistance (ohms)
Returns
true if successful, false otherwise

◆ FindResistanceFromLookupTable()

bool NTC::FindResistanceFromLookupTable ( const ntc_lookup_table_t *  table,
float  temperature_celsius,
float *  resistance_ohms 
)
noexcept

Find resistance using lookup table.

Parameters
tableLookup table
temperature_celsiusTemperature value
resistance_ohmsPointer to store resistance
Returns
true if found, false otherwise

◆ FindTemperatureFromLookupTable()

bool NTC::FindTemperatureFromLookupTable ( const ntc_lookup_table_t *  table,
float  resistance_ohms,
float *  temperature_celsius 
)
noexcept

Find temperature using lookup table.

Parameters
tableLookup table
resistance_ohmsResistance value
temperature_celsiusPointer to store temperature
Returns
true if found, false otherwise

◆ GetLookupTableStats()

void NTC::GetLookupTableStats ( const ntc_lookup_table_t *  table,
float *  min_resistance,
float *  max_resistance,
float *  min_temperature,
float *  max_temperature,
size_t *  entry_count 
)
noexcept

Get lookup table statistics.

Parameters
tableLookup table
min_resistancePointer to store minimum resistance
max_resistancePointer to store maximum resistance
min_temperaturePointer to store minimum temperature
max_temperaturePointer to store maximum temperature
entry_countPointer to store entry count

◆ GetNtcG163Jf103Ft1sLookupTable()

const ntc_lookup_table_t * NTC::GetNtcG163Jf103Ft1sLookupTable ( )
noexcept

Get NTCG163JF103FT1S lookup table.

Returns
Pointer to lookup table

◆ GetNtcG163Jft103Ft1sLookupTable()

const ntc_lookup_table_t * NTC::GetNtcG163Jft103Ft1sLookupTable ( )
noexcept

Get NTCG163JFT103FT1S lookup table.

Returns
Pointer to lookup table

◆ GetNtcG164Jf103Ft1sLookupTable()

const ntc_lookup_table_t * NTC::GetNtcG164Jf103Ft1sLookupTable ( )
noexcept

Get NTCG164JF103FT1S lookup table.

Returns
Pointer to lookup table

◆ GetNtcLookupTable()

const ntc_lookup_table_t * NTC::GetNtcLookupTable ( int  ntc_type)
noexcept

Get lookup table for NTC type.

Retrieves the pre-calculated lookup table for a specific NTC thermistor type. Lookup tables are optimized for fast temperature conversion with minimal computational overhead.

Parameters
ntc_typeNTC thermistor type (e.g., NtcType::NtcG163Jf103Ft1S)
Returns
Pointer to lookup table (nullptr if not available for this type)
Note
Not all NTC types have pre-calculated lookup tables. Use NtcConversionMethod::Mathematical for unsupported types.

◆ InterpolateLookupEntries()

bool NTC::InterpolateLookupEntries ( const ntc_lookup_entry_t &  entry1,
const ntc_lookup_entry_t &  entry2,
float  resistance_ohms,
float *  temperature_celsius 
)
noexcept

Interpolate between two lookup table entries.

Parameters
entry1First entry
entry2Second entry
resistance_ohmsTarget resistance
temperature_celsiusPointer to store interpolated temperature
Returns
true if interpolation successful, false otherwise

◆ ValidateBetaValue()

bool NTC::ValidateBetaValue ( float  beta_value)
noexcept

Validate beta value.

Parameters
beta_valueBeta value to validate
Returns
true if valid, false otherwise

◆ ValidateLookupTable()

bool NTC::ValidateLookupTable ( const ntc_lookup_table_t *  table)
noexcept

Validate lookup table.

Parameters
tableLookup table to validate
Returns
true if valid, false otherwise

◆ ValidateResistance()

bool NTC::ValidateResistance ( float  resistance_ohms,
float  min_resistance,
float  max_resistance 
)
noexcept

Validate resistance value.

Parameters
resistance_ohmsResistance value to validate
min_resistanceMinimum valid resistance
max_resistanceMaximum valid resistance
Returns
true if valid, false otherwise

◆ ValidateSteinhartHartCoefficients()

bool NTC::ValidateSteinhartHartCoefficients ( float  coeff_a,
float  coeff_b,
float  coeff_c 
)
noexcept

Validate Steinhart-Hart coefficients.

Accepts finite coefficients with |A| <= 1e-2, 1e-4 <= B <= 1e-3 and |C| <= 1e-6, which covers NTC fits from about 1 kOhm to 1 MOhm (this part's C is 1.9e-7).

Parameters
coeff_aCoefficient A
coeff_bCoefficient B
coeff_cCoefficient C
Returns
true if valid, false otherwise

◆ ValidateTemperature()

bool NTC::ValidateTemperature ( float  temperature_celsius,
float  min_temperature,
float  max_temperature 
)
noexcept

Validate temperature value.

Parameters
temperature_celsiusTemperature value to validate
min_temperatureMinimum valid temperature
max_temperatureMaximum valid temperature
Returns
true if valid, false otherwise

◆ ValidateVoltage()

bool NTC::ValidateVoltage ( float  voltage_volts,
float  min_voltage,
float  max_voltage 
)
noexcept

Validate voltage value.

Parameters
voltage_voltsVoltage value to validate
min_voltageMinimum valid voltage
max_voltageMaximum valid voltage
Returns
true if valid, false otherwise