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


    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

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    If you have an op-amp in a non-inverting configuration, you have two resistors: one (call it R1) from the op-amp output to the inverting input, and another resistor (call it R2) from the inverting input to GND (usually). The gain will be 1+ (R1/R2). If you tie the end of R2 that normally would go to GND to a voltage instead, the output will be shifted. The gain from that point will be (R1/R2).

    For example: If you have an input that goes from 5 to 6 volts, and you need to change it to one that goes from 0 to 5 volts, you need a gain of 5 (1 volt change going in, to 5 volts change at the output). You could choose R1= 4K and R2= 1K. The gain would be 1+ (4K/1K) = 5.
    Now you need to shift it "down" to the 0 - 5 V range. The gain to the inverting input will be 4 (4K/1K), so you need to apply 5V/4 = 1.25V ABOVE 5V = 6.25V to the end of R2.

    Remember that if you use a voltage divider to provide this 6.25V, the thevenin resistance of the divider will be added to R2's value. The best way around this is to connect R2 to the output of a unity-gain op-amp, and drive THAT op amp with a divider from a voltage reference. And one final thing - if you don't have a negative voltage source for the (-) power pin of the op-amp, you will need a rail-to-rail output type in order for the output to get to near zero volts.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the Help.

    So, I got the op amp all set up to keep the voltage under five volts. I can't believe I let that slip my mind when I was setting this up.

    Now, for coding, to get the analog output of the sensor to a use-able number in the pic. I understand that the pic has to have the AD conversion turned on.

    So, I want to hook up the analog voltage input on to pin RA7 on a 16f88. Would this be the correct code to do that

    'Set up AD conversion
    TRISA = %10000000 'sets RA7 as input and the rest as outputs
    ADCON1.7 = 1 'Right justify for 10-bit results
    Pause 500 'Wait .5 seconds for warm up
    But then, I'm stumped on getting the digital value from that pin to a value to plug into the equations for velocity.

    I'm sorry I'm so slow at this. I'll end up in the lab at 6AM tomorrow working on this so I want to make so I have as much information as possible to get as much done as I can.

    -Marcus

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


    Did you find this post helpful? Yes | No

    Default

    You can take a look at this and the data sheet to help you figure it out.
    Basics for reading an ADC with a 0 to 5 volt input and the chip running on 5 volts.
    Change as needed.
    Code:
    <font color="#000000">    <font color="#008000"><b><i>'16F88 10 BIT ADC TEST  FOR CHANNEL 0
        </i></b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>OSC </b></font><font color="#800000"><b>4           
        </b></font><font color="#0000FF"><b>OSCCON </b></font>= <font color="#800000"><b>%01100000
        </b></font>@ <font color="#0000FF"><b>__config _CONFIG1</b></font>, <font color="#0000FF"><b>_INTRC_IO </b></font>&amp; <font color="#0000FF"><b>_WDT_OFF </b></font>&amp; <font color="#0000FF"><b>_LVP_OFF </b></font>&amp; <font color="#0000FF"><b>_MCLR_OFF </b></font>&amp;<font color="#0000FF"><b>_CP_OFF
        ANSEL </b></font>= <font color="#800000"><b>%00000001
        </b></font><font color="#0000FF"><b>TRISA </b></font>= <font color="#800000"><b>%11111111
        </b></font><font color="#0000FF"><b>CHAN0  </b></font><font color="#FF0000"><b>VAR WORD   </b></font><font color="#008000"><b><i>'VAR TO HOLD ADC0 READING
        
        </i></b></font><font color="#0000FF"><b>START</b></font>:
        <font color="#FF0000"><b>HIGH </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>3    </b></font><font color="#008000"><b><i>'HEART BEAT LED
        </i></b></font><font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>250
        </b></font><font color="#FF0000"><b>LOW </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>3
        </b></font><font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>250
        </b></font><font color="#008000"><b><i>'BELOW WILL SHOW WHAT THE ADRESH AND ADRESL REGISTER HOLDS
        </i></b></font><font color="#FF0000"><b>SEROUT2 </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>2</b></font>, <font color="#800000"><b>16780</b></font>, [<b><i>&quot;ADRESH &quot;</i></b>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>ADRESH</b></font>,<b><i>&quot; ADRESL &quot;</i></b>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>ADRESL</b></font>,<font color="#800000"><b>$a</b></font>,<font color="#800000"><b>$d</b></font>]
        <font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>50
        </b></font><font color="#008000"><b><i>'BELOW SHOWS THE 10 BIT READING OF ADC0 IN VAR CHAN0
        </i></b></font><font color="#FF0000"><b>SEROUT2 </b></font><font color="#0000FF"><b>PORTB</b></font>.<font color="#800000"><b>2</b></font>, <font color="#800000"><b>16780</b></font>, [<b><i>&quot;CHAN0 &quot;</i></b>,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>CHAN0</b></font>,<font color="#800000"><b>$a</b></font>,<font color="#800000"><b>$d</b></font>]
        <font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>250
        </b></font><font color="#FF0000"><b>GOSUB </b></font><font color="#0000FF"><b>ADC_0      </b></font><font color="#008000"><b><i>'STARTS THE READING OF ADC CHANNEL 0
        </i></b></font><font color="#FF0000"><b>GOTO </b></font><font color="#0000FF"><b>START
        
        ADC_0</b></font>:       <font color="#008000"><b><i>'READ AN0
        </i></b></font><font color="#0000FF"><b>ADCON1 </b></font>= <font color="#800000"><b>%10000000      </b></font><font color="#008000"><b><i>'SET FOR 10 BIT
        </i></b></font><font color="#0000FF"><b>ADCON0 </b></font>= <font color="#800000"><b>%00000001      </b></font><font color="#008000"><b><i>'TURNS ADC ON
        </i></b></font><font color="#FF0000"><b>GOSUB   </b></font><font color="#0000FF"><b>READ_AD
        CHAN0</b></font>.<font color="#0000FF"><b>HighByte </b></font>= <font color="#0000FF"><b>ADRESH  </b></font><font color="#008000"><b><i>'PLACES THE HIGH AND LOW BYTE
        </i></b></font><font color="#0000FF"><b>CHAN0</b></font>.<font color="#0000FF"><b>LowByte  </b></font>= <font color="#0000FF"><b>ADRESL   </b></font><font color="#008000"><b><i>'INTO VAR CHAN0
        </i></b></font><font color="#FF0000"><b>RETURN
        
        </b></font><font color="#0000FF"><b>READ_AD</b></font>:   <font color="#008000"><b><i>'DOES THE ADC CONVERSION
        </i></b></font><font color="#FF0000"><b>PAUSE   </b></font><font color="#800000"><b>50
        </b></font><font color="#0000FF"><b>ADCON0</b></font>.<font color="#800000"><b>2 </b></font>= <font color="#800000"><b>1
        </b></font><font color="#FF0000"><b>WHILE </b></font><font color="#0000FF"><b>ADCON0</b></font>.<font color="#800000"><b>2 </b></font>= <font color="#800000"><b>1</b></font>:<font color="#FF0000"><b>WEND
        RETURN  
                        
        
    </b></font>
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

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