Airspeed from MPX5500DP differential pressure sensor using a PIC16F88


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Location
    Northern Colorado
    Posts
    19

    Default Airspeed from MPX5500DP differential pressure sensor using a PIC16F88

    Hey All,
    I am working on a project to calculate the airspeed from a pitot tube that is connected to a differential pressure sensor (MPX5500DP) and then output it to an LCD screen (44780 Driver) using a PIC16F88. I have very little background in picbasic and I am having a hard time writing the code.

    To calculate the velocity from the pressure, I want to use the equation

    Airspeed = sqrt(2P/1.2) where 1.2 is the density of air

    But, the problem is I need P from my sensor. How would I go about getting this value?

    The basic setup is I have the Vout from the sensor going through a non-inverting amplifier (LM741C). So the amplified voltage values range from something like 9V to 13V, depending on what the pressure is on the sensor. I know that I need to turn on the A/D conversion and right justify to get 10-bit results, but I am stuck after that. How do I write the code to take the voltage coming in to the pic and turn that into a value for pressure. I've read several other threads involving pressure sensors but none of them were differential pressure sensors.

    My current code is very short, but its all I could manage to get together from my research.


    'Identify and set the internal oscillator clock speed (required for PIC16F88)
    Define OSC8
    OSCCON.4=1
    OSCCON.5=1
    OSCCON.6=1

    'Set Up A/D Conversion
    TRISA = %11000000 'sets RA6 and RA7 as inputs and the rest as outputs
    ADCON1.7 = 1 'Right justify for 10-bit results
    Pause 500 'Wait .5 seconds for warm up


    I've attached a wiring diagram of how I would like to wire this set up.

    Any help would be greatly appreciated. Let me know if I need to provide more information. Again, I am not very familiar with picbasic so the more simple it is, the better.

    Thanks!

    -Marcus
    Attached Images Attached Images  

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Welcome to the forum.
    Here is a similar one. See if it helps.
    http://www.picbasic.co.uk/forum/showthread.php?t=13141
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2010
    Location
    Northern Colorado
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Dave,

    Thanks for your help. That makes a huge difference. Few questions for you though. Since this sensor will never hit it's maximum pressure reading at any point, is there a way to cut the max pressure to a tenth of what it is? i.e. the MPX5500DP has a Pmax of 500 kpa, if I cut that down to 50 kpa (500 / 10), would that make any major difference in my calculations?

    So, from the copying from the other thread and plugging in my numbers.

    "Using the old formula of
    y = mx-b
    y = output 'Volts
    m = slope
    x = input units
    b = offset
    wanting to read form 0 to 500kpa.
    Output is 10 to 14 volts.

    Start off by looking at the output in volts. I have a 4 volt span. Giving a span of 500 / 4 = 125
    m = 125

    The offset. Starting at 10 volts. 10 volts = 0 kpa. The offset is 10 * 125 = 1250
    1250

    Plug all this into the formula and lets say the input is 14 volts.(full scale)
    y = (125 * 14) - 1250
    y = 500

    Now convert this to an 10 bit PIC resolution.

    10 bits ADC = 0 to 1023, 1024 steps.
    At 14 volts one volt of input will will read 73.
    Spanning 4 volts or 292 steps (4 * 73).

    New value for m. 500 / 292 = 1.7123
    m = 1.7123


    The new offset starting at 730, (10 * 73).
    730 * 1.7123 = 1250
    b = 1250


    y = (ADC * 1.7123) - 1250
    ADC = 1023
    y = 500kpa

    ADC is from the sensor."


    Correct?

    But, then in the code you multiple m by 10,000 and b by 100, what does this do for the values? Is that simple to prevent truncation in the program?

    "Code:

    ' m = 0.00479
    ' b = 0.98
    ' y = (ADC * 0.00479) - 0.98
    ' ADC = 1023
    ' y = 3.92kpa
    M CON 479 'm = 0.00479 * 10,000
    B CON 98 'b = 0.98 * 100
    ADC VAR WORD 'INPUT FROM SENSOR
    Y VAR WORD 'KPA
    Z VAR WORD 'DUMMY VAR
    Z1 VAR WORD 'DUMMY VAR
    'V = SQRT((2 * (Y/1000)) / 1.225)
    V VAR WORD 'METERS/SECOND
    D CON 122 'AIR DENSITY

    START:
    ADC = 1023 'FULL SCALE HARD CODED, NO SENSOR
    Z = ADC * M
    Z1 = DIV32 1000
    Y = Z1 - B
    Z = (2 * Y * 10000)
    Z1 = DIV32 1000
    V = SQR(Z1 / D *100)
    LCDOUT $FE,1,"KPA= ",DEC Y/100,".",DEC Y//100
    LCDOUT $FE,$C0,"M/S= ",DEC V
    PAUSE 250
    GOTO START"

    I really appreciate the help.

    -Marcus

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Output is 10 to 14 volts.
    Remember that the MCU can not handle 14 volts. 5 is the max. You can use a voltage divider to bring the voltage down though. Do a 3 to 1.

    To tighten the readings up you can add a VREF value to the MCU via voltage dividers.

    But, then in the code you multiple m by 10,000 and b by 100, what does this do for the values? Is that simple to prevent truncation in the program?
    Yes, the decimal constants are converted to whole numbers for calculating.

    I will suggest setting up a test board with some pots and play with the ADC some to get a feel for it.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Oct 2010
    Location
    Northern Colorado
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Oh jeeze. I should have realized that... okay. Well I can fix that by bumping down the gain on the op amp by swapping resistors so that's not a problem. I'll work on this and see if I can't get something working. Thanks for your help! I'll probably be back with more questions later.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by marcusvm View Post
    I'll probably be back with more questions later.
    We will be here. Good luck!
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts