PDA

View Full Version : Strange A/D conversion...



Christos_K
- 31st May 2005, 02:17
Hi all! Have been trying to do a 10bit A/D conversion using a PIC16f876 but something strange happens...I have a working circuit and send the result through RS232 to my pc...I use a potentiometer with the two ends connected at Vdd and GND and the other end is connected to PORTA.0...Look at some measurements i did..The first values are from my digital multimeter and the second values are the decimal value of the a/d conversion variable...

5V --> 1023 (5v)
4V --> 785 (3.8v)
3V --> 552 (2.7v)
2V --> 300 (1.47v)
1v --> 65 (0.3v)
0v --> 0 (0v)

As you can see the A/D conversion can show the max and minimum values but it is lost in between..
Here is my code(reference votlage is set to Vdd = 5V):

DEFINE HSER_RCSTA 90h '
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 129
DEFINE HSER_CLROERR 1

DEFINE OSC 20

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 2 (tried 3 but didn;t work)
DEFINE ADC_SAMPLEUS 50 (tried increasing but didn;t work)

adcdata var WORD
trisa = %11111111

ADCON1 = %10000010

main:

ADCIN 0, ADCDATA

hserout [dec ADCDATA ,13]

pause 1000

goto main


What can be wrong?? I 've also tried a version where you manual set the conversion to start and checking the bit2 of adcon0 etc etc but same results...
Also tried with 3.3V reference voltage at PortA but still no luck...

mister_e
- 31st May 2005, 03:33
could be some noise on the pot wiper. Have you place a capacitor between PIC input and gnd? What is the impedance of your POT. Should be less than 10K if my memory is good for that PIC.

Also, make sure your supply line is neat.

Ingvar
- 31st May 2005, 09:22
I suspect a wiring problem since your conversion is dead straight(see ADcurve.gif) with an offset of about 0,75v. That's close to a normal voltage drop over a diode or transistor.

Christos_K
- 4th June 2005, 22:28
Problem solved! Indeed it was wirring problem! Another question now, What do the values for Define ADC_CLOCK repesent and how are they different?

I know that you can have ADC_CLOCK 0,1,2 or 3...What does its number correspond to?

Melanie
- 5th June 2005, 01:35
The value selects the source of the ADC conversion clock. For a detailed answer to this, look at "Selecting the ADC Conversion Clock" sub-section, in the ADC section of your chosen PICs Datasheet. Some newer PICs have a wider selection range than provided by the DEFINE, in those cases it's best to select by presetting the Registers yourself. If you are unsure what source to use, the RC option (which is an internal ADC option and nothing whatsoever to do with the PICs main Oscillator) is always a safe bet.