Measuring Barmometric Pressure using an MPX4115 Pressure Sensor

copyright, Peter H. Anderson, Baltimore, MD, Oct, '99


Introduction.

This discussion illustrates how a Motorola MPX4115 might be interfaced with a 10-bit A/D to measure barometric pressure. Expressions are developed for station pressure and for sea level pressure and an implementation is illustrated in program Barom.Bas. Note that the call to GetADC is simply a "stub" in this routine which was run on the BasicX-1.

Discussion

The new BX24 provides the ability to perform 10-bit A/D conversions. Thus the voltage may be determined as;

	(1) V_a_d = band / 1024 * V_ref
where band is the measured quantized band in the range of 0 to 1023 and V_ref is the nominal 5.0 VDC supply which powers the BX24.

The MPX4115AP sensor outputs a voltage which is proportional to pressure.

	(2) V_out = V_ref * (P_station * 0.0009 - 0.095)
where V_ref is the nominal 5.0 VDC which powers the MPX4115 an P_station is the pressure in millibars.

If the MPX4115 output is connected directly to the A/D, the V_out = V_a_d.

Thus, equating (1) and (2);

	V_ref * (P_station * 0.0009 - 0.095) = band / 1024 * V_ref
Eliminating V_ref and solving for P_station;
	(3) P_station = 1.085 * band + 105.55
However, note that P_station varies with altitude as;
	(4) P_station = P_sea_level * exp (-z/7000.0) 
where z is the altitude in meters.

Thus;

	(5) P_sea_level = P_station / exp (-z/7000.0)

	                = ((1.085 * band) + 105.55) / exp(-z/7000.0)
Note that in this expression, the sea level pressure is in millibars and the altitude z is in meters.

For those living in the US where barometric pressure is reported in inches of mercury;

	(6) P_sea_level_US = ((0.03188 * band) + 2.95) / exp(-z_ft/22965.0))
where P_sea_level_US is in inches of mercury and z_ft is the altitude in feet.


' Barom.Bas
'
' Illustrates how to measure barometric pressure using an MPX4115 Pressure
' Sensor.
'
' Note that subroutine GetADC() is a "stub".  The intent is to map this over
' to the BX24 which has eight 10-bit A/D converters.
' 
' Calculations are performed and displayed both for millibars and inches
' of Hg.
'
' An alternate technique for displying is then presented which truncates
' millibars to an integer and then displays the result in inches of Hg in
' the form XX.YY.
'
' copyright, Peter H. Anderson, Baltimore, MD, Oct, '99

Sub Main()

   Dim Band as Single
   Dim AltitudeMeters as Single, AltitudeFeet as Single
   Dim P_millibars as Single, P_in_Hg as Single

   Dim P_in_Hg_Int as Integer
   Dim WholePart as Integer, DecimalPart as Integer

   Dim str as String

   Call OpenSerialPort(2, 9600)

   AltitudeMeters = 1760.0
   AltitudeFeet = 5774.0

   Band = GetADC()

   P_millibars =  ((1.085 * Band) + 105.55) / exp(-AltitudeMeters/7000.0)
   P_in_Hg = ((0.03188 * Band) + 2.95) / exp(-AltitudeFeet/22965.0)

   str = "Pressure in millibars = "	' display the obvious way
   Call PutStr(str)
   Call PutS(P_millibars)
   Call NewLine()

   str = "Pressure in Inches of Hg = "
   Call PutStr(str)
   Call PutS(P_in_Hg)
   Call NewLine()

   str = "Pressure in millibars = "	' now display millibars ans integer
   Call PutStr(str)
   Call PutI(CInt(P_millibars))
   Call NewLine()

   str = "Pressure in Inches of Hg = "	' and this as XX.YY
   Call PutStr(str)
   WholePart = Cint(100.0 * P_in_Hg) \ 100
   Call PutI(WholePart)
   str = "."				' put in the decimal point
   Call PutStr(str)
   DecimalPart = Cint(100.0 * P_in_Hg) MOD 100

   If (DecimalPart <10) Then
      str="0"				' add leading zero
      Call PutStr(str)
      Call PutI(DecimalPart)
   Else
      Call PutI(DecimalPart)
   End If
   Call NewLine()

End Sub

Function GetADC() as Single

   GetADC = 644.0		' this is a stub

End Function