Andrew: > That can't be right... If your NewData is less than your LastAve, > your Result should be LOWER than LastAve, shouldn't it? > > F46 F15 F14 > That is obviously incorrect. :) basic rules of addition, uh? You're right. I stand corrected. I've messed it up cutting and pasting. This are the values as they came out from spreadsheet: LastAv NewData Result .... ... F0E F0E F5A F12 F12 F46 F15 F15 F14 F14 F14 F78 F1A .... .... A695 A695 EE20 AB0D AB0D F5F0 AFBB AFBB E6 A4CD The result become the last filter or average for the next capture. > > Anyway, here's some code: Nice and simple.... but There is a problem when "LastAve" is greater than "NewData" i.e.: LastAve=F3F NewData=F32 NewAve=F3E In your code: NHI:NLO = N - A. NHI:NLO = F32 - F3F = FFF3 Then the division: BHI:W = N/16. BHI:W = FFF3/16 = FFF Then the final addition CCP_H_AVE:CCP_L_AVE = A + BHI:W CCP_H_AVE:CCP_L_AVE = F3F + FFF = 1F3E and is supposed to be F3E I couldn't overcome that problem with this kind of subtraction. That's why I've used a flag for the sign from the begining. I'll think about your solution. As always, thank you very much... BHI:W..:)) that's short! I'll steal that! Dennis Crawley Argentina -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads