> -----Original Message----- > From: piclist-bounces@MIT.EDU [mailto:piclist-bounces@MIT.EDU] On Behalf > Of Olin Lathrop > Sent: 19 March 2010 17:34 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] measuring 220V mains > > 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. Looking back through the posts in this topic I think there may be a fundamental disconnect between Dwaynes measurement technique and what Dario is hoping to achieve. Dwayne is rectifying and smoothing the AC, so a box filter could be useful to get the mean DC value and reject any ripple. I may be wrong but I get the impression that Dario is effectively half wave rectifying the AC waveform by clipping the negative side to ground with a diode since there was some discussion on the dangers of not using the PICs protection diodes for this. Since that will give one half cycle of positive input followed by one half cycle of 0 volts it's not surprising his box filter isn't giving zero (would be Vpeak/PI I think?). A schematic would certainly reduce confusion here. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist