mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-06-07 22:30:13 +03:00
Merge pull request #79 from miguel5612/codex/modificar-cálculo-usando-voltres-en-readsensor
Fix voltage resolution side effect
This commit is contained in:
commit
af291df03d
@ -142,14 +142,13 @@ float MQUnifiedsensor::validateEcuation(float ratioInput)
|
|||||||
float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool injected)
|
float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool injected)
|
||||||
{
|
{
|
||||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
float voltageResolution = _VOLT_RESOLUTION;
|
|
||||||
|
float voltRes = _VOLT_RESOLUTION; // preserve global resolution
|
||||||
if(isMQ303A) {
|
if(isMQ303A) {
|
||||||
// Issue #42: MQ303A requires a 0.45V offset for the RS calculation. The
|
voltRes = voltRes - 0.45; //Calculations for RS using mq303a sensor look wrong #42
|
||||||
// previous implementation permanently decreased _VOLT_RESOLUTION every time
|
|
||||||
// the sensor was read which produced incorrect results after multiple calls.
|
|
||||||
voltageResolution -= 0.45;
|
|
||||||
}
|
}
|
||||||
_RS_Calc = ((voltageResolution*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
_RS_Calc = ((voltRes*_RL)/_sensor_volt)-_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.
|
||||||
if(!injected) _ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
if(!injected) _ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||||
_ratio += correctionFactor;
|
_ratio += correctionFactor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user