PDA

View Full Version : ADC or ADCIN "bias" problem?



RussMartin
- 26th February 2010, 08:25
PIC16F1827 at 32MHz and PBP.

My AN channels, specifically AN5 and AN6, are each connected to the wiper of a different pot giving a voltage range of 0-5VDC.

Based on what I see on the oscilloscope, with 0VDC present on the ANx pin, the ADC for that pin is reading about 60 counts high out of 1023. When I advance the pot, no effect is evident until about 150 counts is reached (i.e., an additional 90).

It does not appear to be a circuit problem; I have checked the voltage on each pin at the millivolt level and even gone so far as to strap each pin directly to the PIC's ground to verify that the pin is at 0VDC. The "bias" is still there. According to my math, I'd need at least 0.3 VDC to account for it.

I suspect, from what I'm seeing, that this also may be occurring on signal channels AN0 through AN4.

Ideas, anyone?

Acetronics2
- 26th February 2010, 08:41
PIC16F1827 at 32MHz and PBP.

Ideas, anyone?

Hi, Russ

3 Ideas ...

1) Your code ?
2) your scheme ?
3) a PCB drawing ?

+/- 2 counts with a 10 bits adc can be considered Ok ... but here ...

You certainly missed something ...

Alain

Melanie
- 26th February 2010, 09:08
Well, if you strap the input to any ADC down to 0v, you get a count of zero... so... it looks like your software configuration of the PIC or the ADC is shot...

1. Make sure your PIC pins are configured for INPUT (TRIS)
2. Make sure your PIC pins are configured for ADC
3. Make sure Comparators (if they share the same pins) are Switched OFF
4. Make sure you have configured VRef+ and VRef-
5. Make sure that if you have set VRef to EXTERNAL you've connected something to them
6. Make sure your sampling time is sufficient for capture
7. Make sure your justification is correct for 8 or 10 Bit mode

If it's similarly happening on multiple channels, then the chances are your PIC pin is good.

If you have a scope, the ADC should faithfully follow what it sees on the PICs pin. I say that, because the first and last 20 degrees of travel on many a junk POT doesn't do much as the wiper travels over the end stop.

RussMartin
- 26th February 2010, 18:11
Alain, I didn't post code, schematic, or board because all three work just fine with a 16F88. Now, except for controlling the output pins (which Darrel solved in http://www.picbasic.co.uk/forum/showthread.php?t=12739), the only issue is this "bias" (or whatever) on the AN channels.

Melanie, I've tried to be sure I've turned off the comparators, the CCP modules, and the capacitive sensing module. I don't know if I've missed something, but here's what I did:

ANSELA= %00011111
ANSELB= %11000000
CCP1CON=%00000000
CCP2CON=%00000000
CCP3CON=%00000000
CCP4CON=%00000000
OSCCON= %11110000
TRISA = %01111111
TRISB = %11000001

ADCON1.7 =1
CM1CON0.7=0
CM2CON0.7=0
CPSCON0 =0

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 6
DEFINE ADC_SAMPLEUS 12

I'll take a look at the Vref matter; maybe that's it. The pots seem okay, with good linear travel and value proportionate to rotation. Remember, I'm seeing the effect with the pins strapped to ground, too.

falingtrea
- 26th February 2010, 18:31
Have you tried just converting one channel and not multiplexing the ADC? I have had issues before because a previous channel precharged the ADC and would see the same kind of "bias" voltage even though the channel being converted is grounded.

RussMartin
- 26th February 2010, 19:39
Once again, Melanie, you've saved my bacon!

It was Vref+ and Vref-. This is what I needed to do:

ADCON1 = %11101000

Bit 2 "0" selects Vss (internal) for Vref-
Bits 1-0 "0" selects Vdd (internal) for Vref+

No wonder the result was screwy!

Thanks!

Tim, thanks for your note, too. I'll remember that as a troubleshooting tip for the future.