Dear You are right, this does *look* simple. Have you single-stepped through your code with the ICD ? Patrick J on 2001-06-08 09:52:27 AM asked for help: > new filt val = - /256 + /256 ... >with sample-input val of 0:255. Right ? Sample is always in the range of 0-255 >I have simulated this in Excel, works fine there. (not tried as fixed point math tho) > >Must this be done with floating point math ??? simple 2 byte (``fixed point'') math should work fine. > ; // calc: 'input/256' // > movfw sampleA > movwf tempL ; move high-byte to low-byte makes /256 > clrf tempH ; set high byte to 0 > ; Now 'input/256' is in tempH:tempL > > ; // calc: 'old/256' // > movfw FilterAH ; get old value. > movwf temp1L ; move high-byte to low-byte makes /256 > clrf temp1H ; set high byte to 0 > ; Now 'old/256' is in temp1H:temp1L > Looks good to me. (After you get it working, it might be possible to improve it to only use 1 temporary 16 bit register tempL:tempH ... or maybe none at all ). > > ; // calc: 'old/256' + 'input/256' > movf tempL, W > addwf temp1L, F ; W eller F ? > > movf tempH, W > btfsc STATUS, C > incfsz tempH, W > addwf temp1H, F ; W eller F ? > ; Now 'old/256' + 'input/256' is in temp1H:temp1L Yes, it is true that temp1H:temp1L := 'old/256' + 'input/256'; but I think you really want temp1H:temp1L := (-'old/256') + 'input/256'; right ? That's the first partial result from new filt val = + ( - /256 + /256 ) right ? > ; // calc: 'old' - ('old/256' + 'input/256') // Um.... close. What you want is new = - /256 + /256 new = + (- /256 + /256) new = + ( /256 - /256 ) > movf temp1L, W > subwf FilterAL, F > movf temp1H, W > btfss STATUS,C > incfsz temp1H, W > subwf FilterAH, F > ; Now FINAL RESULT should be in FilterAH:FilterAL ! I hope this isn't optimized to the point of incomprehension: ; warning: untested code. ; 2001-06-08: David Cary ; tempH:tempL := -(old/256); clrf tempH comf FilterAH,w movwf tempL incfsz tempL decf tempH ; tempH:tempL := tempH:tempL +(input/256) movfw sampleA addwf tempL,f skpnc incf tempH ; FilterAH:FilterAL := FilterAH:FilterAL + tempH:tempL; ... [missing code for 16 bit addition] ... ; Now FINAL RESULT should be in FilterAH:FilterAL ! -- David Cary -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.