make adc_ph formula more flexible

This commit is contained in:
barbudor 2022-01-04 16:33:35 +01:00
parent 3916709d5f
commit 27a08b456e
1 changed files with 7 additions and 7 deletions

View File

@ -338,13 +338,13 @@ float AdcGetPh(uint32_t idx) {
int adc = AdcRead(Adc[idx].pin, 2); int adc = AdcRead(Adc[idx].pin, 2);
float y1 = Adc[idx].param1 / ANALOG_PH_DECIMAL_MULTIPLIER; float y1 = (float)Adc[idx].param1 / ANALOG_PH_DECIMAL_MULTIPLIER;
uint32_t x1 = Adc[idx].param2; int32_t x1 = Adc[idx].param2;
float y2 = Adc[idx].param3 / ANALOG_PH_DECIMAL_MULTIPLIER; float y2 = (float)Adc[idx].param3 / ANALOG_PH_DECIMAL_MULTIPLIER;
uint32_t x2 = Adc[idx].param4; int32_t x2 = Adc[idx].param4;
float m = (y2 - y1) / (x2 - x1); float m = (y2 - y1) / (float)(x2 - x1);
float ph = m * (adc - x1) + y1; float ph = m * (float)(adc - x1) + y1;
char phLow_chr[6]; char phLow_chr[6];
@ -417,7 +417,7 @@ void AdcEverySecond(void) {
double Rt = (adc * Adc[idx].param1) / (ANALOG_RANGE * ANALOG_V33 - (double)adc); // Shelly param1 = 32000 (ANALOG_NTC_BRIDGE_RESISTANCE) double Rt = (adc * Adc[idx].param1) / (ANALOG_RANGE * ANALOG_V33 - (double)adc); // Shelly param1 = 32000 (ANALOG_NTC_BRIDGE_RESISTANCE)
#else #else
double Rt = (adc * Adc[idx].param1) / (ANALOG_RANGE - (double)adc); double Rt = (adc * Adc[idx].param1) / (ANALOG_RANGE - (double)adc);
#endif #endif
double BC = (double)Adc[idx].param3 / 10000; // Shelly param3 = 3350 (ANALOG_NTC_B_COEFFICIENT) double BC = (double)Adc[idx].param3 / 10000; // Shelly param3 = 3350 (ANALOG_NTC_B_COEFFICIENT)
double T = BC / (BC / ANALOG_T0 + TaylorLog(Rt / (double)Adc[idx].param2)); // Shelly param2 = 10000 (ANALOG_NTC_RESISTANCE) double T = BC / (BC / ANALOG_T0 + TaylorLog(Rt / (double)Adc[idx].param2)); // Shelly param2 = 10000 (ANALOG_NTC_RESISTANCE)
Adc[idx].temperature = ConvertTemp(TO_CELSIUS(T)); Adc[idx].temperature = ConvertTemp(TO_CELSIUS(T));