Dario Greggio wrote: > Yeah, I need the RMS i.e. 220V :) But how do you want to handle harmonics and spikes? Are you trying to detect the spikes or want to filter them out? If you want more of a smoothed RMS, what kind of response time? You can't start thinking about the right filter until you know what you want it to accomplish. > The Filtering idea was provided by Dwayne as part of his code and I > took it kind of good, since "smoothing" could've helped in making the > samples more "smooth"... OK, so it sounds like you want a smoothed recent RMS voltage. Now we're finally getting somewhere, although I still haven't heard what response time you are willing to live with in order to get a smoothed value, and how much you want to attenuate random noise. If that's all you want, a simple peak detector followed by two low pass filter will work nicely. You don't need to store 20 recent samples, only 1 and a flag. As the samples come in, look for local minima and maxima. Each go into separate low pass filters. You adjust the time constant and number of poles of these filters to get the random noise reduction and reponse time you want. Keep in mind that each filter will only be fed at the line frequency of 50Hz. Every time you update the filters, the final filtered maxima minus the final filtered minima times a fixed constant is the line voltage. > I also have to say that, after the IIR, overall sum of 20 samples does > no longer yeld 0... ! Actually it should yield 20x whatever the representation of 0 line voltage is in your system. If your input signal is offset by half Vdd and that is not subtracted out then you will get 20x that offset. However, the AC information you are looking for will be gone and only this "effective zero" will be left. ******************************************************************** 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