On Wed, 22 Jan 2003, Olin Lathrop wrote: > > I have an a/d tied to a fuel level sender, and am > > trying to smooth the resultant value so that any quick > > fluctuations in fuel level are dampened out (tilting > > the tank, bumps, etc.) I've thought of a push/pop > > stack scheme to average but am afraid that would > > consume too much memory. I've also thought of > > sampling the a/d once a second and taking an average > > over ten seconds... > > I like to sample the A/D as fast as possible and filter in software. I've > mentioned this many times, so see the archives for details. An easy > software single pole filter is: > > FILT <-- FILT + (NEW - FILT) * FP And everytime Olin mentions this a few suggestions pop out on how this can be efficiently implemented. For example: http://www.dattalo.com/technical/software/pic/twist.asm implements this formula. ;;; A*x + B*y ;;; ------------ ;;; A + B ;;; ;;; Such that A+B = 2^N Or re-writing: = (A*x + B*x-B*x + B*y)/(A+B) = x + (y-x) * B/(A+B) x == FILT y == NEW B/(A+B) = FP Scott -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads