NTC Thermistor Driver
API reference
Loading...
Searching...
No Matches
ntc_thermistor.ipp
Go to the documentation of this file.
1
6#ifndef NTC_THERMISTOR_IMPL
7#define NTC_THERMISTOR_IMPL
8
9// When included from header, use relative path; when compiled directly, use
10// standard include
11#ifdef NTC_THERMISTOR_HEADER_INCLUDED
12#include "../inc/ntc_thermistor.hpp"
13#include "../inc/ntc_conversion.hpp"
14#include "../inc/ntc_lookup_table.hpp"
15#else
16#include "ntc_conversion.hpp"
17#include "ntc_lookup_table.hpp"
18#include "ntc_thermistor.hpp"
19#endif
20
21#include <algorithm>
22#include <cmath>
23#include <cstring>
24
31
32//--------------------------------------
33// CONSTRUCTORS AND DESTRUCTOR
34//--------------------------------------
35
36template <typename AdcType>
38 AdcType *adc_interface) noexcept
39 : config_(), adc_interface_(adc_interface), initialized_(false),
40 filtered_temperature_(ZERO_FLOAT_), filter_initialized_(false) {
41
42 // Initialize configuration for NTC type
43 initializeConfigForType(ntc_type, &config_);
44}
45
46template <typename AdcType>
48 AdcType *adc_interface) noexcept
49 : config_(config), adc_interface_(adc_interface), initialized_(false),
50 filtered_temperature_(ZERO_FLOAT_), filter_initialized_(false) {}
51
52//--------------------------------------
53// INITIALIZATION AND CONFIGURATION
54//--------------------------------------
55
56template <typename AdcType> bool NtcThermistor<AdcType>::Initialize() noexcept {
57 if (initialized_) {
58 return true;
59 }
60
61 // Validate configuration
62 NtcError validation_error = validateConfiguration(config_);
63 if (validation_error != NtcError::Success) {
64 return false;
65 }
66
67 // Validate ADC interface
68 if (adc_interface_ == nullptr) {
69 return false;
70 }
71
72 // Initialize ADC interface if needed
73 if (!adc_interface_->IsInitialized()) {
74 if (!adc_interface_->EnsureInitialized()) {
75 return false;
76 }
77 }
78
79 // Validate ADC channel
80 if (!adc_interface_->IsChannelAvailable(config_.adc_channel)) {
81 return false;
82 }
83
84 // Reset filter
85 filter_initialized_ = false;
86 filtered_temperature_ = ZERO_FLOAT_;
87
88 initialized_ = true;
89 return true;
90}
91
92template <typename AdcType>
94 if (!initialized_) {
95 return true;
96 }
97
98 initialized_ = false;
99 filter_initialized_ = false;
100 filtered_temperature_ = ZERO_FLOAT_;
101
102 return true;
103}
104
105template <typename AdcType>
107 return initialized_;
108}
109
110template <typename AdcType>
113 if (config == nullptr) {
115 }
116
117 *config = config_;
118 return NtcError::Success;
119}
120
121template <typename AdcType>
124 // Validate new configuration
125 NtcError validation_error = validateConfiguration(config);
126 if (validation_error != NtcError::Success) {
127 return validation_error;
128 }
129
130 config_ = config;
131
132 // Reset filter when configuration changes
133 filter_initialized_ = false;
134 filtered_temperature_ = ZERO_FLOAT_;
135
136 return NtcError::Success;
137}
138
139//--------------------------------------
140// TEMPERATURE READING
141//--------------------------------------
142
143template <typename AdcType>
145 float *temperature_celsius) noexcept {
146 if (temperature_celsius == nullptr) {
148 }
149
150 if (!initialized_) {
152 }
153
154 // Read voltage from ADC
155 float voltage_volts = 0.0F;
156 NtcError voltage_error = readAdcVoltage(&voltage_volts);
157 if (voltage_error != NtcError::Success) {
158 return voltage_error;
159 }
160
161 // Calculate resistance
162 float resistance_ohms = 0.0F;
163 NtcError resistance_error =
164 calculateResistance(voltage_volts, &resistance_ohms);
165 if (resistance_error != NtcError::Success) {
166 return resistance_error;
167 }
168
169 // Convert resistance to temperature
170 float raw_temperature = 0.0F;
171 NtcError conversion_error =
172 convertResistanceToTemperature(resistance_ohms, &raw_temperature);
173 if (conversion_error != NtcError::Success) {
174 return conversion_error;
175 }
176
177 // Apply calibration offset
178 *temperature_celsius = raw_temperature + config_.calibration_offset;
179
180 // Apply filtering if enabled
181 if (config_.enable_filtering) {
182 *temperature_celsius = applyFiltering(*temperature_celsius);
183 }
184
185 // Validate temperature range
186 if (!NTC::ValidateTemperature(*temperature_celsius, config_.min_temperature,
187 config_.max_temperature)) {
189 }
190
191 return NtcError::Success;
192}
193
194template <typename AdcType>
196 float *temperature_fahrenheit) noexcept {
197 if (temperature_fahrenheit == nullptr) {
199 }
200
201 float celsius = 0.0F;
202 NtcError error = ReadTemperatureCelsius(&celsius);
203 if (error == NtcError::Success) {
204 *temperature_fahrenheit = CelsiusToFahrenheit(celsius);
205 }
206 return error;
207}
208
209template <typename AdcType>
211 float *temperature_kelvin) noexcept {
212 if (temperature_kelvin == nullptr) {
214 }
215
216 float celsius = 0.0F;
217 NtcError error = ReadTemperatureCelsius(&celsius);
218 if (error == NtcError::Success) {
219 *temperature_kelvin = CelsiusToKelvin(celsius);
220 }
221 return error;
222}
223
224template <typename AdcType>
227 if (reading == nullptr) {
229 }
230
231 // Initialize reading structure
232 reading->error = NtcError::Success;
233 reading->is_valid = false;
234 reading->timestamp_us = 0; // Implementer should provide timestamp
235 reading->accuracy_celsius = 0.5F; // Estimate based on typical NTC accuracy
236
237 // Read temperature
238 float temperature_celsius = 0.0F;
239 NtcError error = ReadTemperatureCelsius(&temperature_celsius);
240
241 if (error == NtcError::Success) {
242 // Get additional data
243 float resistance_ohms = 0.0F;
244 GetResistance(&resistance_ohms);
245
246 float voltage_volts = 0.0F;
247 GetVoltage(&voltage_volts);
248
249 uint32_t adc_raw = 0U;
250 GetRawAdcValue(&adc_raw);
251
252 // Fill reading structure
253 reading->temperature_celsius = temperature_celsius;
254 reading->temperature_fahrenheit = CelsiusToFahrenheit(temperature_celsius);
255 reading->temperature_kelvin = CelsiusToKelvin(temperature_celsius);
256 reading->resistance_ohms = resistance_ohms;
257 reading->voltage_volts = voltage_volts;
258 reading->adc_raw_value = adc_raw;
259 reading->is_valid = true;
260 }
261
262 reading->error = error;
263 return error;
264}
265
266//--------------------------------------
267// RESISTANCE AND VOLTAGE
268//--------------------------------------
269
270template <typename AdcType>
272NtcThermistor<AdcType>::GetResistance(float *resistance_ohms) noexcept {
273 if (resistance_ohms == nullptr) {
275 }
276
277 if (!initialized_) {
279 }
280
281 float voltage_volts = 0.0F;
282 NtcError voltage_error = readAdcVoltage(&voltage_volts);
283 if (voltage_error != NtcError::Success) {
284 return voltage_error;
285 }
286
287 return calculateResistance(voltage_volts, resistance_ohms);
288}
289
290template <typename AdcType>
291NtcError NtcThermistor<AdcType>::GetVoltage(float *voltage_volts) noexcept {
292 if (voltage_volts == nullptr) {
294 }
295
296 if (!initialized_) {
298 }
299
300 return readAdcVoltage(voltage_volts);
301}
302
303template <typename AdcType>
305 if (adc_value == nullptr) {
307 }
308
309 if (!initialized_) {
311 }
312
313 if (adc_interface_ == nullptr) {
315 }
316
317 // Convert AdcError to NtcError helper
318 auto convert_error = [](ntc::AdcError err) -> NtcError {
319 switch (err) {
321 return NtcError::Success;
329 return NtcError::Timeout;
332 default:
334 }
335 };
336
337 // Perform sampling if configured
338 if (config_.sample_count > 1) {
339 uint64_t sum = 0;
340 uint32_t successful_samples = 0;
341
342 for (uint32_t i = 0; i < config_.sample_count; ++i) {
343 uint32_t sample_value = 0;
344 ntc::AdcError err =
345 adc_interface_->ReadChannelCount(config_.adc_channel, &sample_value);
346 if (err == ntc::AdcError::Success) {
347 sum += sample_value;
348 successful_samples++;
349 }
350
351 if (i + 1 < config_.sample_count) {
352 delayBetweenSamples();
353 }
354 }
355
356 if (successful_samples == 0) {
358 }
359
360 *adc_value = static_cast<uint32_t>(sum / successful_samples);
361 return NtcError::Success;
362 }
363 // Single sample
364 {
365 uint32_t sample_value = 0;
366 ntc::AdcError err =
367 adc_interface_->ReadChannelCount(config_.adc_channel, &sample_value);
368 if (err != ntc::AdcError::Success) {
369 return convert_error(err);
370 }
371 *adc_value = sample_value;
372 return NtcError::Success;
373 }
374}
375
376//--------------------------------------
377// CALIBRATION
378//--------------------------------------
379
380template <typename AdcType>
382 float reference_temperature_celsius) noexcept {
383 if (!initialized_) {
385 }
386
387 // Read current temperature
388 float current_temperature = 0.0F;
389 NtcError read_error = ReadTemperatureCelsius(&current_temperature);
390 if (read_error != NtcError::Success) {
391 return read_error;
392 }
393
394 // The reading already includes the current offset, so add the remaining
395 // error to it rather than replacing it.
396 config_.calibration_offset +=
397 reference_temperature_celsius - current_temperature;
398
399 return NtcError::Success;
400}
401
402template <typename AdcType>
404NtcThermistor<AdcType>::SetCalibrationOffset(float offset_celsius) noexcept {
405 config_.calibration_offset = offset_celsius;
406 return NtcError::Success;
407}
408
409template <typename AdcType>
411 float *offset_celsius) const noexcept {
412 if (offset_celsius == nullptr) {
414 }
415
416 *offset_celsius = config_.calibration_offset;
417 return NtcError::Success;
418}
419
420template <typename AdcType>
422 return SetCalibrationOffset(ZERO_FLOAT_);
423}
424
425//--------------------------------------
426// CONFIGURATION METHODS
427//--------------------------------------
428
429template <typename AdcType>
431 NtcConversionMethod method) noexcept {
432 config_.conversion_method = method;
433 return NtcError::Success;
434}
435
436template <typename AdcType>
438NtcThermistor<AdcType>::SetVoltageDivider(float series_resistance) noexcept {
439 if (series_resistance <= ZERO_FLOAT_) {
441 }
442
443 config_.series_resistance = series_resistance;
444 return NtcError::Success;
445}
446
447template <typename AdcType>
449NtcThermistor<AdcType>::SetReferenceVoltage(float reference_voltage) noexcept {
450 if (reference_voltage <= ZERO_FLOAT_) {
452 }
453
454 config_.reference_voltage = reference_voltage;
455 return NtcError::Success;
456}
457
458template <typename AdcType>
460 if (!NTC::ValidateBetaValue(beta_value)) {
462 }
463
464 config_.beta_value = beta_value;
465 return NtcError::Success;
466}
467
468template <typename AdcType>
469NtcError NtcThermistor<AdcType>::SetAdcChannel(uint8_t adc_channel) noexcept {
470 if (adc_interface_ != nullptr &&
471 !adc_interface_->IsChannelAvailable(adc_channel)) {
473 }
474
475 config_.adc_channel = adc_channel;
476 return NtcError::Success;
477}
478
479template <typename AdcType>
481 uint32_t sample_count, uint32_t sample_delay_ms) noexcept {
482 if (sample_count == 0) {
484 }
485
486 config_.sample_count = sample_count;
487 config_.sample_delay_ms = sample_delay_ms;
488 return NtcError::Success;
489}
490
491template <typename AdcType>
493 float alpha) noexcept {
494 constexpr float MIN_FILTER_ALPHA_ = 0.0F;
495 constexpr float MAX_FILTER_ALPHA_ = 1.0F;
496 if (alpha < MIN_FILTER_ALPHA_ || alpha > MAX_FILTER_ALPHA_) {
498 }
499
500 config_.enable_filtering = enable;
501 config_.filter_alpha = alpha;
502
503 // Reset filter when changing settings
504 filter_initialized_ = false;
505 filtered_temperature_ = ZERO_FLOAT_;
506
507 return NtcError::Success;
508}
509
510//--------------------------------------
511// UTILITY FUNCTIONS
512//--------------------------------------
513
514template <typename AdcType>
515float NtcThermistor<AdcType>::CelsiusToFahrenheit(float celsius) noexcept {
516 return (celsius * CELSIUS_TO_FAHRENHEIT_MULTIPLIER_) + FAHRENHEIT_OFFSET_;
517}
518
519template <typename AdcType>
520float NtcThermistor<AdcType>::FahrenheitToCelsius(float fahrenheit) noexcept {
521 return (fahrenheit - FAHRENHEIT_OFFSET_) * FAHRENHEIT_TO_CELSIUS_MULTIPLIER_;
522}
523
524template <typename AdcType>
525float NtcThermistor<AdcType>::CelsiusToKelvin(float celsius) noexcept {
526 return celsius + KELVIN_OFFSET_;
527}
528
529template <typename AdcType>
530float NtcThermistor<AdcType>::KelvinToCelsius(float kelvin) noexcept {
531 return kelvin - KELVIN_OFFSET_;
532}
533
534template <typename AdcType>
536 switch (error) {
538 return "Success";
540 return "General failure";
542 return "Not initialized";
544 return "Already initialized";
546 return "Invalid parameter";
548 return "Null pointer";
550 return "Out of memory";
552 return "ADC read failed";
554 return "Invalid resistance value";
556 return "Temperature out of range";
558 return "Lookup table error";
560 return "Temperature conversion failed";
562 return "Calibration failed";
564 return "Operation not supported";
566 return "Operation timeout";
568 return "Hardware fault";
569 default:
570 return "Unknown error";
571 }
572}
573
574template <typename AdcType>
576 switch (type) {
577 case NtcType::Unknown:
578 return "Unknown";
580 return "NTCG163JFT103FT1S";
582 return "NTCG164JF103FT1S";
584 return "NTCG163JF103FT1S";
585 case NtcType::Custom:
586 return "Custom";
587 default:
588 return "Invalid";
589 }
590}
591
592//--------------------------------------
593// PRIVATE HELPER METHODS
594//--------------------------------------
595
596template <typename AdcType>
598 const ntc_config_t &config) const noexcept {
599 if (config.resistance_at_25c <= ZERO_FLOAT_) {
601 }
602
603 if (!NTC::ValidateBetaValue(config.beta_value)) {
605 }
606
607 if (config.reference_voltage <= ZERO_FLOAT_) {
609 }
610
611 if (config.series_resistance <= ZERO_FLOAT_) {
613 }
614
615 if (config.sample_count == 0) {
617 }
618
619 if (config.min_temperature >= config.max_temperature) {
621 }
622
623 constexpr float MIN_FILTER_ALPHA_ = 0.0F;
624 constexpr float MAX_FILTER_ALPHA_ = 1.0F;
625 if (config.enable_filtering && (config.filter_alpha < MIN_FILTER_ALPHA_ ||
626 config.filter_alpha > MAX_FILTER_ALPHA_)) {
628 }
629
630 return NtcError::Success;
631}
632
633template <typename AdcType>
634NtcError NtcThermistor<AdcType>::readAdcVoltage(float *voltage_volts) noexcept {
635 if (voltage_volts == nullptr) {
637 }
638
639 if (adc_interface_ == nullptr) {
641 }
642
643 // Convert AdcError to NtcError helper
644 auto convert_error = [](ntc::AdcError err) -> NtcError {
645 switch (err) {
647 return NtcError::Success;
655 return NtcError::Timeout;
658 default:
660 }
661 };
662
663 // Perform sampling if configured
664 if (config_.sample_count > 1) {
665 float sum = ZERO_FLOAT_;
666 uint32_t successful_samples = 0;
667
668 for (uint32_t i = 0; i < config_.sample_count; ++i) {
669 float sample_voltage = ZERO_FLOAT_;
670 ntc::AdcError err =
671 adc_interface_->ReadChannelV(config_.adc_channel, &sample_voltage);
672 if (err == ntc::AdcError::Success) {
673 sum += sample_voltage;
674 successful_samples++;
675 }
676
677 if (i + 1 < config_.sample_count) {
678 delayBetweenSamples();
679 }
680 }
681
682 if (successful_samples == 0) {
684 }
685
686 *voltage_volts = sum / static_cast<float>(successful_samples);
687 return NtcError::Success;
688 } // Single sample
689 float sample_voltage = 0.0F;
690 ntc::AdcError err =
691 adc_interface_->ReadChannelV(config_.adc_channel, &sample_voltage);
692 if (err != ntc::AdcError::Success) {
693 return convert_error(err);
694 }
695 *voltage_volts = sample_voltage;
696 return NtcError::Success;
697}
698
699template <typename AdcType>
702 float *resistance_ohms) noexcept {
703 if (resistance_ohms == nullptr) {
705 }
706
708 voltage_volts, config_.reference_voltage, config_.series_resistance,
709 resistance_ohms)) {
711 }
712
713 return NtcError::Success;
714}
715
716template <typename AdcType>
718 float resistance_ohms, float *temperature_celsius) noexcept {
719 if (temperature_celsius == nullptr) {
721 }
722
723 // Choose conversion method
724 switch (config_.conversion_method) {
726 const NTC::ntc_lookup_table_t *table =
727 NTC::GetNtcLookupTable(static_cast<int>(config_.type));
728 if (table != nullptr && FindTemperatureFromLookupTable(
729 table, resistance_ohms, temperature_celsius)) {
730 return NtcError::Success;
731 }
732 // Fall back to mathematical conversion if lookup fails
733 break;
734 }
735
738 default:
739 break;
740 }
741
742 // Use mathematical conversion (beta parameter)
744 resistance_ohms, config_.resistance_at_25c, config_.beta_value,
745 temperature_celsius)) {
747 }
748
749 return NtcError::Success;
750}
751
752template <typename AdcType>
754 if (config_.sample_delay_ms == 0U || adc_interface_ == nullptr) {
755 return;
756 }
757 // Optional port hook, detected at compile time: an RTOS sleep or a timed
758 // wait. Without it the samples are taken back to back.
759 if constexpr (requires(AdcType &adc, uint32_t ms) { adc.DelayMs(ms); }) {
760 adc_interface_->DelayMs(config_.sample_delay_ms);
761 }
762}
763
764template <typename AdcType>
765float NtcThermistor<AdcType>::applyFiltering(float new_temperature) noexcept {
766 if (!config_.enable_filtering) {
767 return new_temperature;
768 }
769
770 if (!filter_initialized_) {
771 filtered_temperature_ = new_temperature;
772 filter_initialized_ = true;
773 return new_temperature;
774 }
775
776 // Apply exponential moving average
777 filtered_temperature_ =
778 (config_.filter_alpha * new_temperature) +
779 ((ONE_FLOAT_ - config_.filter_alpha) * filtered_temperature_);
780
781 return filtered_temperature_;
782}
783
784template <typename AdcType>
786 NtcType ntc_type, ntc_config_t *config) noexcept {
787 if (config == nullptr) {
788 return;
789 }
790
791 // Set default values
792 *config = GetDefaultNtcConfig();
793 config->type = ntc_type;
794
795 // Set type-specific values
796 switch (ntc_type) {
800 config->resistance_at_25c = NTC::DefaultConfig::DEFAULT_RESISTANCE_AT_25C_;
801 config->beta_value = NTC::DefaultConfig::DEFAULT_BETA_VALUE_;
802 break;
803 }
804
805 case NtcType::Custom:
806 case NtcType::Unknown:
807 default:
808 // Use default values from GetDefaultNtcConfig()
809 break;
810 }
811}
812
813#endif // NTC_THERMISTOR_IMPL
Hardware-agnostic NTC thermistor driver.
Definition ntc_thermistor.hpp:75
NtcError SetVoltageDivider(float series_resistance) noexcept
Set voltage divider parameters.
Definition ntc_thermistor.ipp:438
NtcError SetBetaValue(float beta_value) noexcept
Set beta value.
Definition ntc_thermistor.ipp:459
NtcError GetVoltage(float *voltage_volts) noexcept
Get voltage across thermistor.
Definition ntc_thermistor.ipp:291
NtcError SetFiltering(bool enable, float alpha=0.1F) noexcept
Enable/disable filtering.
Definition ntc_thermistor.ipp:492
NtcError SetSamplingParameters(uint32_t sample_count, uint32_t sample_delay_ms) noexcept
Set sampling parameters.
Definition ntc_thermistor.ipp:480
NtcError ReadTemperatureCelsius(float *temperature_celsius) noexcept
Read temperature in Celsius.
Definition ntc_thermistor.ipp:144
static float FahrenheitToCelsius(float fahrenheit) noexcept
Convert Fahrenheit to Celsius.
Definition ntc_thermistor.ipp:520
NtcError SetConfiguration(const ntc_config_t &config) noexcept
Set configuration.
Definition ntc_thermistor.ipp:123
NtcError SetReferenceVoltage(float reference_voltage) noexcept
Set reference voltage.
Definition ntc_thermistor.ipp:449
static float CelsiusToKelvin(float celsius) noexcept
Convert Celsius to Kelvin.
Definition ntc_thermistor.ipp:525
NtcError SetConversionMethod(NtcConversionMethod method) noexcept
Set conversion method.
Definition ntc_thermistor.ipp:430
static const char * GetTypeString(NtcType type) noexcept
Get NTC type string.
Definition ntc_thermistor.ipp:575
NtcError ReadTemperatureFahrenheit(float *temperature_fahrenheit) noexcept
Read temperature in Fahrenheit.
Definition ntc_thermistor.ipp:195
NtcError SetCalibrationOffset(float offset_celsius) noexcept
Set calibration offset.
Definition ntc_thermistor.ipp:404
NtcError GetCalibrationOffset(float *offset_celsius) const noexcept
Get calibration offset.
Definition ntc_thermistor.ipp:410
NtcError GetResistance(float *resistance_ohms) noexcept
Get thermistor resistance.
Definition ntc_thermistor.ipp:272
static float KelvinToCelsius(float kelvin) noexcept
Convert Kelvin to Celsius.
Definition ntc_thermistor.ipp:530
NtcError ReadTemperature(ntc_reading_t *reading) noexcept
Read complete temperature information.
Definition ntc_thermistor.ipp:226
bool IsInitialized() const noexcept
Check if initialized.
Definition ntc_thermistor.ipp:106
NtcError GetConfiguration(ntc_config_t *config) const noexcept
Get current configuration.
Definition ntc_thermistor.ipp:112
static const char * GetErrorString(NtcError error) noexcept
Get error string.
Definition ntc_thermistor.ipp:535
NtcError SetAdcChannel(uint8_t adc_channel) noexcept
Set ADC channel.
Definition ntc_thermistor.ipp:469
static float CelsiusToFahrenheit(float celsius) noexcept
Convert Celsius to Fahrenheit.
Definition ntc_thermistor.ipp:515
NtcThermistor(NtcType ntc_type, AdcType *adc_interface) noexcept
Constructor with NTC type and ADC interface.
Definition ntc_thermistor.ipp:37
bool Initialize() noexcept
Initialize the NTC thermistor driver.
Definition ntc_thermistor.ipp:56
NtcError GetRawAdcValue(uint32_t *adc_value) noexcept
Get raw ADC value.
Definition ntc_thermistor.ipp:304
NtcError ReadTemperatureKelvin(float *temperature_kelvin) noexcept
Read temperature in Kelvin.
Definition ntc_thermistor.ipp:210
NtcError ResetCalibration() noexcept
Reset calibration.
Definition ntc_thermistor.ipp:421
bool Deinitialize() noexcept
Deinitialize the NTC thermistor driver.
Definition ntc_thermistor.ipp:93
NtcError Calibrate(float reference_temperature_celsius) noexcept
Calibrate the thermistor.
Definition ntc_thermistor.ipp:381
constexpr float CELSIUS_TO_FAHRENHEIT_MULTIPLIER_
Celsius to Fahrenheit multiplier.
Definition ntc_conversion.hpp:54
constexpr float ZERO_FLOAT_
Zero as float.
Definition ntc_conversion.hpp:47
constexpr float FAHRENHEIT_TO_CELSIUS_MULTIPLIER_
Fahrenheit to Celsius multiplier.
Definition ntc_conversion.hpp:57
constexpr float FAHRENHEIT_OFFSET_
Fahrenheit offset.
Definition ntc_conversion.hpp:56
constexpr float ONE_FLOAT_
One as float.
Definition ntc_conversion.hpp:46
constexpr float KELVIN_OFFSET_
Celsius to Kelvin conversion offset.
Definition ntc_conversion.hpp:16
constexpr float DEFAULT_BETA_VALUE_
Default beta value (3435K)
Definition ntc_types.hpp:159
constexpr float DEFAULT_RESISTANCE_AT_25C_
Default resistance at 25°C (10kΩ)
Definition ntc_types.hpp:157
bool FindTemperatureFromLookupTable(const ntc_lookup_table_t *table, float resistance_ohms, float *temperature_celsius) noexcept
Find temperature using lookup table.
Definition ntc_lookup_table.cpp:128
bool ConvertResistanceToTemperatureBeta(float resistance_ohms, float resistance_at_25c, float beta_value, float *temperature_celsius) noexcept
Convert resistance to temperature using beta parameter.
Definition ntc_conversion.cpp:27
bool CalculateThermistorResistance(float voltage_thermistor, float reference_voltage, float series_resistance, float *resistance_ohms) noexcept
Calculate thermistor resistance from voltage divider.
Definition ntc_conversion.cpp:221
bool ValidateTemperature(float temperature_celsius, float min_temperature, float max_temperature) noexcept
Validate temperature value.
Definition ntc_conversion.cpp:318
bool ValidateBetaValue(float beta_value) noexcept
Validate beta value.
Definition ntc_conversion.cpp:329
const ntc_lookup_table_t * GetNtcLookupTable(int ntc_type) noexcept
Get lookup table for NTC type.
Definition ntc_lookup_table.cpp:115
AdcError
ADC error codes.
Definition ntc_adc_interface.hpp:14
@ HardwareError
Hardware-level error.
@ Success
Operation successful.
@ ReadFailed
ADC read operation failed.
@ InvalidChannel
Invalid ADC channel.
@ NotInitialized
ADC not initialized.
@ Timeout
Operation timeout.
Mathematical conversion functions for NTC thermistor temperature.
Lookup table implementation for NTC thermistor temperature conversion.
Hardware-agnostic NTC thermistor driver for temperature measurement.
NtcError
NTC thermistor error codes.
Definition ntc_types.hpp:24
@ TemperatureOutOfRange
Temperature out of range.
@ NullPointer
Null pointer.
@ LookupTableError
Lookup table error.
@ Success
Operation successful.
@ HardwareFault
Hardware fault.
@ AdcReadFailed
ADC read failed.
@ InvalidParameter
Invalid parameter.
@ InvalidResistance
Invalid resistance value.
@ NotInitialized
Not initialized.
@ AlreadyInitialized
Already initialized.
@ OutOfMemory
Out of memory.
@ CalibrationFailed
Calibration failed.
@ Timeout
Operation timeout.
@ Failure
General failure.
@ UnsupportedOperation
Operation not supported.
@ ConversionFailed
Temperature conversion failed.
constexpr ntc_config_t GetDefaultNtcConfig() noexcept
Default NTC configuration.
Definition ntc_types.hpp:224
NtcConversionMethod
Temperature conversion methods.
Definition ntc_types.hpp:82
@ Auto
Auto-select based on accuracy requirements.
@ Mathematical
Use mathematical conversion (slower, more accurate)
@ LookupTable
Use lookup table (faster, less accurate)
NtcType
NTC thermistor types.
Definition ntc_types.hpp:58
@ NtcG163Jft103Ft1S
NTCG163JFT103FT1S (10kΩ @ 25°C, β=3435K)
@ NtcG164Jf103Ft1S
NTCG164JF103FT1S (10kΩ @ 25°C, β=3435K)
@ NtcG163Jf103Ft1S
NTCG163JF103FT1S (10kΩ @ 25°C, β=3435K)
@ Unknown
Unknown type.
@ Custom
Custom NTC type.
Lookup table structure.
Definition ntc_lookup_table.hpp:31
NTC thermistor configuration structure.
Definition ntc_types.hpp:107
NTC thermistor reading structure.
Definition ntc_types.hpp:136