At 07:11 PM 1/21/03 -0800, you wrote: >I am wondering what the best method is to average an >a/d input in C. Just skimming responses and adding a bit, here are some options:- 1) Do a boxcar filter by implementing something like a circular buffer and averaging the results. This requires enough RAM to store each result. 2) IIR filter, the single pole version of which is Dn = Dn-1 + K(x - Dn-1) Where K = Ts/(Ts + Tf) (or Tf = (1/K-1)* Ts Tf is the desired filter time constant Ts is the periodic sample time. By making K a 1/(2^n) you can make the calculations faster. Watch that there's still enough bits left after you do the division or your filter output can have a persistent error. Eg. Ts = 0.01 second K = 1/256 you get a time constant of 2.55 seconds. This is about the simplest possible filter, this subject is HUGE. 3) If your output rate is low and you can oversample a lot, just accumulate a number n readings then divide the result by n. n can be made a power of two or some other number to control the reading rate (effectively an integration period). Best regards, Spehro Pefhany --"it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads