Monday, June 25, 2012

Measuring liquified petroleum gas (LPG) levels

Before anything else, I forgot to mention in in the LPG detection test that I took temperature measurements of the TGS2610 sensor of the LPM2610 module using a Fluke 87V and its thermocouple. After the module had been powered up for many minutes I held the thermocouple junction to the case for a couple of minutes and obtained a maximum reading of 52.8°C. Ambient temperature was 32.7°C. I am not confident with this case temperature measurement. Contact area between thermocouple and case is small and manually holding the thermocouple did not of course properly secure it to the sensor. Taping or even gluing it in place may be a more reliable way of taking a measurement.

As I mentioned in Detecting LPG, it occurred to me that we can use the Figaro LPM2610 module to not just detect the presence of LPG when it's >= 10% of its lower explosive limit (LEL), we may also be able to use its analog outputs to measure the amount of gas in the air.

Before we jump in, a couple of caveats relevant to measuring gas levels. The TGS2610 datasheet says the sensor's typical detection range is between 500 to 10,000 ppm. Given butane LEL = 18,000 ppm, the sensor's detection range translates to 2.8% to 55.5% LEL. I want to be able to measure all the way down to 1% but it looks like this may be asking too much from this sensor. Then again we can take our chances.

Secondly, the sensor is hardly accurate as can be seen in this Figaro diagram of the module's expected performance:

The note below the chart says 
When using LPM2610, typical alarm tolerances for 10% LEL of LP gas such as those shown in the figure above can be expected. However, in actual usage, alarm thresholds may vary since the threshold is also affected by such factors as the tolerances of test conditions and heat generation inside the gas detection enclosure. 
The tolerances are pretty wide: 5 to 20% LEL. Not at all encouraging.

Given these characteristics, using the LPM2610 to measure gas levels seems almost foolhardy. But in quixotic fashion we shall nevertheless proceed--if only as a mathematical exercise.

To start off here's a list of definitions of terms and variables we'll be using:
  • Standard values are sensor resistance and output voltage at an ambient temperature of 20°C. To standardize a voltage is to apply a corrective factor provided by VREF so that the voltage value becomes that which would be expected if ambient = 20°C.
  • Actual values are LPM2610 resistance and output voltage values without consideration to ambient temperature.
  • VREF is the output of the LPM2610 voltage divider consisting of a thermistor and various fixed-value resistors. VREF is theoretically = VDD/2 when ambient temperature = 20°C.
  • VOUT(act) = actual output of the LPM2610 voltage divider consisting of (1) the TGS2610 sensor whose resistance varies with amount of LPG present and (2) a fixed value load resistor RL.
  • RS(act) = actual sensor resistance in the LPM2610
  • RS(std) = standard sensor resistance  
  • VOUT(std) = standard voltage output given RS(std) 
  • RL = load resistance in series with RS 

Preliminary equations

Take a look at the LPM2610 circuit diagram above. Given the voltage divider RS and RL, output voltage VOUT is given by the equation below. VOUT in this case is the actual VOUT and RS is the actual RS.

Given our definitions of standard sensor resistance and output voltage it follows that:

The LPM2610 module is calibrated at an ambient temperature of 20°C where VREF = VDD/2. As ambient temperature deviates from 20°C, VREF is adjusted by the module's thermistor. In our equations we will need to determine VOUT(std). And so we need to adjust VOUT(act) by a certain factor. This correction factor is as follows:

Derivation of RS(std) Equation

We need to find an equation that describes sensor resistance in terms of % LEL. Since Figaro provides no equation we need to derive it from sensor data. Fortunately, Application Note for LP Gas Detectors using TGS2610 lists RL = RS for various %LEL and TGS2610 ID numbers (ID# corresponds to specific sensor resistances). For example the Figaro LPM2610 modules that I got have sensors with ID#15. From the AN here are its characteristics:

Specification of TGS2610 with ID#15
% LEL RS(std) in ohms
5 3830
10 2740
15 2260
20 2000

To transform that table of data into a formula we perform regression analysis. If we plot the above we end up with a nonlinear curve, one which shows the characteristics of a power law curve where y = axb. Unfortunately, the spreadsheet I'm using can only do linear regression. Fortunately, we can work around this limitation. If we plot the values in the above table on a log-log paper (where x and y axes are graduated in a logarithmic scale), we get a nearly straight line and not a curve. Therefore, we can take the log(x) and log(y) and plug those in the linear regression equations. Solving for the log of both x and y, i.e., of %LEL and RS(std), we obtain the following:

log(%LEL) log(RS(std))
0.698970004336019 3.58319877396862
1 3.43775056282039
1.17609125905568 3.3541084391474
1.30102999566398 3.30102999566398

We let the spreadsheet perform a linear regression using the above logarithmic data and it magically spews out the following:

b = x coefficient = -0.471269891979091
c = constant = 3.91103846203761
r squared = 0.999483957661255

r2 is the square of the correlation coefficient. Since it's practically = 1 it implies that the correlation between data and the equation is extremely high. Keeping in mind that we had used the logarithms of x and y, the regression equation is:

log(y) = b*log(x) + c

Here's a plot of both the datasheet values (red points) and computed line using an online linear regression calculator:

Taking the antilog of both sides of the equation above gives us:

y =  10[b*log(x) + c]

Table below shows the computed RS(std) and the %error from values given in the datasheet.

RS(std) using regression equation
% LEL RS(std) in ohms error in %
5 3816 -0.36
10 2753 0.47
15 2274 0.62
20 1986 -0.72

Recall that I performed a linear regression because my spreadsheet does not have the capability of doing a power regression. However, there are various online resources that we can use, obviating the need to get the logarithms of x and y. Plugging the data from the very first table above into a power regression calculator gives us the following results:

a = 8147.7643914991
b = -0.471269892
correlation coefficient = 0.9998059883

So the power equation is

y =  8147.7643914991x-0.471269892

Now, since both the linear and power equations yield the same y we can equate the two:

axb = 10[b*log(x) + c]

Taking the log of both sides we obtain:

log(a) + b*log(x) = b*log(x) + c

log(a) =  c

Indeed, if we take the log of  8147.76 we get 3.911

Bear in mind that the above equations apply only to TGS2610 ID#15. Nevertheless, upon subjecting ID#10 and #20 to power regression and computing for VOUT(std) as a percentage of VDD I obtained results which confirmed the guess that they'd all show practically the same characteristic voltage outputs given their respective voltage divider resistor values. Click the "Vout as %Vdd" tab at the bottom of the following spreadsheet to see the computed values. Take a look at the columns with blue headers. The percentages for each of the three ID# are practically the same for every %LEL.

Determining % LEL

There's at least two ways--when using a microcontroller--to determine the % LEL: direct computation and use of a look-up table.

I. Direct Computation

The direct way is to derive a formula which the microcontroller can use to calculate the amount of gas detected (as % LEL).

Given the voltage divider in the TGS2610 sensor and from our definition of standard values we infer that:

From the above power regression we have:


Given VOUT(act) we can obtain VOUT(std) by applying the corrective factor:

Rearranging the terms, substituting and solving for x:

RL is a constant and will be contingent upon the particular TGS2610 unit being used (its ID# will determine what RLwill be).

II. Look-up Table

The other method--which is less CPU intensive--would be to compare the standardized VOUT as a fraction of VDD with the values in a look-up table to determine % LEL (eg., to the nearest %). The look-up table is populated with values computed using the following formula, where x = %LEL and a and b derived from power regression:

As we already obtained in the direct computation method:

We then divide VOUT(std) by VDD to obtain a unitless fraction:

So all the MCU has to do is evaluate the relatively simply equation on the right and then look for the closest value in the table to determine %LEL.

No comments:

Post a Comment