View previous topic :: View next topic |
Author |
Message |
krasi
Joined: 17 Jun 2009 Posts: 9 Location: Bulgaria
|
ADC channels unwanted crosstalk (solved) |
Posted: Sat Mar 19, 2011 3:36 am |
|
|
Hi,
I am reading several different voltages with the ADC channels on a 18F25k20. And it seems that there is crosstalk between channels which I don't want. My compiler version is 4.093.
I tried all possibilities that I have on mind but no effect. So, what I've tried so far is:
- increasing the time after setting the MUX, from 20us to 100us;
- changing the acquisition time;
- adding same voltage to all inputs;
- disabling the reading;
My hardware is simple: at each analog channel I have a resistor divider like 1.2kOms in serial of the input and 10kOms in parallel of it. So my input impedance is below max allowed specified in the datasheet.
I post the simple test program that I used and still have the crosstalk.
Code: |
#include <18F25k20.h>
#device ADC=10
#FUSES HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=16M, oscillator=4M) // 4Mhz Crystal is Used with enabled PLL (x4)
void main(void)
{
int16 value;
// ADC SETUP
setup_adc_ports(sAN0|sAN1|sAN2|sAN3);
setup_adc(ADC_CLOCK_DIV_16|VSS_VDD); // 1us Tad
//setup_adc(ADC_CLOCK_DIV_32|VSS_VDD); // 2us Tad
while( TRUE )
{
set_adc_channel(0);
delay_us(100);
value=read_adc(); // take a read from ADC
delay_ms(2000);
set_adc_channel(1);
delay_us(100);
value=read_adc(); // take a read from ADC
delay_ms(2000);
set_adc_channel(2);
delay_us(100);
value=read_adc(); // take a read from ADC
delay_ms(2000);
set_adc_channel(3);
delay_us(100);
value=read_adc(); // take a read from ADC
delay_ms(2000);
}
}
|
Disabling lines with read_adc(), also have no effect, so I think the problem is somewhere in the MUX settings, but I can't figure it out.
I tried the same program with PIC18F2580 and it works perfect.
I'm stuck in this, so any ideas are welcome.
Thanks in advance.
Krasi
Last edited by krasi on Sat Mar 19, 2011 8:49 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Sat Mar 19, 2011 5:33 am |
|
|
Ok, I'm not using those PICs but
These lines...
setup_adc_ports(sAN0|sAN1|sAN2|sAN3);
setup_adc(ADC_CLOCK_DIV_16|VSS_VDD);
can be combined into one
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|setup_adc(ADC_CLOCK_DIV_16|VSS_VDD);
Maybe the compiler is using the last setup_adc(..); and resetting sANn selection. You'ld have to check the listing to see if the correct bits are set/reset.
I've always combined all options into one directive and never had a problem. |
|
|
krasi
Joined: 17 Jun 2009 Posts: 9 Location: Bulgaria
|
|
Posted: Sat Mar 19, 2011 7:35 am |
|
|
Ok, I've checked the option with combined lines, but an error appears - "A numeric expression must appear here".
I checked the listing file as you mentioned, but everything seems to be normal.
So, I'm keep searching for a decision. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Mar 19, 2011 7:59 am |
|
|
Quote: | it seems that there is crosstalk between channels which I don't want. |
I would prefer some more substantial information. How do you determine the crosstalk? What's the voltage at all involved ADC pins in this situation? Can you exclude interferring signals at other pins or an unstable supply/ADC-reference? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Sat Mar 19, 2011 8:34 am |
|
|
oops
it should be..
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|ADC_CLOCK_DIV_16|VSS_VDD);
for some reason it looked fine when I cut and pasted it,
hopefully it'll look right this time.
there should be a vertical bar(| ) between each option; |
|
|
krasi
Joined: 17 Jun 2009 Posts: 9 Location: Bulgaria
|
Problem solved! |
Posted: Sat Mar 19, 2011 9:03 am |
|
|
The problem is solved already.
Thanks to all of you for your ideas and especially to FvM. When he mentioned: Quote: | Can you exclude interferring signals at other pins or an unstable supply/ADC-reference? | I start thinking and discover my problem.
Because I used an old PCB made for 5V PIC, most of my inputs were 5V tolerant. So, for 25k20 which is 3V PIC, I've changed all necessary pins to 3V, and forgot the others. So, there was 5V applied to few pins which acts like digital inputs. And in this case the internal protection diodes were triggered and the result was changed Vreff and so on, and so on.
That's why I measured different value every time, although I was applied same voltage to all analog pins.
Thanks again for your help. |
|
|
|