PDA

View Full Version : Mutliple ADC problem with PIC16F877



andyto
- 24th September 2007, 08:22
Hello everyone, I have encountered the problem of using dual/multiple ADC inputs into PIC. Since I am using 2 ADC channels, the output I receive is always of the higher pin ( eg. If I am using pin RA1 & RA0, only the conversion of RA1 is received in my LCD display; hence there is a replica of digital values. ) There seems to be an overwrite of the RA1 over RA0. This problem persist when I am using different input pins.

The below mentioned is the code for ADC reading and initialisation. :

Thank you for your help.


void ADC_init() // for init of ADC
{
ADCON1=0x82;
TRISA=0xff;
}

int read_ADC_channel(unsigned int channel_number) // for reading
{
int value;
switch(channel_number)
{
case 0:
ADCON0 = 0b01000011;
case 1:
ADCON0 = 0b01001011;
default:;
}
DelayMs(1);

ADGO=1; //start AD conversion
while(ADGO) //wait for conversion to finish
{};
value=(ADRESH<<8)+ADRESL; //read the values in the registers

return(value);
}

mackrackit
- 24th September 2007, 11:47
Why are you posting code in "C"? on a PIC BASIC forum?

If you are not using PIC BASIC give it a try. You will find it much more user friendly.

andyto
- 24th September 2007, 12:16
I am sorry about not using BASIC, but because I am currently on a school project and we are restricted to C or Asm only therefore. I can't use it. Hope you can understand that.

mister_e
- 24th September 2007, 15:46
Hi,
i'm a bit rusty but i think it 'should' work. I would check the analog source impedance. It should be bellow 10K. Could also be a bad clock conversion choice, variable type, etc etc.

But yeah... sure i miss something obvious. I can't check the whole thing here for some reasons, but as Mackarit suggest, you should go on the according forum for a better answer.

Out of curiosity, which C compiler are you using?

mackrackit
- 24th September 2007, 17:02
I am sorry about not using BASIC, but because I am currently on a school project and we are restricted to C or Asm only therefore. I can't use it. Hope you can understand that.

I understand, I would help and so would many others, but most of us do not use C or at least not very often.

Have you tried the http://www.piclist.com/techref/piclist/index.htm ?

When I was doing ASM I hung out there.

Srigopal007
- 3rd October 2007, 17:47
This will not work because if you read the datasheet of the microcontroller.. it specifically mentions that you must have 10 microsecond delay when switching from channels. This is an absolute must, because the processor requires a delay from switching drivers from one ADC channel to another. This is just my assumption.

-Srig