Often with multiple channels, you will be sampling then all at the same rate, which you would like to be as high as possible. Now that you know you need to allow for sampling time, reread the data sheet carefully and you will find that you can overlap the sampling time of the next channel with the conversion time of the current channel. So the highest sample rate can be achieved by: Start conversion of current channel Switch the input mux to the next channel Wait for the conversion to complete (Maybe doing something useful along the way, like processing the previous channel's data) Store the results of the conversion > -----Original Message----- > From: Bob Ammerman [mailto:RAMMERMAN@PRODIGY.NET] > Sent: Tuesday, April 03, 2001 6:22 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Trouble w/multiple AD inputs (F877) > > > You must insert a delay between selecting the channel and starting the > conversion to allow the sampling capacitor to charge to the > selected input. > You have leftovers from the other channel on the cap when you > start the > conversion. > > Bob Ammerman > RAm Systems > (contract development of high performance, high function, low-level > software) > > ----- Original Message ----- > From: Brian Reed > To: > Sent: Tuesday, April 03, 2001 1:47 AM > Subject: [PIC]: Trouble w/multiple AD inputs (F877) > > > I've been using one A/D input for months and have now expanded > to 3. I must really have something goofy in my code, because the > channels interact with each other. Normally I'd do more testing > before asking here, but I'm going to try and run it at the SME robot > competion this Saturday (near Pittsburgh), so I wanted to ask if my > error is obvious... > > This is what use to work, with the ICD demo board and the pot on RA0: > void AD_init(void) > { > OPTION = 0x87; // Set TMR0 prescaler, and 1:256 > ADCON1 = 0x0E; // Left justify result, 1 analog channel > } > and > unsigned char AD_RA0(void) > { > ADCON0 = 0x41; // Fosc/8, A/D enabled > ADGO = 1; // Set the bit to start the > conversion > while (ADGO) // Wait for the conversion > to complete > continue; // > return ADRESH; // Return the AD value (just > the top 8 bits) > } > > Problem is, now that I've taken ADCON1 to 0x02 (for 5 D/A inputs and > 3 digital I/Os, with Vdd&Vss as Vref's), the output of > AD_RA0() does not > vary through the full range, and is greatly affected by input on RA1. > Yipes! Only when I turn RA0 and RA1 all the way up do I get > a full-scale > A/D reading on RA0. > > Here's the current code - likely this has the problem ---> > > /// PICLIST: note the change in ADCON1 > void AD_init(void) > { > OPTION = 0x87; // Set TMR0 prescaler, and 1:256 > ADCON1 = 0x02; // Left justify result, 3 analog channels > } > > /// PICLIST: note the only difference between AD_RAx() > routines is ADCON0 > unsigned char AD_RA1(void) > { > ADCON0 = 0x49; // Fosc/8, A/D enabled > ADGO = 1; // Set the bit to start the conversion > while (ADGO) // Wait for the conversion to complete > continue; // > //// could/should disable A/D here? (w/ADCON0) > return ADRESH; // Return the AD value (just > the top 8 bits) > } > > unsigned char AD_RA2(void) > { > ADCON0 = 0x51; // Fosc/8, A/D enabled > ADGO = 1; // Set the bit to start the conversion > while (ADGO) // Wait for the conversion to complete > continue; // > //// could/should disable A/D here? (w/ADCON0) > return ADRESH; // Return the AD value (just > the top 8 bits) > } > > while (1) { > uctmp1 = AD_RA1(); // sensor > uctmp2 = AD_RA2(); // sensor > PORTC = AD_RA0(); // Turn on LEDs per POT on ICD demo board > } > > Thanks, > > - Bri > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics