Here is the code that I have written based on filter feedback. I think the straight average gives a better result. I am using a 877 and seem to get +/- 1.5bits of random noise without filtering (input is pot tied to +5V, also Vref+ tied to +5V). Is there a better way? Are there any good sites covering this subject? ADC_FILT = 0; // Clear out previous count for (i=0; i<64; i++) { ADIE = 0; // Masking the interrupt ADIF = 0; // Resetting the ADC interupt bit ADRESL = 0; // Resetting the ADRES value register ADRESH = 0; ADGO = 1; // Staring the ADC process while(!ADIF) continue; // Wait for conversion complete ADC_VALUE = ADRESL; // ADC registers are split 2 and 8 bit ADC_VALUE += (ADRESH << 8); // Combined into a single integer ADC_FILT += ADC_VALUE; } ADC_FILT = (ADC_FILT/64)+0.5; // Average of 64 readings to reduce noise // ALTERNATIVE FILTER. Change i to <255 in the for statement above // Comment out 3 lines below and replace with 2 lines below. // Adjust delay in analog1.c // // Software low pass filter to attenuate noise by -12dB // ADC_FILT = ADC_FILT + ((ADC_VALUE - ADC_FILT) * 0.0625); // } if (ADC_Channel == 0) ADC_VALUE = ADC_FILT*4.83;// Scaled to read 0 - 5V else ; // All other channels un-scaled ADC_VALUE = bintobcd (ADC_VALUE); // convert to BCD return (ADC_VALUE); // Return the value of the ADC process Ian ------------------------------------------------------ http://mdm1.bravepages.com Technical support for the Multifunction Display Module ------------------------------------------------------ > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Mike Mansheim > Sent: 27 August 2002 17:26 > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Real newbie question on ADC > > > >>> FILT <-- FILT + (NEW - FILT) * FF > > >> Using your formula and simulating in Excel I always get an offset > >> dependant on FF... > > > The formula was not intended for just integers. It is usually a good > > idea to have enough fraction bits for the bits of shifting implied by > > FF... > > If you're not familiar with fraction bits (newbie reference in subject), > that just means you carry the working data in the upper bits of a longer > variable. For example, if you want to use the full 10 bits of the a/d, > you can use a 16 bit variable and use the bottom 6 bits as fraction bits. > > An example, in C, that shows how this works: > (the variables are 16 bit unsigned integers) > > // read_a2d() is some function that puts 10 bit a/d reading in NEW > > // shift new a/d reading to the top of the word > NEW = read_a2d() << 6; > > // this is for FF = 1/8 > FILT = FILT + (NEW/8) - (FILT/8); // this particular rendition of > // the formula does the divide > // twice, but lets you completely > // ignore signs > > then if you need to use the filtered reading for anything, pick off the > top ten bits of FILT. Say you have a display function that takes a 16 > bit variable as a parameter: > > display(FILT >> 6); // (but don't use FILT = FILT >> 6; to work with > // it; you'll lose the fraction bits > > As Olin pointed out, if you use an 8 bit a/d reading and 8 fraction bits, > the bit shifting in this example simply becomes a matter of selecting > high and low bytes. And if FF = 1/256, then the divide(s) get real > simple too! > > Hope this helps. > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/02 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/02 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.