PIC 18F4550 ADC stability problems

Thread Starter

TimothyBlue

Joined Jan 4, 2009
11
I am working with a PIC 18F4550. I am using it to translate an analog voltage to digital and then send that information via the USB port.

This is the snippet of code being used.

OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_REF_VREFPLUS_VREFMINUS & ADC_REF_VREFPLUS_VREFMINUS, 0);

Delay10TCYx(5);
ConvertADC(); //START ADC Conversion
while( BusyADC() ); // Wait for ADC conversion

buffer[0] = ADRESL;
buffer[1] = ADRESH;

CloseADC(); // Disable A/D converter


The PIC is using an external 20mHz crystal.
The voltage applied to Vref+ is 5V and at Vref- it is 0V.
The voltage being applied at AN0 is being read by my multimeter as 1.079V but when I acquire the voltage with the pick I get values that dance around this value. For instance in 20 samples I saw these readings.

220 = 1074.2187 V
221 = 1079.101563 V
222 = 1083.9843 V

I would expect the values to be constant since the input voltage is not varying.

This is my first use of an analog to digital converter and so I do not know if this is as good as it gets or if I am doing something wrong.

Any help would be greatly appreciated.

TIA,
Tim Blue
 

nanovate

Joined May 7, 2007
666
220 = 1074.2187 V
221 = 1079.101563 V
222 = 1083.9843 V
I assume you mean mV here.
This is normal since there is always noise present. Sources of noise and error include the ADC itself, the voltage reference and plain old thermal noise. If you post a schematic of your analog input circuit we "might" be be able to make some suggestions. One thing you can look at is how the "dancing values" are distributed -- create a histogram of a large amount of values. Or is what you are measuring is very slow then you can oversample and average (this assumes the noise is well-behaved)
 

beenthere

Joined Apr 20, 2004
15,819
Your PIC has 10 bit resolution, or just about 5 mv for a 5 volt full scale conversion. Your conversions do not seem to make sense, as the A to D can't measure anything like those resolutions. Your code may have problems with the conversion from the A to D value to engineering units

Quality of your component layout, especially how you handle the digital and analog grounds will have an effect on the performance of the converter, as will the stability of the reference voltage.
 

Thread Starter

TimothyBlue

Joined Jan 4, 2009
11
Nanovate,

Yes, I did mean mV in that post.

I created a schematic of the circuit I am using and have attached it to this post. I am definitely an amateur so please bear with any of my lack of knowledge. You will see a 1mA current source circuit created using a MCP602 op-amp driving my RTD temperature-sensing element. The voltage from this element is sent to the ADC input of the PIC. This RTD is 1000 Ohms at 0 Celsius.

Again, thank you for your help.

Tim
 

Attachments

Alberto

Joined Nov 7, 2008
169
Reset switch as in your schematic will short power supply when pressed! Change wiring!.

Add 100 nF to pin 5 (Vref)

Connect to ground all unused analog inputs.

From schematic I cannot see if your ground connection make a close ring, check carefully your hardware and if you discover it open it!.

I would also connect the two ground points (RTD1 & R7) directly to power supply ground with two separate wires.

A 10 nF capacitor is a better filter for pic Vdd.

One way to overcome small analog fluctuation is to average three or more reading before to display them. This is easily achievable with minor change in your software.

Edited: Check also your code to verify if comparator and usb has been disabled.

Alberto
 
Last edited:

Thread Starter

TimothyBlue

Joined Jan 4, 2009
11
Alberto,

Thank you for the information, I will look at all of those things in the circuit.

My comparator is turned off, but USB is on since I require that for communication with the computer.

My RTD cannot output more than 2.5V due to the circuit being used to drive it. That being said, I would like to scale the ADC from 0-5V to 0-2.5V so that I could have better resolution. I read that the ADC does not work well with less than a 3V delta. I had originally tried tying the same 2.5Vref that I use for the RTD driver circuit to the Vref+ on the PIC but when I did that the numbers were way off.

Tim
 

beenthere

Joined Apr 20, 2004
15,819
Then you can place an op amp in circuit to buffer the RTD voltage and apply some gain. You will need a rail-to-rail op amp if you only have 5 volts available.
 
Top