Searching \ for '[PIC] 16F877A A/D Weirdness' in subject line. ()
Help us get a faster server
FAQ page: massmind.org/techref/microchip/ios.htm?key=a%2Fd
Search entire site for: '16F877A A/D Weirdness'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] 16F877A A/D Weirdness'
2005\10\06@022408 by

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

From: "Palmed GmbH"
> Padu,
>
> give us a code snippet of your port init. This sounds, that your input
isn't
> an input...
>
> A simple test is, to connect a relative high resistor (let's say 100K)
from
> RA0 to GND, if RA0 is really an input the voltage should be 0V. Then
connect
> same R to +5V and RA0 must be +5V.
>
> Peter

Ok, I didn't have an 100k around, so I did it with a 68k. When I measure it
from RA0 to GND, it is zero allright, but when I connect it to +5V, measured
voltage is 1.27V. If I connect RA0 directly to VCC then it goes to 5V, but I
think that would happen no matter what right?

I'm using mikroPascal, which sometimes simplifies lots of things because of
their libraries, but sometimes it screws me up because I have to debug their
libraries for them....

Here's a snippet of pascal:

////////select Vref and analog inputs, in order to use ADC_read
///////////////
ADCON1 :=   0;       // all porta pins as analog, VDD as Vref
TRISA  :=   \$FF;
////////////////////////////////////////////////////////////////////////////
////

and to read I use this command:

Ein := ADC_read(0);

Do I need to do something other than TRISA := FF in order to set RA0 as
input?

I'm gonna try to examine the assembly code generate by mP to see what how
they are initializing the ADC.

Padu wrote:

>Ok, I didn't have an 100k around, so I did it with a 68k. When I measure it
>from RA0 to GND, it is zero allright, but when I connect it to +5V, measured
>voltage is 1.27V. If I connect RA0 directly to VCC then it goes to 5V, but I
>think that would happen no matter what right?
>
Forcing an OUTPUT to +5 quite likely exceeded the current specification
of the pin driver.
It is likely you have damaged the device.
Why it is an output is still a mystery to me.

{Quote hidden}

A good idea!
BTW: What did you assign to ADCON0?

--
*
|  __O    Thomas C. Sefranek   WA1RHPARRL.net
|_-\<,_   Amateur Radio Operator: WA1RHP
(*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

On 5 Oct 2005 at 23:27, Padu wrote:
> 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?

You must apply power to the PIC before putting input signal to it.

Cheerful regards,

Bob

Peter wrote:
>>
Padu,

your inits sound good (even if don't know anything about µPascal, so I hope
:= means a LET or "=" in Basic). 68K is also perfect for this test.

Two things come into my mind:
1. May be you already killed your PIC by hardwiring RA0 to +5V.
2. Are you sure, your PIC is running? Is any LED blinking? If not, there
also would be no init, which could explain.

Peter
<<

Yes, := is assignment in pascal. The pic is working. My program involves LED's, compactflash and USART, everything works fine. Right now everything is on a development board (mikroelektronika easypic2).
On RA1 I have an ACS750 (current sensing) that outputs VCC/2 to VCC levels and I'm reading it perfectly. One test I didn't perform but you reminds me of doing is trying to read the ACS750 on RA0 and see if I get the same results.

I cannot do any tests until next Monday. Today I'm taking off to Vegas to watch the Darpa Grand Challenge :)

Cheers

Padu

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...