MPXA4115A picbasic code


Closed Thread
Results 1 to 40 of 104

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Scalerobotics

    Could you tell us what it shows for some close to another calibrated pressures ( water column i.e.) I'm really curious about this "oversampling method" application ...

    And moreover after having carefully read the relevant AN 1152 from Microchip ...

    Alain

    " Surely overpaid Engineer ... ( lol ) , but Graduate Engineer ... "
    ************************************************** ***********************
    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 " !!!
    *****************************************

  2. #2
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    @Acetronics
    VERY good infos in AN thanks for sharing!

    @ Scalerobotics

    You have done excellent job That was exactly I was thinking to do trying oversampling on 12f pics! so you did the job for me THANKS!

    So the conclusion is that we can use 12f675 ir 12f683 as I want to just measure an alt difference of 200m

    I did some calculation and I have attaches 2 XL one is the previous 10,12,14bit calculation and bolded out the 200m measurements just to see what is going on and the second one is use pic 10bit ADC but with Dual AMP LMC662 (Acetronics suggestion) to give a narrow-window measurements and the resolution improved to about 4m .

    Also attached a fast schematic of my thoughts (not checked , improvements are welcome!)

    Final conclusion I take the amp route or MPX connected directly to pic (with oversampling). I think as I will only want to measure 200m difference. the pcb must/and can be kept simple (low weight) and low part count.

    (dual amp trick: first subtracts 2.5V from MPX vout and the result is multiplied by 3 , so we have a range just from
    0-2300meters but better resolution for 10bit pic adc -see AZAltitude10bit_DUALAMP.xls)

    Scalerobotics about oversampling on 12f do you think you can 'go with' just the internal 8Mhz rc oscilator or it will not do the trick?!
    Attached Files Attached Files
    Last edited by bitmaniac; - 4th June 2009 at 11:03.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    bitmaniac, Check your J1 and J2 power wiring....

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dave View Post
    bitmaniac, Check your J1 and J2 power wiring....

    Dave Purola,
    N8NTA
    Oh! you have a sharp eye!
    I told you it was a fast schematic he!he!

    corrected.

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bitmaniac View Post
    Scalerobotics about oversampling on 12f do you think you can 'go with' just the internal 8Mhz rc oscilator or it will not do the trick?!
    You can go with the internal, but at least on the 12F675 you have 4mhz internal, so your conversions are a little slower. See the TAD vs device operating frequencies part of your schematic. 1.6 us if fastest. Looks like 4mhz would be 2.0 us. So as long as you are not using 16 bit, you probably won't notice the difference in speed, and you will save one more part in your part count.
    http://www.scalerobotics.com

  6. #6
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    @scalerobotics

    I have import your code to Proteus Sim and playing around with your code.

    It seems to work ok (I have to use meters instead of feets here ).

    My MPX4115A arrived yesterday (4pieces) so it is time to make the real thing and figure out how it works. I am going to use my schematic ommiting the opamp and hope oversampling method works (12f683,internal 8Mhz,MPX,3caps -> total part count 5!)

    For the moment I put everythimg in SIM (i used 12f683 with internal 8Mhz) and here what I found:
    According to simulation at 50.400kPa I read 17646 feet ALT (lower limit) and
    at 99.900kPa I read 5 feet ALT (upper limit) that is with this code we measure aprox. 49,500Kpa difference. (two screenshots attached)

    Note: We must also use calibration data and/or Level0 default presure

    (Please note that in the sim I can only vary sensor kPa in .100 increaments)
    Attached Files Attached Files
    Last edited by bitmaniac; - 5th June 2009 at 08:22.

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Sounds good. If you beat me to it, try it with and without C3. I am guessing it may work better without it. If not without, it may work best with a much smaller capacitor. That defies most filtering logic, but I think oversampling likes a little bit of noise. I can't find my 470pf, but I know they are around here somewhere.....
    Last edited by ScaleRobotics; - 5th June 2009 at 08:36.
    http://www.scalerobotics.com

  8. #8
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    .....I can see your 470pf.... over there... yes there.....next to your Pickit2 he!he!

  9. #9
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    3d visualization of a test pcb attached...

    As you notice I didn't care much about the placement of sensor caps.
    Just wanted to see the size of the board and best placement of connectors

    (pcb measured... 45mm X 30 mm)

    PLEASE NOTE all connectors will be male (not as seen) except for the sensor that it will be soldered on board
    The sensor will be layed above C3 C2 and C1 (low profile cap)
    Attached Images Attached Images  
    Last edited by bitmaniac; - 5th June 2009 at 11:47.

  10. #10
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Scalerobotics

    Could you tell us what it shows for some close to another calibrated pressures ( water column i.e.) I'm really curious about this "oversampling method" application ...

    And moreover after having carefully read the relevant AN 1152 from Microchip ...
    At my location and 14 bits, I get an output of 13255. This calculates to a pressure of 1004.86 mBar, and an altitude of 229.85 feet. I don't have a barometer here, so I can't really give you a side by side comparison on the figures. On the internet, it said a nearby weather barometer read 1014.42. But I think this is more a function of the accuracy of the MPX4115a, and to a bigger extent (since I don't have a calibrated barometer side by side) my altitude. The altitude from my calculations seem very close. I think I am between 250 and 285 feet altitude.

    Oversampling is really just a form of averaging. So it can't skew your results. At worst, you could have no noise in your A/D conversion, which would give you a 10 bit result with lots of useless bits to the right. Once I find a 470pf capacitor around here, I plan to test results again. I think this will filter the result a bit too much, and take away some of the needed noise. Here, white noise is our friend.

    On a side note, at 16 bits, when you watch the results at first power up, you can really see the effects of the MPX4115a and maybe the PIC12F675 warming up. For about two minutes the values really move!
    Last edited by ScaleRobotics; - 4th June 2009 at 17:36.
    http://www.scalerobotics.com

  11. #11
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Altitude from lookup example PIC12F675

    Here's a little code to calculate altitude from 0 to about 17,000 feet. I could not quite fit the full 85 value lookup2 table without getting some errors, so it is more of a 74 value lookup table. I may try a 74 value lookup table that covers the range to 36,000 feet later. Also will not work for Death Valley where the altitude goes to negative.

    It is a pretty short program. I am using about 900 words of the PIC12F675 though, so not much space left over. Have not tested it too much, so if anyone finds issues, let me know.

    Code:
    DEFINE OSC          20
    INCLUDE "DT_Analog.pbp"     ; DT's 16-bit Analog Module
    
    DEFINE ADC_BITS     10  '10 BIT A/D CONVERSION RESULT
    DEFINE ADC_CLOCK    2   '
    DEFINE ADC_SAMPLEUS 5  'SET SAMPLE TIME IN MICROSECONDS
    
    
    CMCON = 7               'TURN COMPARATORS OFF
    TRISIO = %000100        'Set GSIO 0 INPUTS, others to OUTPUT
    ANSEL = %00100100 	    '
    ADCON0.7 = 1	        'Right Justify for 10-bit
    ADCON0 = %10001001 
    
    ADbits = 14                ; set to 14-bit resolution
    
    
    DEFINE DEBUG_REG	GPIO
    DEFINE DEBUG_BIT	0
    DEFINE DEBUGIN_BIT	1
    DEFINE DEBUG_BAUD	2400
    DEFINE DEBUG_MODE	0
    ALTresult var word       'lookup table output
    tempALT var word         'base altitude of lookup from table
    ADtemp var byte          'lookup table input
    ALTdifference var word   'difference of two nearby altitudes
    finalALT var word        'final calculated altitude in feet
    
    ;---------------------------------------------------------------------------
    Main:
        ADchan = 2       ; Do only AN2 channel
        GOSUB GetADC            ; Get A/D value
        ADtemp = (ADvalue/100) - 60 ' get to table acceptable value for lookup
        gosub lookmeup
        tempALT = ALTresult   'save first result for use in math
        ADtemp = ADtemp - 1  'run another lookup for nearby altitude for diff calc
        gosub lookmeup
        ALTdifference = ALTresult - tempALT   'get difference in nearby alt
        finalALT = tempalt - (((ADvalue//100)* ALTdifference)/100) 
        'use difference to calculate slope & adjust altitude accordingly
        debug "Alt= ",DEC finalALT," A/D= ",DEC ADvalue,"   "
        pause 1000
    GOTO Main:
    
    End
    
    lookmeup:
    lookup2 ADtemp,[_
    17646,17327,17011,16699,16389,16083,15780,15480,15183,14888,14597,14308,14022,_
    13739,13458,13179,12903,12630,12359,12090,11823,11559,11297,11037,10779,10524,_
    10270,10018,9769,9521,9275,9031,8789,8549,8310,8074,7838,7605,7373,7143,6915,_
    6688,6463,6239,6017,5796,5577,5359,5143,4928,4715,4502,4292,4082,3874,3667,_
    3462,3257,3054,2852,2652,2452,2254,2057,1861,1666,1472,1280,1088,898,708,520,_
    332,146],ALTresult
    return
    Last edited by ScaleRobotics; - 4th June 2009 at 23:33.
    http://www.scalerobotics.com

Similar Threads

  1. sample code for AT45DB642D in Picbasic Pro
    By itsssyam in forum General
    Replies: 0
    Last Post: - 10th March 2010, 06:01
  2. 16f887 44 pin demo board code problem?
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th December 2008, 14:17
  3. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  4. PicBasic code problems with a 16F84A
    By Lauren Barta in forum mel PIC BASIC
    Replies: 3
    Last Post: - 30th May 2006, 22:50
  5. PicBasic Fundamentals
    By Billyc in forum General
    Replies: 9
    Last Post: - 4th May 2004, 10:04

Members who have read this thread : 0

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

Posting Permissions

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