Dario Greggio wrote: > Take 20 samples/sine > for each sample > take previous sum > divide by 20 > subtract this (sum/20) from previous sum > add new sample to sum That makes no sense for any reasonable interpretation of "measure mains voltage". Remember this is a AC signal. This description above is not totally clear, but it looks like you're box filtering the signal, sortof, I guess. Box filtering a AC signal with a aperture width a multiple of the period will always yield 0. In other words, the sum of any consecutive 20 samples (one whole period) will be 0. Again, it's too early to jump into the implementation since there isn't yet a clear definition of what exactly you want. On top of that this implementation appears broken, at first glance at the level of detail of what I think the above description is saying anyway. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist