|
|
View previous topic :: View next topic |
Author |
Message |
helpless..! Guest
|
Interfacing MPXA6115A pressure sensor to PIC16F877A |
Posted: Fri Jan 05, 2007 3:21 am |
|
|
I'm currently working on a digital altimeter which uses a MPXA6115A pressure sensor by freescale, but the output is in analog voltage form.So, i need to covert it into 10-bits digital form by using A/D Converter module built inside the PIC16F877A.
can anyone suggest a sample program code to me?
thanks. |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 05, 2007 8:35 am |
|
|
First, you need to think quite hard about the circuit. If you intend to use the 5v as a reference (since the chip gives up to about 4.7v out), you need to think very carefully about how to get good accuracy and stability on this line. If there is other electronics involved, it may be worth having a separate regulator for this line for the PIC and the sensor. Though the chip is close to ratiometric for supply changes (about 96%), it is not perfect in this regard.
Second, you shold consider buffering the output of the unit. Though it can sink/source 0.5mA at the ends of it's swing, it tends to give noticeable non linearity into some loads. It is best run with the pull down resistor and capacitor shown in the data sheet, and then buffered with something like an LMC6482 (rail to rail input and output off 5v).
Then you simply have a ADC value, corresponding to either absolute pressure, or differential pressure, according to the unit version chosen.
Now, in terms of taking an ADC reading, and converting it to a 'useful' value, the chip is a 'doddle'. The manufacturers scale the output as 45.9mV/kPA. Beautifully, this means a single count, of a 10bit ADC, using 5v reference, is a kPA (or mBar). So if you have 'ADC=10' selected, and use a signed int16 to hold the adc result, it is directly in mBar. So for many applications, this is great. However for altimetry at lowish altitudes, you will need to add amplification, or use a more sensitive ADC for reasonably useful results. The problem is that 1mB, corresponds to between 30, and 50 feet of altitude change (depending on humidity etc.). Hence you should consider having an external pot, which can be set to give a DC offset voltage, and then using an op=amp to subtract this from the sensor voltage, and amplify the result a few times to give higher gain. for 'normal' pressure conditions, the pot should be arranged to give between about 4.35v, and about 4.8v out, corresponding to a barometric range of about 950 to 1050mB, which would cover most likely weather conditions (unless you want to set an 'above sea level' origin, in which case the ability to select lower starting voltages will be neded). Obviously the ADC count per mB, will then depend on the selected gain.
Best Wishes |
|
|
helpless..! Guest
|
|
Posted: Fri Jan 05, 2007 11:30 am |
|
|
Thanks for the suggestion.Here i have other question:
Is it necessary to hav a op-amp to do the filter stage?or to step up the gain?
The idea i have advise i had is to connect the MPXA6115 straight to the Microcontroller,and let the A/D converter do it's job. But which pin on the microcontroller to connect to...?
Vref+ and Vref- ? |
|
|
Ttelmah Guest
|
|
Posted: Fri Jan 05, 2007 3:52 pm |
|
|
You need to have an op-amp, just to buffer the output. The problem (as I already posted), is that the output can become non linear into the load presented by the ADC. You may also need an op amp to provide gain, if you want more sensitivity than 1 count = 1mBar, but this is down to what you require. The chip is designed to operate with an ADC, using the sensor's 5v supply as it's Vref. Hence you can just connect the buffered output directly into AN0, and run the PIC ADC using Vss to Vdd as it's reference, provided this supply is carefully arranged (as already posted...).
Best Wishes |
|
|
Guest
|
|
Posted: Fri Jan 05, 2007 4:05 pm |
|
|
Hi,
Here is a weather station project that uses the sensor you are interested in, and includes code for CCS C.
Chas. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Fri Jan 05, 2007 6:10 pm |
|
|
Anonymous wrote: | Hi,
Here is a weather station project that uses the sensor you are interested in, and includes code for CCS C.
Chas. |
Where, oh where? The link seems to be missing. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 05, 2007 6:14 pm |
|
|
Guests can't post links. Darren disabled that feature to discourage
the spammers. I think a guest can post the URL, as long as he
leaves off the "http" part. Or he could register and post it. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Fri Jan 05, 2007 6:15 pm |
|
|
Slightly OT. This pressure sensor consumes 10mA at most. If power consumption is an issue, you could power the sensor directly from a digital I/O pin of a PIC. This will allow you to turn it on only when you needto make a pressure reading |
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 06, 2007 5:32 am |
|
|
If you do this, then the line feeding the ADC, will need to connect to Vref+, and be used as the reference, otherwise the voltage drop in the output, will cause massive errors. Also a better switching element should really be used. At 10mA, the direct output from the PIC, will drop a significant fraction of a volt, and the device has a rather narrower than normal supply voltage allowable range.
I did a system some years ago, using the 4115, which was upgraded a little while ago to use the 6115. The devices really are easy to use and drive, and accuracy is very good indeed (we calibrate them from a known pressure source, but the amount of adjustment is normally very small - also the temperature of the system is stabilised, which helps noticeably). These are used in a lot of factories around the world, and have been one of the most 'trouble free' parts to work with I have ever used!...
Best Wishes |
|
|
helpless..! Guest
|
|
Posted: Sun Jan 07, 2007 6:59 am |
|
|
thanks for all advices!
do anyone have an example source code to do the calculation for the altitude..?i need an reference to write my program.urgent,time is short.
assembly code is preferable.
thanks. |
|
|
ttelmah Guest
|
|
Posted: Sun Jan 07, 2007 10:52 am |
|
|
This goes back to my first answer.
First comment. Do you understand how pressure altimetry is done?.
There are two basic operating 'modes'. The first, is used in aviation at low altitudes, and for things like basic rocketry. Here the current ground level barometric pressure (Qfe in aviation terms), or sea level pressure (Qnh), is 'dialed in'to the altimeter. The pressure _difference_ from this reading is then taken, and displayed as height. The second mode, is used at higher levels in aviation. Here a _standard_ zero point pressure (1013.2mB), is dialed into the instrument, and your altitude is then displayed relative to this. In aviation, height, and altitude are used as 'keywords' to distinguish these modes. You are flying at an 'altitude', when 'flight levels' are referred to.
Now, in both cases, you need to work relative to a reference pressure. For the latter, a standard setting could be made, but for the former, an adjustment will be needed to feed into the circuit. The input stage gain, will need to be selected by you, to give the sort of useable range required. So (for instance), if you wanted to display to 10000 feet, given that there are 1024 steps in the standard ADC, you would want to chose the gain to use most of this range. Seperately, the rate at which pressure changes with altitude is not constant. To get an accurate height/altitude, requires that corrections are applied for the temperature. Even with this, you are still working with a 'model' of the atmosphere, and real heights will differ. For aviation, a simplified model is used, where pressure changes at 1mB/29.53 feet (normally approximated to 30 feet), and temperature drops by 2C/1000 feet. So for the 10000 feet operation, a pressure change of 333mB would be involved (33.3kP). At the 45.9mV/kP output from the sensor, this corresponds to 1.528v. To give 1000 steps, using a 5v reference,this would require 1000/(1.528/(5/1024)) * gain in the input amplifier. 3.2*.
So you would build a simple op-amp circuit to give 3.2*. Have a voltage source that can be subtracted from the input, which you adjust, either having a dial calibrated in mB, or by 'zeroing the output at your starting location. Then you simply read the ADC, and multiply the reading by 10, to give altitude. Correctly, you should also measure the OAT at the same time, since if the temperature changes faster or slower than the standard figure, or starts at a different temperature, this implies an error in the barometric reading will result. The normal simple correction for this, is 13 feet per degree different from the ISA temperature (starts at 15C at ground level). There are also more complex corrections, if the lapse rate (rate at which the temperature is changing) is non standard. There are standard correction formulae that can be applied for this. However for low altitudes this is not normally a significant problem.
So, there is nothing at all _to_ the code. Once the input amplifier is built, and the adjustment performed, the basic reading, as would be displayed on a simple aircraft altimeter, is just a matter of taking the ADC reading, and multiplying by 10 (for the gain circuit proposed above). The work, is in designing the gain circuit, and the adjustments tobring the range into a useable value...
Best Wishes |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Sun Jan 07, 2007 3:57 pm |
|
|
ttelmah wrote: | Even with this, you are still working with a 'model' of the atmosphere, and real heights will differ. |
For most aeronautical aplications people use ICAO Atmosphere model.
The cheap comodity pressure sensors are also excellent accelerometers. If there's an acceleration perpendicular to the membrane of the sensor, the sensor is going to lie. Same goes for vibration. Luckily, you might be able to filter (in analog or digital domains) the efefcts of vibration.
What are kind of vehicle are you going to install your sensor in? |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 07, 2007 4:10 pm |
|
|
I agree.
The original poster doesn't seem to want to actually give data about the application, but then wants 'code'. The basic barometric reading code, is one line, it is the question of how much tweaking is needed to this (internally, and externally), which needs to be answered before even thinking about this. My comments about still using a 'model', were aimed at the possibility that he did not understand the limitations of barometric altimetry, and that this won't really read 'height' as such, but just give a generally accepted approximation to this. Historically, this was why early estimated of the heights of some mountains were so badly in error. Even using very careful corrections, and the best available model, it still only gives an approximation....
Best Wishes |
|
|
helpless...! Guest
|
|
Posted: Mon Jan 08, 2007 1:53 pm |
|
|
let me explain in detail:
i'm currently working on the digital altimeter for a kit airplane, the altitude of the flight is to be transmitted thru the RS232 port,and displayed onto a LCD.i'm new to programming, so i need a reference to guide me.
now, i'm writing the ADC program to acquire the analog input from the Vout of MPXA6115. then, the converted 10-bit result will be stored in ADRESH and ADRESL depending on the A/D result justification i set(left/right).but i wonder how is the output look like? is it 5v is '1111111111' in binary form and 0v is '0000000000'?
hmmn, the calculation part for this program is tricky...!
as u said 5v correspons to 1024 A/D counts, and each A/D count weight 4.8mV/bit (5/1024=4.8m), means the resolution of the altimeter.
given sensitivity=45.9mV/kpa , and now we have 9.56bit/kpa (45.9/4.8=9.56bit/kpa).
this means 1kpa corresponds to 9.56bits(A/D counts) and max A/D counts= 1024bit, so the max pressure i can measure is 107.11297kpa (1024*9.56=107.11297kpa).
now, i hav the range check:
0kpa-----1kpa------2kpa---------------------101kpa--------107.11297kpa
= = = = =
0count 9.5count 19.12count 965.56count 1024count(bits)
'00......0' '0000010011' '1111000101' '1111111111'
the program must be able to check the range where the digital output of 10bit falls between, and calls the pressure level at that the particular A/D count range.
example: if the ADC give an output of 1111000111 (equals to 967A/D counts), and the program must check which range this data falls..and tells the pressure level of that range.
then,by using the eqn: h=-7935.ln (P/Po) where Po=101.3 kpa and P is value we obtained.
so, the h,height of the airplane can be calculated and displayed on to the LCD.
is this a workable idea?workable design? |
|
|
helpless..! Guest
|
|
Posted: Mon Jan 08, 2007 2:04 pm |
|
|
let me rearrange the range check:
0kpa= 0count ('0000000000')
1kpa= 9.5count ('0000010011')
2kpa= 19.12count ('0000010011')
.
.
.
.
101kpa=965.56count ('1111000101')
107.11297kpa=1024count ('1111111111') |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|