On Tue, 3 Feb 1998, Lawrence Lile wrote: > > I have a meter to measure the fuel level of a tank 0=empty 255=full. > > I want to use software to provide a buffer so that the slosh of the > > fuel is not seen on the fuel gauge. PTM: Q&D solution: TEMP = (TEMP + NW)/2 This needs 8 bit + carry to handle 0..255 values. This function works if the sloshing makes small differences to both sides of the right one and the time period is rather short, about 1/20 sek. If this still give odd values, you can make even: TEMP = (TEMP + NV - TEMP/D) VAL =TEMP / D There TEMP is a 16 bit register for the summ NV = nev measured value (0..255) D is 2,4,8,16... (2^n) static VAL is the value that is shown in the display. This gives you totally wrong values from the first D*5 times (I tried this) but after that you get every time a bit better approximation. D is selected as a 2^n to get the program easier. You can even make a try with QBasic: '-------------------------------------------------- 'PTMUSTA@UTU.FI 'Demonstrating running averages 'shareware ;) '-------------------------------------------------- CLS NV = 3 D = 4 FOR i = 1 TO D * 6 'here we simulate random slosh NVU = NV + (RND(1) - .5) / 10 'running average value TEMP = (TEMP + NVU - TEMP / D) DISPLAY = TEMP / D PRINT i;"New=";NVU;"Displ=";DISPLAY;"err=";(DISPLAY-NV)/NV;"%" NEXT -------------------------------------------------------------------------- PTM, pasi.mustalahti@utu.fi, ptmusta@utu.fi, http://www.utu.fi/~ptmusta Lab.ins. (mikrotuki) ATK-keskus/Mat.Luon.Tdk OH1HEK Lab.engineer (PC support) Computer Center OI7234 Mail: Turun Yliopisto / Fysla, Vesilinnantie 5, 20014 Pt 02-3336669, FAX 02-3335632 (Pk 02-2387010, NMT 049-555577) --------------------------------------------------------------------------