Mutliple ADC problem with PIC16F877


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2007
    Posts
    2

    Default Mutliple ADC problem with PIC16F877

    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);
    }

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by mackrackit; - 24th September 2007 at 11:50.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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?
    Last edited by mister_e; - 24th September 2007 at 15:50.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by andyto View Post
    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.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. pic12f675 ADC problem
    By radu022003 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 1st September 2009, 10:13
  2. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  3. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22
  4. 16F876 ADC problem
    By Douwe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th June 2006, 19:38
  5. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts