Merge pull request #16287 from barbudor/cheap-MQ-TDS-refactoring

Analog MQ TDS: refactor pow to constant
This commit is contained in:
Theo Arends 2022-08-23 09:26:56 +02:00 committed by GitHub
commit 909f4debff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -404,7 +404,7 @@ float AdcGetMq(uint32_t idx) {
float _R0 = 10;
for (int i = 0; i < ANALOG_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
if (_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.