CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F14K22 very inaccurate ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
doctorprox



Joined: 09 Nov 2010
Posts: 7
Location: UK

View user's profile Send private message

18F14K22 very inaccurate ADC
PostPosted: Tue Nov 09, 2010 3:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 3:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 4:00 pm     Reply with quote

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: 19236

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 4:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 4:30 pm     Reply with quote

@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

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 4:35 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group