PDA

View Full Version : MPXA4115A ADC vref set_up



iw2fvo
- 4th August 2009, 16:29
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

Darrel Taylor
- 4th August 2009, 17:49
You've set PCFG here ...
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...
ADCON1.3=0
Which puts PCFG at 0111, (all digital).
<br>

iw2fvo
- 4th August 2009, 20:37
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

Darrel Taylor
- 5th August 2009, 16:45
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>

iw2fvo
- 5th August 2009, 19:04
Hi Darrel,
thanks a lot for your usefull answers on the matter.
That is great.
regards,
Ambrogio
North Italy