diff --git a/src/common/math.c b/src/common/math.c index a1743ab..e6a2a07 100644 --- a/src/common/math.c +++ b/src/common/math.c @@ -10,16 +10,19 @@ // TODO: Is resistance function semantically correct? // 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 -static const float SC1 = 1.009249522e-3f; -static const float SC2 = 2.378405444e-4f; -static const float SC3 = 2.019202697e-7f; -static const float R1 = 10000.0f; +#define SC1 1.009249522e-3f +#define SC2 2.378405444e-4f +#define SC3 2.019202697e-7f // Humidity conversion constants -static const float TH1 = 100.0f; -static const float TH2 = 243.04f; -static const float TH3 = 17.625f; +#define TH1 100.0f +#define TH2 243.04f +#define TH3 17.625f float Resistance(int adc_raw) { @@ -30,10 +33,9 @@ float Resistance(int adc_raw) // [GND] - [10K RESISTOR] - [ADC INPUT] - [THERMISTOR] - [VCC] + // return ((VRES - adc_raw) * R1) / adc_raw; r2 = (float) adc_raw / 264.8f * 0.05f; - // XXX: Ohms Law solved for resistance? - // R = V / I return R1 / (5.0f / r2 - 1.0f); }