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 CCS Technical Support

Problem using ADC

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



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

Problem using ADC
PostPosted: Mon Feb 21, 2011 2:58 am     Reply with quote

Hi,

I'm using the PIC18F2620 with 20mhz and have problems using the ADC. Compiler version 4.093

Whenever I try using the analog input, I notice there will already be a voltage of 4.79V there. Vdd is 4.93V

The problem is when I connect the analog input pin to any nodes on the circuit, its voltage level changes.

I've tried various settings but this problem still occurs. This is my settings
Code:

setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(AN0);
set_adc_channel (0);


Can someone help me out? What am I doing wrong? Do I need additional circuitry to use the adc?

Btw if I connect the AN0 pin to Vdd or ground, it will show 1023 and 0 respectively.
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Feb 21, 2011 3:34 am     Reply with quote

First, your ADC clock is too fast. Won't cause the problems you are describing, but won't help....
Clock/16, is the fastest divisor for a chip running at 20MHz, Look at table 19-1 in the data sheet. Also note that if you have the LF device (rather than the F), this needs to double again.

Now, the ADC input, is basically a capacitor, in series with a couple of resistors, so _will_ have some affect on circuitry, unless it has quite a low impedance. The maximum recommended source impedance, is 2.5KR, for your chip. So tell us more about your source?. There is a leakage current, of about 0.1uA, but this is to 0v, not to +ve.
So, the description to me suggests you may have a fine solder whisker, or something resistive in the circuit round the pin, actually pulling it up to another signal. Scrub the area down with a toothbrush and alcohol, and get a magnifying glass on the connection....

Best Wishes
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Mon Feb 21, 2011 6:47 pm     Reply with quote

HI,

The source is a LEM current transducer LA 55-P. It outputs current, so I've placed a resistor of 1K to get a reading. Using a multimeter, I can get it, but not with the PIC.

I also noticed that when I tried it with a simple voltage divider circuit using a 1k resistor and 10k potentiometer, the same thing happened. However,
I then added this command :
Code:

setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(AN0);
set_adc_channel (0);
output_float(pin_a0);


Then I could get the proper reading of the voltage from the divider. And it doesnt affect the voltage levels anymore.

In any case its a bit odd that I had to set the output to float after already selecting it as an analog input.
Is there some other setting I'm missing out?

However that doesn't seem to work with the current sensor. The voltage across the resister increases correctly as the current increases, however the adc reading doesnt increase gradually.

It just remains the same, until it reaches the maximum voltage, then only the value changes to the correct one. In between minimum and maximum, the adc displays the value of the minimum voltage only.

The transistor that allows current flow through the sensor is controlled by PWM with a frequency of 1.2khz. Could this have some kind of effect on the analog input pin? Because the current flow is switch on and off rapidly
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Tue Feb 22, 2011 3:16 am     Reply with quote

Depends what 'else' you are doing earlier in your code....

All PIC pins wake up floating, so 'output_float', should not be needed.
However a pin set as 'output', _overrides_ the ADC.

So if (for example), you do 'output_a(x)', then this _will_ set the the whole port as an output, unless you select fast_io mode, or fixed_io mode, and you will have to set the analog pin back to 'float'.

Best Wishes
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