View previous topic :: View next topic |
Author |
Message |
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
18F14K22 very inaccurate ADC |
Posted: Tue Nov 09, 2010 3:20 pm |
|
|
Hi all.
I have tried everything to get the ADC on this chip working correctly but it just wont.
It seems to be around 20% out, ie. 2.5v in reads in on the ADC as about 3.1v, and fluctuates all over the place (actual 10bit ADC readings from 610-650 sent by RS232 and also measured externally via PWM).
Power supply is stable at 5.01v
I have tried running off a crystal aswell, makes no difference.
Any help would be MUCH appreciated.
Code: |
#include <18F14K22.h>
#FUSES PLLEN
#FUSES NOMCLR
#FUSES INTRC_IO
#device adc=10
#use delay(internal=64000000)
#use fast_io (ALL)
#use rs232(uart1, baud=38400)
long adcval;
long count;
void main()
{
set_TRIS_A(0b11111111);
set_TRIS_B(0b01111111);
set_TRIS_C(0b01011111);
setup_adc(ADC_CLOCK_DIV_64);
setup_adc_ports(sAN3);
set_adc_channel(3);
delay_us(20);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1);
count = 0;
astart:
count+=1;
If (count==1000){
output_toggle(pin_c7);
count=0;
}
adcval = read_adc();
if (count==500)
printf("%Lu \r\n",adcval);
set_pwm1_duty(adcval);
GoTo astart;
}
|
|
|
|
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
|
Posted: Tue Nov 09, 2010 3:45 pm |
|
|
Seems my multimeter was affecting the input voltage somehow. Changed multimeter and it appears to now be fluctuating around +-2%.
Not ideal since i may aswell be using 8bit in that case. Could this be the internal osc? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 09, 2010 4:00 pm |
|
|
What device is driving the AN3 input pin ? What is the output impedance
of this device (in ohms) ? The 18F14K22 data sheet says:
Quote: |
16.3 A/D Acquisition Requirements
The maximum recommended impedance for analog
sources is 10 Kohms.
|
Also, try reducing the PIC frequency to 4 MHz. Change the ADC divisor
to ADC_CLOCK_DIV_4 for this test. See if it affects the result. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Tue Nov 09, 2010 4:11 pm |
|
|
And (of course), though the power supply may 'appear' stable, it rarely is. Scopes will not tend to show really high frequency noise. Voltmeters won't respond to this. It is 'rare' to get better than perhaps 7-8bit real accuracy using the power supply as Vref (only by ensuring all digital circuits are 'static' during the sampling, and sleeping the processor)...
Best Wishes |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Nov 09, 2010 4:30 pm |
|
|
@Ttelmah, what if the power supply is a battery? _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
|
Posted: Tue Nov 09, 2010 4:35 pm |
|
|
The power supply is actually a PC PSU, probably not the best of supplies.
Anyhow, the input to the ADC was a 1Mohm pot. I have replaced this with 100ohms and the results now seem spot on. Cheers PCM. |
|
|
|