Test different approach for resistance calculation

This commit is contained in:
2024-09-19 21:34:24 +02:00
parent a548518b9c
commit 053ee1674d

View File

@@ -10,16 +10,19 @@
// TODO: Is resistance function semantically correct? // TODO: Is resistance function semantically correct?
// TODO: Check results for humidity conversion functions. // TODO: Check results for humidity conversion functions.
// Thermistor general constants
#define R1 10000.0f // Resistor ohm value
#define VRES 0xFFFF // 16-bit ADC resolution
// Thermistor coeficients // Thermistor coeficients
static const float SC1 = 1.009249522e-3f; #define SC1 1.009249522e-3f
static const float SC2 = 2.378405444e-4f; #define SC2 2.378405444e-4f
static const float SC3 = 2.019202697e-7f; #define SC3 2.019202697e-7f
static const float R1 = 10000.0f;
// Humidity conversion constants // Humidity conversion constants
static const float TH1 = 100.0f; #define TH1 100.0f
static const float TH2 = 243.04f; #define TH2 243.04f
static const float TH3 = 17.625f; #define TH3 17.625f
float Resistance(int adc_raw) float Resistance(int adc_raw)
{ {
@@ -30,10 +33,9 @@ float Resistance(int adc_raw)
// [GND] - [10K RESISTOR] - [ADC INPUT] - [THERMISTOR] - [VCC] // [GND] - [10K RESISTOR] - [ADC INPUT] - [THERMISTOR] - [VCC]
// return ((VRES - adc_raw) * R1) / adc_raw;
r2 = (float) adc_raw / 264.8f * 0.05f; r2 = (float) adc_raw / 264.8f * 0.05f;
// XXX: Ohms Law solved for resistance?
// R = V / I
return R1 / (5.0f / r2 - 1.0f); return R1 / (5.0f / r2 - 1.0f);
} }