I found the two stage filter to be too fast for my application so I added 6 more stages (cascaded). The responsetime is approx 1 sec now, still way too fast ! As I add more and more stages I notice the responsetime gets a little longer for each stage. Wonder if that is because the mainloop gets bigger or its due to the filter gets more stages... hmm... I'd expect the responsetime to increase very much with so many stages. As u can see I use a new variable for each stage, is that really necessary ? All my attemts to use a sub or just re-use the same variables seems to make the filter response faster than if using many variables! Could be error in the calc ? I also need slower decay when the sensor reads 0, and not as now symetrical responstime. The fill-up-time is 2-4 sec, but the time until empty is 20-30 secs. With a simple box filter I could put more 'weight' on the 1:s by adding 2 or 3 to the filter for each 1 that is read. That would yield a faster response for 1 and keep same response for the 0 level. Cant really see howto do that using a cascaded single pole filter. From: "Olin Lathrop > of the code. The two stage filter would yield a cleaner and less noisy > value than the single stage filter. The step response of the two stage > filter would be a little slower, but still well within your requirements as > I understand them. The 50% step response time would be a bit over 400 > samples, and the 80% response time at about 760 samples. My implementation: FILTER_A ; new = old - old/256 + input/256 ; *** FILTER: STEG 1 ; ; Subtract from FILT1 ; movf FilterA1H, W ;get FILT1/255 subwf FilterA1L, F ;make the new low byte btfss STATUS, C ;no borrow from high byte ? decf FilterA1H, F ;propagate the borrow ; ; Add to the filter ; btfss sample, plutt ;the input bit is 1 ? goto done_inbitA ;input bit is 0, skip this section movlw h'FF' ;get value implied by input bit / 256 addwf FilterA1L, F ;make new low byte btfsc STATUS, C ;no carry to high byte ? incf FilterA1H, F ;propagate the carry done_inbitA ;done dealing with input bit contribution ; *** FILTER: STEG 2 ; ; Subtract from FILT2 ; movf FilterA2H, W ; get subwf FilterA2L, F ; make the new low byte btfss STATUS, C ; need to borrow from high byte ? decf FilterA2H, F ; yes, propagate the borrow ; ; Add to the filter ; movf FilterA1H, W ;get FILT1/256 addwf FilterA2L, F ;make new low byte btfsc STATUS, C ;no carry to high byte ? incf FilterA2H, F ;propagate the carry ; ---- FILTER: STEG 3 ---- ; ; Subtract ; movf FilterA3H, W ; get subwf FilterA3L, F ; make the new low byte btfss STATUS, C ; need to borrow from high byte ? decf FilterA3H, F ; yes, propagate the borrow ; ; Add to the filter. ; movf FilterA2H, W ; get (the output from the filter above) addwf FilterA3L, F ; make new low byte btfsc STATUS, C ; no carry to high byte ? incf FilterA3H, F ; propagate the carry repeat same as above with new variables for each stage... use the high byte of the last set of variables as output. ; ---- FILTER: STEG 4 ---- ; ---- FILTER: STEG 5 ---- ; ---- FILTER: STEG 6 ---- ; ---- FILTER: STEG 7 ---- -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu