MPXA4115A ADC vref set_up


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default MPXA4115A ADC vref set_up

    Good day to all at the forum.
    I am going to set up the AN_0 to read a voltage of around 3.5 VDC and so I plan to use the Vref + connected to 5vdc an Vref - Connected to +2.5Vdc.
    The PIC used is the 18F452 running at 40 Mhz clock.
    I did the wiring in this way:
    > AN0 pin_2 connected to the signal input ( 3.5 Vdc )
    > AN3 ( Vref + ) pin_5 connected to 5Vdc
    > AN2 ( Vref - ) pin_4 connected to a resistor divider that gives 2.5 Vdc.
    I suppose that the ADresult will be "0" count at 2.5 Vdc input ( pin_2 )
    and the ADresult has to be "1023" counts at 5.0 Vdc input at pin_2.
    I wrote a small picbasic program but it seems to me that Vref - is not taken into account. It does not work !
    Thanks for any help .
    regards
    Ambrogio
    Here is the program:

    ' AD converter set_up.

    ' analog input on AN_0 pin_2
    ' Vref+ AN_3 on pin_5
    ' Vref - AN_2 on pin_4

    TRISA = %11111111 ' port A set to all INPUT

    ADCON1.3 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+) PCFG= 1111
    ADCON1.2 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
    ADCON1.1 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
    ADCON1.0 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)

    ADCON0.0=1 ' ad = ON

    'CLOCK CONVERSION

    ADCON1.6=1 'ADCS2
    ADCON0.7=1 'ADCS1
    ADCON0.6=1 'ADCS0

    ' ANALOG INPUT SELECTION an_0

    ADCON1.5=0
    ADCON1.4=0
    ADCON1.3=0

    'RIGHT JUSTIFIED

    ADCON1.7 = 1 ' Right justified.

    'DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
    'DEFINE ADC_CLOCK 3 ' ADC clock source
    'DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec)

    ADVAL VAR WORD
    P VAR WORD
    ADC_FLAG VAR BIT

    MAIN: '------------------------------------------------------------


    GOSUB RD_CLOCK_CALEN ' LETTURA CLOCK CALENDAR:
    IF SEC <> SEC_OLD then ' EVERY SECOND...
    GOSUB DISPLAY_CLOCK_CALEN
    ADCON0.0=1
    ADCON0.2=1 ' START CONVERSION > GO/_DONE
    ADC_FLAG=1 '
    ENDIF

    IF ADC_FLAG=1 THEN
    IF ADCON0.2=0 THEN ' WAIT FOR ADC_DONE

    DEBUG DEC ADRESH," " , DEC ADRESL,13,10
    ADVAL=ADRESL+(256*ADRESH)
    P=ADVAL*5432
    P=DIV32 1000
    P=P+6611
    DEBUG 13,10,"adval=",dec adval," P=",DEC P/10,".",DEC1 P//10," mBar",13,10
    ADC_FLAG=0
    ENDIF
    ENDIF
    GOTO MAIN

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You've set PCFG here ...
    Code:
    ADCON1.3 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+) PCFG= 1111
    ADCON1.2 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
    ADCON1.1 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
    ADCON1.0 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
    Then changed one of those bits again...
    Code:
    ADCON1.3=0
    Which puts PCFG at 0111, (all digital).
    <br>
    DT

  3. #3
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    thanks for the reply.
    I do have to apologize for my own error.

    I will like another couple of questions if I am not so tedious:
    How to set the clock conversion ADCS0 through ADCS2 bits ?
    The ADresult change if I set Fosc/2 : what is the correct one ?

    I have two sensors MPXA4115A in my hands now: is it reasonable to have a difference of 8 mBar between the two ? What is your experience ?

    Thanks a lot for the assistance
    Your is a great help .
    regards,
    Ambrogio
    Italy

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The idea is to get Tad (1 period of the A/D clock) as close to 1.6uS as possible (without going under). Which gives 625,000hz to the converter.

    For a main oscillator of 40Mhz ...
    take 40,000,000 / 625,000 = 64. So FOSC/64 is the proper selection @ 40Mhz.

    @ 24Mhz ... 24,000,000 / 625,000 = 38.4
    38.4 is between 32 and 64, so you take the highest of the two numbers, and at 24Mhz you also need FOSC/64.

    So that you don't have to calculate it each time, here's a table I made of the recommended settings for most oscillator frequencies.

    If using PBP's ADCIN statement, just use the highlighted numbers in the DEFINE ADC_CLOCK statement in your program.
    If manipulating the A/D converter manually, you'll need to encode the number into the ADCONx registers which varies between PIC families.

    <table cellspacing="1" cellpadding="3" border="1"> <thead> <tr> <th scope="col" align="center">OSC</th> <th scope="col" align="center">DEFINE ADC_CLOCK</th> <th scope="col" align="center">Clk source</th> <th scope="col" align="center">Tad (µs)</th> <th scope="col" align="center">12 Tad (µs)</th> </tr> </thead> <tbody> <tr> <th style="text-align: center">4</th> <th style="text-align: center"><span style="color: #ff6600">1</span></th> <th style="text-align: center">Fosc/8</th> <th style="text-align: center">2</th> <th style="text-align: center">24</th> </tr> <tr> <th style="text-align: center">8</th> <th style="text-align: center"><span style="color: #ff6600">5 / 2 </span><sup><span>(2)</span></sup></th> <th style="text-align: center">Fosc/16</th> <th style="text-align: center">2 / 4</th> <th style="text-align: center">24 / 48</th> </tr> <tr> <th style="text-align: center">10</th> <th style="text-align: center"><span style="color: #ff6600"><span style="color: #ff6600">5 / 2 </span><sup><span><font color="#000000">(2)</font></span></sup></span></th> <th style="text-align: center">Fosc/16</th> <th style="text-align: center">1.6 / 3.2</th> <th style="text-align: center">19.2 / 38.4</th> </tr> <tr> <th style="text-align: center">12</th> <th style="text-align: center"><span style="color: #ff6600">2</span></th> <th style="text-align: center">Fosc/32</th> <th style="text-align: center">2.6</th> <th style="text-align: center">31.2</th> </tr> <tr> <th style="text-align: center">16</th> <th style="text-align: center"><span style="color: #ff6600">2</span></th> <th style="text-align: center">Fosc/32</th> <th style="text-align: center">2</th> <th style="text-align: center">24</th> </tr> <tr> <th style="text-align: center">20</th> <th style="text-align: center"><span style="color: #ff6600">2</span></th> <th style="text-align: center">Fosc/32</th> <th style="text-align: center">1.6</th> <th style="text-align: center">19.2</th> </tr> <tr> <td style="text-align: center">24</td> <td style="text-align: center"><span style="color: #ff0000">6</span></td> <td style="text-align: center">Fosc/64</td> <td style="text-align: center">2.6</td> <td style="text-align: center">31.2</td> </tr> <tr> <td style="text-align: center">32</td> <td style="text-align: center"><span style="color: #ff0000">6</span></td> <td style="text-align: center">Fosc/64</td> <td style="text-align: center">2</td> <td style="text-align: center">24</td> </tr> <tr> <td style="text-align: center">40</td> <td style="text-align: center"><span style="color: #ff0000">6</span></td> <td style="text-align: center">Fosc/64</td> <td style="text-align: center">1.6</td> <td style="text-align: center">19.2</td> </tr> <tr> <td style="text-align: center">48</td> <td style="text-align: center"><span style="color: #ff0000">3</span></td> <td style="text-align: center">FRC</td> <td style="text-align: center">~4</td> <td style="text-align: center">~48us</td> </tr> <tr> <td colspan="5" style="text-align: left"><sup>(2)</sup> Most <span style="font-size: 12px">16F's don't have Fosc/16 (<span style="font-size: 12px"><span style="color: #ff6600">5</span></span>). Use Fosc/32 (<span style="font-size: 12px"><span style="color: #ff6600">2</span></span>) instead @ 8-10mhz</span></td> </tr> </tbody></table>
    It takes 12 Tad to complete 1 Analog to Digital conversion.

    I have two sensors MPXA4115A in my hands now: is it reasonable to have a difference of 8 mBar between the two ? What is your experience ?
    They have a maximum error of 1.5% full scale.
    The scale goes from 150 mBar to 1150 mBar or 1000mBar, and 1.5% of that is 15 mBar.

    So it sounds like yours are within tolerances.
    <br>
    DT

  5. #5
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,
    thanks a lot for your usefull answers on the matter.
    That is great.
    regards,
    Ambrogio
    North Italy

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. ADC Vref
    By srob in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th April 2008, 18:07
  3. I2C Slave, config Vref - + in pic with ADC
    By sebapostigo in forum PBP Wish List
    Replies: 4
    Last Post: - 5th March 2007, 03:21
  4. Using VREF with 16F88
    By jpeakall in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th May 2005, 19:06
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 1

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