Kerry Wentworth wrote: >> Right. You generally want to use Log2 fraction bits to avoid this. > > Where are your fractional bits? Where they ususally are, to the right of the binary point. > In Filt? In all the values. Everything is a fixed point number with the specified number of fraction bits. To be clear, the algorithm I mentioned was: FILT <-- FILT + FF(NEW - FILT) NEW and FILT are expressed as fixed point values. This is usually easy on = a PIC when NEW is successive A/D readings by using the left justify A/D resul= t mode. For example, with the common 10 bit PIC A/D, you automatically get each reading in 10.6 fixed point format in left justify mode. The minimum number of fraction bits you need to not loose information is -Log2(FF). For example, if FF =3D 1/16, then you need 4 fraction bits. In the other method that uses TOTAL, you still need the extra 4 bits but they are on the high end of the number. For example, if filtering 10 bit values with FF =3D 1/16, then TOTAL needs to be 14 bits wide. Note that TO= TAL then has exactly the same representation as FILT. It makes no difference whether you consider it in the scale of the original value with 4 fraction bits, or in the scale of the original value times 16. The bits inside the processor are exactly the same. The only real difference between these methods is that yours requires the additional piece of persistant state, being the TOTAL accumulator. You can do some substitutions in your algorithm to reduce it to what I described above. > Are you doing floating point math? You can, but this discussion was about fixed point. There have been a few cases where I've done that where I needed precise control over the time constant or on the host computer with floating point hardware or where cycles don't matter anyway. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .