Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Noise Filtering on ADC'
2002\08\27@142659
by
ian.forse
|
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 removed}
More... (looser matching)
- Last day of these posts
- In 2002
, 2003 only
- Today
- New search...