# PIC A/D Weirdness

Maybe I'm doing something wrong, but here's what I'm trying to do.
I'm trying to measure voltage of a battery that can go as high as 16V. I'm
using RA0 set as analog input for the A/D and I'm using Vdd as a reference.
In order to reduce the voltage to compatible levels, I've connected the following voltage divider: from the + side of the battery, I have a 4.7K and then a 2.0K in series going to the - side. Let's say that the battery has 12V across poles. I put my multimeter + probe in between the two resistors and the - probe on the - of the battery. It reads about 3.6V, perfect.
Now I connect my circuit's ground to the ground on the battery to be measured, still 3.6V. The problem happens when I connect my RA0 pin to the divider (same spot where my probe is). Immediately the voltage drops to 2.65V.... why is that? 1V doesn't seem a lot but when I do the math to output the real battery voltage, of course it doesn't match anymore.
What am I doing wrong?
I measured the voltage accross RA0 and ground, it is not zero. I figured that perhaps it is because the pin is set as input and is floating?
Help is very much appreciated
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

I am not specifically familiar with the PIC product line, but your voltage divider sounds like the right approach. What supply voltage is the PIC running on? If it were running on 2.5 volts, I would suspect that you need to re-calculate your voltage divider so that the analog input voltage is lower than the supply voltage. This is pretty standard.
If the PIC supply voltage is 3.3 or 5V, my guess is that the pin is being shared with something and whatever it is being shared with still thinks it is an output or needs a pull down or something. The last time I fooled with an Atmel ARM microcontroller, it was not at all obvious where all the bits were located to get a pin to function as a plain GPIO pin. I can't say whether PIC's are similar in that respect.
As a last guess, see what the input current requirements for the A/D are. I would be pretty surprised if the A/D would load a 4.7K resistor significantly, but it's a place to look.
Good Luck, Bob
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

That seems to make sense. If the A/D circuit introduces a resistance in parallel to the 2k resistor in your voltage divider the voltage measured at your test point will drop. I haven't played with PIC comparators, so I'm not sure what their input impedance is like. Well the current leakage is stated as +/- 500nA so I'm guessing it's high.
If you can work out the input *resistance* of the comparator and it doesn't change with varying input, you can factor that into your calculations
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
"Tim Polmear" wrote

I've been researching about that and I believe that's the most probable thing to be happening. It seems like the input resistance on the pic is around 8K, so I'll try to calibrate my divider taking that in consideration.
A few people have also suggested using a voltage buffer implemented by a given opamp, but I just want to measure the voltage of an almost static signal (the voltage level of a battery), so that may be overkill.
Thanks
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

probable
is
consideration.
AFAIK, the input impedance of the ADC is very much higher than 8K. You were better off when you asked this question on the PICLIST. There are far more experts on PIC usage there than there is in all the electronics newsgroups combined. I suggest you continue responding to the advice that you received there.
What are you putting in ADCON0 and have you looked at the actual assembler output from the pascal compiler? As Mr. Sefranek suggested, you may have damaged the PIC when you hooked RA0 directly to Vcc. It appears as though RA0 was an output pin since it was trying to pull low thru the 68K resistor. When you hooked it directly to Vcc, you would have easily exceeded its maximum current capability. I have killed individual pins on a PIC before, it's not that hard to do. I have also killed a single ADC input without damaging the digital i/o capability of a pin, though I'm not really sure how I managed it.
I strongly suspect that you haven't properly initialized the ADC. I haven't specifically used a 16F877, but I have used PIC ADC inputs and they usually take a bit more initialization than I saw in the program you posted to the PICLIST. Post the assembly output of the compiled program and then we can see what's actually happening.

a
static
It is overkill. You shouldn't need to do that to measure a voltage point.
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

I hesitate to even respond; the results are so screwy that you have to wonder what else isn't right. There aren't too terribly many ways for the node voltage will drop that much (I seem to recall a fair amount more than a diode drop). One way is for the "input" pin to source that voltage. Diagram the node; put a voltage source where your "input" pin is, and write down the voltage and current it would have to be pushing to give those results.

Measuring the direction and magnitude of current in that line would seem the obvious place to start. The next step is just as simple: figure out where it's coming from (or where it's going).
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
On Wed, 5 Oct 2005 21:54:59 -0700, the renowned "Padu"

Your voltage divider has a source impedance of 4K7 || 2K = 1.4K, which is sufficiently low for all PIC family members (for full accuracy over temperature). It's certainly not that. I'll assume your Vdd is more than 3.6V.
I don't suppose there's a hidden 4.0K resistor connected to RA0? It's suspiciously close...
Alternatively, you could have a situation where the RA0 pin is either damaged or rapidly switching between a high-Z state and Vss due to software issues.
What happens if you hold the PIC in reset?
Best regards, Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
snipped-for-privacy@interlog.com Info for manufacturers: http://www.trexon.com
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
"Spehro Pefhany"

It is. To be exact it is 4.99V.

Nope. There is the 12V battery (which is not the power supply for my circuit) with only two wires coming out of it. Between the wires I have the divider, and between the divider resistors I have the wire that goest to RA0.
On a side note, I'm also measuring current of another circuit on RA1. The way I'm measuring is through an current sensing IC (allegro acs750). The allegro shares the same vcc and gnd as my circuit, and it outputs an analog signal in the range vcc/2 to vcc. I don't have a problem reading that signal. There is no significant voltage drop when I connect RA1 to that wire. I'm going to test connecting that signal to RA0 and see if voltage drops or anything weird happens. I guess that would be a reliable test to see if my RA0 is damaged, isn't it?

I'm gonna test it, but only next Monday. I'm going to Vegas in a couple of hours to watch the Darpa Grand Challenge. :)
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
On Fri, 7 Oct 2005 08:25:40 -0700, the renowned "Padu"

It could also be your firmware.
Best regards, Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
snipped-for-privacy@interlog.com Info for manufacturers: http://www.trexon.com
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

## Site Timeline

• ### FA: Lego gearmotors and tracks (conveyor belt links)

• - previous thread in General Robotics Forum
• ### Servo drive signals for HP 7978 tape drive controller

• - last updated thread in General Robotics Forum

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.