PDA

View Full Version : Voltage meassure



Pedro Pinto
- 20th November 2009, 14:07
Hello

I try to meassure the voltage of a lithium 3v Batterie with a PIC 18F4520
on pin PORTA.0, AN0 trough a 100k serie resistor


' Define parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result
TRISA.0 = 1 'PORTA.0 as input
ADCON1 = %10001110 ' PORTA.0 analog and right justify result

ADCIN 0, adval ' read the chanell 0
Serout2 tx_485,bmode,["Bat Voltage = ",Dec adval,13,10]

Like the Define ADCON1 the Ref. is the VDD and that is 5.3V
The adval result value show 56704, that can't be correct, or?

What make i wrong?

Thanks for help

Best regards

Pedro

Acetronics2
- 20th November 2009, 15:12
What make i wrong?


answer 1) is in the question ...



AN0 trough a 100k serie resistor


Look at the datasheet ... ADC section ...

Alain

Pedro Pinto
- 20th November 2009, 17:40
Hello Acetronics

I want use a 100k serial resistor to reduce the possibility of descharge
the RTC backup Battery trough the PIC pin over the time.

About the value that i read in the adval variable, i donīt know if it's correct and how to calculate 3.1 V.

Regards
Pedro

Gusse
- 20th November 2009, 19:57
What if I use higher input resistance (> 2.5kOhm) than Microchip recommends in datasheet?

"The source impedance affects the offset voltage at the analog input (due to pin leakage current). The maximum recommended impedance for analog sources is 2.5 kΩ. After the analog input channel is selected (changed), the channel must be sampled for at least the minimum acquisition time before starting a conversion."

http://kotiweb.kotiportti.fi/karl-erik.gustafsson/PIC/ACD1.jpg
Internal leakage is ~100nA.

So, what if:
Rs = 100kOhm, V_ain = 5V -> I_in = 50uA
In this case leakage is 1/500 of input current. Should not affect too much.


http://kotiweb.kotiportti.fi/karl-erik.gustafsson/PIC/ADC2.jpg
By calculating Tc with 100kOhm I got 19.6uS, total time should be over 21uS

So, is code below OK or not?

<code><font color="#000000"><b>DEFINE </b>ADC_BITS 8 <font color="#000080"><i>' ADCIN resolution (Bits)
</i></font><b>DEFINE </b>ADC_CLOCK 2 <font color="#000080"><i>' ADC clock source (Fosc/32)
</i></font><b>DEFINE </b>ADC_SAMPLEUS 500 <font color="#000080"><i>' ADC sampling time (uSec)</i></font></code>

This ADC is bit unclear to me and I would like to understand it better.

BR,
-Gusse-