Dmitry Kiryashov wrote: > There are more short version algorithm above ;) No additional cell > required > > avg = (avg + 3*sample)/4 = ( ( avg + sample )/2 + sample )/2 > > MOVFW SAMPLE > ADDWF AVG,F > RRF AVG,F > ADDWF AVG,F > RRF AVG,F > > 5 Cycles > Excellent observation Dmitry! And in a personal message, Bob Fehrenbach wrote: > > Hey Scott, > > >Have you considered an IIR (infinite impulse response) filter? > >Specifically, I've had good results with filters of this type: > > > > avg = (m*avg + n*sample) /(m+n) > > Without additional 'round off' code, my experience has been that > these filters tend to oscillate when presented with constant data. > In some cases it was only one bit but a nuisance nevertheless. Actually, they tend to round down such that in the example of my previous message where m+n=4, the average will tend to be 1 to 3 counts too small. For example suppose that the current average is 4 and the input sample is 5. Then after an iteration, avg = (avg + 3*sample)/4 = (4 + 15)/4 = 4 The fractional remainder (of 0.75) is lost. Where as with Ralf's desire of taking the last 8 samples, a constant input of '5' will eventually produce an average of '5'. It's something certainly to keep in mind. If your signal jumps around wildly then it is not a big deal. If you're trying to get a couple of more bits out of an A/D converter by integrating samples, then this is not the method you would choose. Scott -- "The problem with television is not the resolution." Hugh. F. Frohbach