Olin Using your formula and simulating in Excel I always get an offset dependant on FF i.e. if using 1/16 then error is -15 counts and if 1/32 then error is -31 counts. Should this be added on at the end if using integer maths? For example my line 11 is as follows: =A10+INT(($D$1-A10)/$C$1) Ian Forse ------------------------------------------------------ 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 Olin Lathrop > Sent: 17 August 2002 23:08 > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Real newbie question on ADC > > > > This is fine if working in perfect conditions on a bench, but > in the real > > world, my circuits will be subjected to noisy industrial environments. I > > have read elsewhere that multiple readings are required - sort of like > > debouncing a pushbutton, I guess - but I have also read about 50Hz and > 60Hz > > hum. > > First, you have to characterize the signal you want and the noise > you don't > want. What kind of bandwidth does your signal have? How fast > does anything > need to respond to this signal? Are you only worried about 50 or > 60Hz power > line noise or other random noise? > > Let's take the easy case where the desired signal has a much > lower frequency > than the dominant noise sources. In that case, you take lots of readings > and low pass filter the crap out of them. > > I often take one reading every 1mS, then do the rest in software. The > equation for the equivalent of an analog R/C low pass filter is: > > FILT <-- FILT + (NEW - FILT) * FF > > where FILT is the current filtered value that is updated by this equation > for each new reading, NEW is the new reading, and FF is the > filter fraction. > This is a number from 0 to 1 that controls what fraction of the > input signal > is "let thru" each iteration. The filter time constant is a > function of FF > and how often this filter operation is performed. An FF value of > 0 results > in an infinite time constant (the filter value never changes), and FF of 1 > results in a 0 time constant (output immediately follows the input). > Obviously useful values are somewhere in between. > > The cool part comes from the observation that if you arrange FF > to be 2**-N, > where N is a positive integer, then the multiply by FF just becomes right > shift by N. You can see an example of this kind of filtering in the > HAL_AD.ASPIC module at http://www.embedinc.com/pic/hal.htm. > There the value > of FF is defined by the assembler constant FILTB. FILTB is actually the > number of bits to shift right, which is 4 in this example. Therefore FF = > 1/16, although it is never computed nor used directly. This > filter yields a > 50% step response in 11 samples, and a 90% step response in 36 > samples. The > attached SHR4.GIF show a plot of the step response. If you only > need about > 100mS response to a changing input and you are taking a sample every 1mS, > then you could use a smaller FF, like 1/32 or 1/64, for example. > > These filters can also be cascaded, just like you can have multiple R/C > filters in series. The attached file SHR44.GIF shows the step > response of a > two pole filter, each with a filter fraction of 1/16. The step > response is > a little slower, but random input noise has been attenuated by an > additional > 12 dB for a total of 24dB. > > > I did post a question regarding the filtering of hum, and I was simply > > pointed to some example code for filters - which was all a little > daunting. > > Don't feel bad, there are entire graduate level courses that deal with > filtering and signal processing. There is a lot of hidden > complexity, which > may be why people prefer to just point at examples. > > > What is the trick? Is it just a matter of taking multiple readings at a > > given frequency? I have read something about 40KHz - as it is a multiple > of > > both 50Hz and 60Hz > > 300Hz is also a multiple of both 50 and 60Hz. Of course all multiples of > 300Hz work too. > > --- > 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: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads