Andries Tip wrote: > ;------------------------------------------------------------------------= ---- >=20 > FIR_256_16BIT ; average =3D (255*average + setpoint)/25= 6 >=20 > movf average0,w ; average =3D 256*average - average =3D 2= 55*average > sublw d'0' ; prepare carry > movwf temp ; save value for rounding later, otherwis= e we cannot reach 65535 > movf average1,w ; > subwfb average0,f ; > movf average2,w ; > subwfb average1,f ; > movlw d'0' ; > subwfb average2,f ; >=20 > movlw d'255' ; average =3D round((average + setpoint)/= 256) > addwf temp,w ; > movf setpoint1,w ; > addwfc average0,f ; > movf setpoint2,w ; > addwfc average1,f ; > clrw ; > addwfc average2,f ; >=20 > ;------------------------------------------------------------------------= ---- Taking a closer look at your code, I think it has a flaw. First of all, the comment about "we cannot reach 65535" is simply false. Ev= en without temp, with a steady input of 65535, the filter will definitely reac= h 65535 at the output; it just takes a very long time (i.e., 256 iterations after it reaches 65534). This is normal behavior for this type of filter. You're using temp as an extra byte of fractional precision in your accumula= tor, but you've made an error in doing that: When you add the new setpoint value= to the accumulator, the operation to initialize the carry with rounding should= be 128 + temp, not 255 + temp. But, like I said at the beginning, this whole business with temp is superfluous to begin with, and could simply be deleted. -- Dave Tweed --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .