> > Anybody got a good averaging algorithm? derivation deleted > Now, this would normally be rather problematic to calculate without > floating point, and slow to do WITH floating point, so we observe > that the smallest fractional value we need to deal with is 1/N, pick > N to be a nice power of two, and use what is essentially FIXED POINT > fractional numbers > N*avg = N*avg - avg + sampN > N*avg = N*avg + (sampN - avg) > > If we store N*avg, we now have one division (shift) and a couple > adds rather than anything more complicated, and we keep log2(N) bits > of fraction around. Of course, you have to remember to also divide > by N whenever you want to access the actual average... Maybe I don't even have to divide by N. My results go into an algorithm that compares the measured temperature to a setpoint. Setpoint could be any number, so I'll just pick a setpoint that is already N times my temperature reading. I'm going to simulate this on a spreadsheet again, and see how far off it gets after several hundred or thousand cycles. if it doesn't "wind up" too bad, this might do the trick. Best Regards, Lawrence Lile