From: "Olin Lathrop" > Two cascaded single pole filters each > with a filter fraction of 1/256 looks like would work well here > new filt val <-- - /256 + /256 Ok, just disregard prev msg. Dunno what I was thinking when I wrote that = crap. The filter isnt quite ok. It counts up when I'd expect it do count down, = and vice versa. The high byte overflows in one direction. The high byte looks like it basically works as filter output (when = overflow fixed) The low byte is just plain nuts... With 0 as sample input it keeps=20 counting in a set speed. With 255 as sample input it it also keep counting, but the counting freq isnt constant. It looks more like a = binary count on the LEDs. I would have expected it to be 0 all the time with 0 as input ! ; When we come here we have done 255 samples, 1 byte each for Chan A & = B. ; The new sample values are available in sampleA & sampleB ; Now calculate the filtered values for both values :=20 ; new =3D old - old/256 + input/256 ; Filtered output should be in FilterAH, FilterAL when done here FILTER_A ; // Single pole filter // ; new =3D old - old/256 + input/256 ; // calc: 'input/256' // movfw sampleA ; save old value.=20 movwf tempL ; move high-byte to low-byte makes /256 clrf tempH ; set highbyte to 0 ; Now 'input/256' is in tempH:tempL ; // calc: 'old/256' // movfw FilterAH ; get old value.=20 movwf temp1L ; move high-byte to low-byte makes /256 clrf temp1H ; set highbyte to 0 ; Now 'old/256' is in temp1H:temp1L =20 ; // calc: 'old' - 'old/256' // movf temp1L, W subwf FilterAL, F ; *** ska det vara F eller W ??? movf temp1H, W btfss STATUS,C incfsz temp1H, W subwf FilterAH, F ; *** ska det vara F eller W ??? ; Now 'old'-'old/256' is in FilterAH:FilterAL ; // Calc: 'result above' + 'input/256' // movfw tempL ; get result from 'input/256' addwf FilterAL, F ; add to the result from ['old'-'old/256'] btfss STATUS,C ; any carry ? incfsz FilterAH, F ; if carry then high byte +1 ; Now FINAL RESULT should be in FilterAH:FilterAL ! -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics