refactor pow to constant

This commit is contained in:
barbudor 2022-08-22 14:32:08 +02:00
parent 1bbec84f24
commit 4d7f78e06e
1 changed files with 7 additions and 7 deletions

View File

@ -112,7 +112,7 @@
#define ANALOG_PH_DECIMAL_MULTIPLIER 100.0 #define ANALOG_PH_DECIMAL_MULTIPLIER 100.0
// MQ-X sensor (MQ-02, MQ-03, MQ-04, MQ-05, MQ-06, MQ-07, MQ-08, MQ-09, MQ-131, MQ-135) // MQ-X sensor (MQ-02, MQ-03, MQ-04, MQ-05, MQ-06, MQ-07, MQ-08, MQ-09, MQ-131, MQ-135)
// //
// A0 ------------------- // A0 -------------------
// | // |
// GND ----------- | // GND ----------- |
@ -121,7 +121,7 @@
// | | | // | | |
// 3V3 GND ADC <- (A0 for nodemcu, wemos; GPIO34,35,36,39 and other analog IN/OUT pin for esp32) // 3V3 GND ADC <- (A0 for nodemcu, wemos; GPIO34,35,36,39 and other analog IN/OUT pin for esp32)
//means mq type (ex for mq-02 use 2, mq-131 use 131) //means mq type (ex for mq-02 use 2, mq-131 use 131)
#define ANALOG_MQ_TYPE 2 #define ANALOG_MQ_TYPE 2
//exponential regression a params //exponential regression a params
#define ANALOG_MQ_A 574.25 #define ANALOG_MQ_A 574.25
//exponential regression b params //exponential regression b params
@ -134,13 +134,13 @@
CO | 521853 | -3.821 CO | 521853 | -3.821
Alcohol| 0.3934 | -1.504 Alcohol| 0.3934 | -1.504
Benzene| 4.8387 | -2.68 Benzene| 4.8387 | -2.68
Hexane | 7585.3 | -2.849 Hexane | 7585.3 | -2.849
NOx | -462.43 | -2.204 NOx | -462.43 | -2.204
CL2 | 47.209 | -1.186 CL2 | 47.209 | -1.186
O3 | 23.943 | -1.11 O3 | 23.943 | -1.11
*/ */
//ratio for alarm, NOT USED yet (RS / R0 = 15 ppm) //ratio for alarm, NOT USED yet (RS / R0 = 15 ppm)
#define ANALOG_MQ_RatioMQCleanAir 15.0 #define ANALOG_MQ_RatioMQCleanAir 15.0
// Multiplier used to store pH with 2 decimal places in a non decimal datatype // Multiplier used to store pH with 2 decimal places in a non decimal datatype
#define ANALOG_MQ_DECIMAL_MULTIPLIER 100.0 #define ANALOG_MQ_DECIMAL_MULTIPLIER 100.0
// lenght of filter // lenght of filter
@ -387,7 +387,7 @@ void AddSampleMq(uint32_t idx){
if (Adc[idx].indexOfPointer==-1) if (Adc[idx].indexOfPointer==-1)
{ {
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Init samples for mq-sensor")); AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Init samples for mq-sensor"));
for (int i = 0; i < ANALOG_MQ_SAMPLES; i ++) for (int i = 0; i < ANALOG_MQ_SAMPLES; i ++)
Adc[idx].mq_samples[i] = _adc; Adc[idx].mq_samples[i] = _adc;
} }
else else
@ -402,9 +402,9 @@ float AdcGetMq(uint32_t idx) {
float avg = 0.0; float avg = 0.0;
float _RL = 10; //Value in KiloOhms float _RL = 10; //Value in KiloOhms
float _R0 = 10; float _R0 = 10;
for (int i = 0; i < ANALOG_MQ_SAMPLES; i ++) for (int i = 0; i < ANALOG_MQ_SAMPLES; i ++)
avg += Adc[idx].mq_samples[i]; avg += Adc[idx].mq_samples[i];
float voltage = (avg / ANALOG_MQ_SAMPLES) * ANALOG_V33 / ((FastPrecisePow(2, ANALOG_RESOLUTION)) - 1); float voltage = (avg / ANALOG_MQ_SAMPLES) * ANALOG_V33 / ANALOG_RANGE;
float _RS_Calc = ((ANALOG_V33 * _RL) / voltage) -_RL; //Get value of RS in a gas float _RS_Calc = ((ANALOG_V33 * _RL) / voltage) -_RL; //Get value of RS in a gas
if (_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted. if (_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.