ADC question again


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Mar 2010
    Posts
    52

    Default ADC question again

    Hi Guys, and Lady, :-)

    Im no good with maths, :-(

    I have a differential pressure sensor and am looking to use it to get an airspeed, once I have the airspeed I can work with it, :-)

    Vref = 3.0V
    ADC = 10-bit = 1023 steps
    Air density @ sea Level = 1.225
    Sensor Range = 0.6V per kpa

    So, the formula that Im currently trying to get right is as follows:

    Code:
    VelocityKPH VAR WORD
    A VAR WORD
    
    ADCIN 4, A ‘will do a loop of 10 samples later
    
    VelocityKPH = (A-186)*36667
    VelocityKPH = SQR VelocityKPH
    VelocityKPH = VelocityKPH / 18
    As I say, my maths is shocking, :-( I kinda understand the principles but dont get how to string it all together, any help will be very much appreciated.

    Kind Regards
    Rob

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


    Did you find this post helpful? Yes | No

    Default

    First thing I see is you will want to use LONGs.
    Code:
    VelocityKPH VAR LONG
    You will over run the WORD size variable
    </pre>
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Strange, does not look like we can edit our previous posts in the new forum, :-(

    Slight correction was, the sensor range is not 0.6v, :-), rather, sensitivity.

    The Zero (min Vout) value is 0.66V, thus I need to remove the first 207 / 208 counts of the AD value in order to get a 0 value.

    The sensor range is rather: 0 to 3.92Kpa

    Dave, I tried the long Var and PBP complains on compile, help only lists BIT, BYTE and WORD as valid variable types?

    Any ideas on what the PBP equivalent equation / formula would be to extrapolate the Kpa to a speed?

    In a C / Arduino example using the same sensor (although 5V sensor) is as follows:

    Code:
    ;#define Pressure_MTS(x) sqrt((((x*(INTPUT_VOLTAGE/1024.0))/1.0)*2.0)/1.225) //Converts to AirSpeed in meters per second
    ;#define Pressure_KMH(x) Pressure_MTS(x)*3.6 //converts to KPH
    I've been able to get the RAW ad reading as well as the sensor output voltage displaying on the LCD, however I'm lost on the conversion from a ratiometric voltage to a speed, :-(

  4. #4
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Thumbs up

    Well, managed to get a result in excel, :-) but my conversion to "integer" math for PBP does not work, I've tried probably 40 different variations of the code below and am still not getting a result, :-(

    The excel formula works as follows:

    rho: 1.225 Air Density constant
    Zo: 0.75 Zero Offset
    Vs: 3260 Voltage supply
    Vo: 1.2 Voltage out from sensor (Output from ADC)

    Formula1 Dp=(Vs*(Vo/Vs)-Zo)
    Formula 2 Mps=SQRT((2*Dp*1000)/rho)

    However, translated into PBP I tried the following:

    Code:
      rho = 1225        'Constant for pressure calc
      Zo = 74           'Zero Offset
      Vs1 = 3260        'Vref
        
      AD_in = 0
      Pres = 0
      volt = 0  
        for samples = 1 to 4      '4 Samples from AD - Sensor is low pass filtered
                ADCIN 4, ad_in
             volt = volt + ad_in
                Pause 25
         Next Samples
         volt = volt / 4          'Average AD
         
    volt = volt * 3186            'convert to voltage out
    Vind = DIV32 10000            'DIV32
    
    'Excel Formula:
    'Dp=(Vs*(Vo/Vs)-Zo)
    
    dy_p = vind * 1000
    Dy_p = (vind / Vs1)
    dy_p = (dy_p * vind) / 1000
    dy_p = dy_p - Zo
    
    LCDOUT $FE, $80+6, dec2 dy_p, "    " 'output to first line
    
    'Excel Formula:
    'Mps=SQRT((2*Dp*1000)/rho)
    
    Vmps = dy_p / 1000
    vmps = vmps * 2 * 1000
    vmps = vmps / (rho/1000)
    vmps = sqr vmps
    
    lcdout $FE, $C0+5, dec2 vind        'output to second line
    Can anyone help steer me in the right direction? I tried using the DIV32 after the multipys but also then got some unexpected values.

    Many Thanks
    Rob

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


    Did you find this post helpful? Yes | No

    Default

    Sorry for not following up sooner.

    LONGs are only available in PBP 2.5 and newer and for 18F parts only. LONGs might make this easier but should not be needed.

    First off, do you have

    DEFINE ADC_BITS 10
    In your code?

    Next I have a question about your senso to get started.
    The sensor has an output from
    0.66 to 3 volts ?
    0 to 3.92Kpa ?

    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    Appreciate the help, still struggling to get PBP to understand my math, :-)

    yip, i do,

    Code:
    ;----- NEW LCD Configuration for Testing-------------
    DEFINE OSC 20	'20 MHz Osc
    DEFINE ADC_BITS 10
    yes, the input from the regulator is acutally 3.26v which is just under the sensors "Max", output @ rest should be "Min" = 0.45v Typ = "0.60" and "Max" = 0.75 i assme this is due to the barometric pressure varying.

    Range of the sensor is: 0 to 3.92kpa

    in excel the maths seems to give me a realistic number based on changing the Vo cell where i would expect the reading from the sensor to be, however the testing has been blowing into the tube so not really very scientific, :-)

    Kind Regards
    Rob

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default

    Hi, Bobbo

    seems PBP is not the only one to have difficulties with your maths ...

    so, in case I could help ...

    Could you give me a link to your sensor Datasheet ...

    There are things I'm missing ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Hi Ace,

    Sorry, :-( some concepts just dont sink in, they need to be beaten in, :-)

    Attached is the datasheet.

    Haven t tried again since Thursday, going to sit down now and try get each value multiplied out and then DIV32'ed to try get to the right values, see if it works.

    Many thanks for the help

    Rob
    Attached Images Attached Images

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


    Did you find this post helpful? Yes | No

    Default

    First the ADC needs to be converted into KPA for yourformuls to work.
    You will need to have the ADC setup with a 3.0 volt reference.
    Using the old formula of
    y = mx-b
    y = output 'Volts
    m = slope
    x = input units
    b = offset

    You are wanting to read form 0 to 30 amps.
    You are wanting to read form 0 to 3.92kpa.
    Output is 0.6 to 3 volts.

    Start off by look at the output in volts. You have a 2.4 volt span. Giving a span of 3.92 / 2.4 = 1.633
    m = 1.633

    The offset. Starting at 0.6 volts. 0.6 volts = 0 kpa. The offset is 0.6 * 1.633 = 0.98
    b = 0.98

    Plug all this into the formula and lets say the input is 3.0 volts.(full scale)
    y = (1.633 * 3) - 0.98
    y = 3.92

    Now convert this to an 10 bit PIC resolution.

    10 bits ADC = 0 to 1023, 1024 steps.
    At 3.0 volts one volt of input will will read 341.
    Spanning 2.4 volts or 818 steps (2.4 * 341).

    New value for m. 3.92 / 818 = 0.00479
    m = 0.00479


    The new offset starting at 205, (0.6 * 341).
    205 * 0.00479 = 0.98
    b = 0.98


    y = (ADC * 0.00479) - 0.98
    ADC = 1023
    y = 3.92kpa

    ADC is from the sensor.

    Now for some code.
    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
       
    
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    Fianlly have usable numbers to work with, had some issues using a 3.3v reference as the sensor only works to 3V so I bought a LM317 adjustable reg and got it set to 3.00V, now it is working as per you calculations, :-) only thing im need to change a bit is the air density constant based on the altitude, temp and humidity.

    the reveal, :-) basically what I am doing with this sesnor and program is setting it up in my RC plane to drop the flaps in relation to the airspeed, so as the airspeed decreases the flaps increase, and then as airspeed increases the flaps decrease. was driving in the car with the GPS, PIC and 2 servos connected and they seem to be reacting as I want them.

    Will post a clip when I get a second hand to hold the cammera while I drive, :-)

    Kind regards
    Rob

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default

    Hi, bobbo

    Some diving bomber planned ???

    I hope not the " Stuka syndrom " ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    lol, nope, just a lazy pilot and like automating as much as possible, :-), if I could figure out how to do an inflight re-fuel I would be quite happy, :-)

  13. #13
    Join Date
    Mar 2010
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Next thing will be to use a sensor to turn on nav lights automatically, :-)

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