ADC question again


+ Reply to Thread
Results 1 to 13 of 13

Hybrid View

  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

    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

    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

    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

    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

    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

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