f



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

Padu


0
Padu
10/6/2005 4:54:59 AM
comp.robotics.misc 7077 articles. 0 followers. Post Follow

8 Replies
161 Views

Similar Articles

[PageSpeed] 23

Padu wrote:
> Maybe I'm doing something wrong, but here's what I'm trying to do.
> 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?

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
0
MetalHead
10/6/2005 11:41:49 PM
On Wed, 5 Oct 2005 21:54:59 -0700, "Padu" <padu@merlotti.com> wrote:

>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
>
>Padu
>
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

0
Tim
10/7/2005 5:19:03 AM
"Tim Polmear" wrote
> 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
>

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

Padu 


0
Padu
10/7/2005 1:12:39 PM
"Padu" <padu@merlotti.com> wrote in message
news:vLydnZ_8PZ_X6dveRVn-gA@iswest.net...
> "Tim Polmear" wrote
> > 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
> >
>
> 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.

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 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.

It is overkill.  You shouldn't need to do that to measure a voltage
point.

0
Anthony
10/7/2005 1:49:55 PM
"Padu" <padu@merlotti.com> wrote in message 
news:vLydnZ_8PZ_X6dveRVn-gA@iswest.net...
>> 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
>>
>
> 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.

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.

> 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.

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).

0
Mike
10/7/2005 2:42:23 PM
On Wed, 5 Oct 2005 21:54:59 -0700, the renowned "Padu"
<padu@merlotti.com> wrote:

>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
>
>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"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
0
Spehro
10/7/2005 3:01:27 PM
"Spehro Pefhany"
> 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.

It is. To be exact it is 4.99V.

> I don't suppose there's a hidden 4.0K resistor connected to RA0?  It's
> suspiciously close...

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?

> 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?

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. :)

Thanks for the reply

Padu


0
Padu
10/7/2005 3:25:40 PM
On Fri, 7 Oct 2005 08:25:40 -0700, the renowned "Padu"
<padu@merlotti.com> wrote:

> I guess that would be a reliable test to 
>see if my RA0 is damaged, isn't it?

It could also be your firmware. 


Best regards, 
Spehro Pefhany
-- 
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
0
Spehro
10/7/2005 4:20:59 PM
Reply: