Santiago wrote: > > Hello all > > I need to made a routine for to obtain the RMS Voltage of a signal, > independently of a frecuency, but for to measure 50 or 60 Hz.(is for a > signal of 220 V. en Europe, 110 V. in America). > > I use a 74 device, I haven't problems of memory, perhaps of RAM. > > I can to use a Vrms device of harware, but I think that to made a > routine with the PIC, is the best form. Like the signal is in low > frecuency, the with the time there are not problem, but if I made 100 > measures, better that 50. Riding in to work this morining I noticed branded on one of my four-wheeled foes the Oregon license plate: RMS 101 What a coincidence! Santiago, The RMS calculation is like: Vrms = sqrt( v(0)^2 + v(dt)^2 + ... + v(N*dt)^2 )*scale_factor Or simply said, it's the square root of the sum of the squares. However, there are several caveats: 1) Integer number of samples per cycle. While this is not 100% necessary, it certainly makes the arithmetic easier. The down side is that you may need a phase locking algorithm/hardware. No biggy, just a caveat. 2) The more samples per cycle the better; especially if you expect harmonics. However, keep in mind that nyquist thing. 3) Since you have a periodic signal, there's one way to overcome the "very high" sampling rate. For example, suppose you only have enough processing power to handle say 10 samples per cycle, but you want to grind 100 through the algorithm. Well, on the first 60 hz cycle you can obtain the 0th, 10th, 20th, ...samples. On the second cycle obtain the 1st, 11th, 21st, ... samples, and so on. After 10 cycles you'll have obtained the 100 samples. The asumption is that the signal IS periodic. 4) What's your dynamic range? Mid range PICs can square an 8-bit number in 80 instruction cycles (as I recall). You can use my square root routine to find the square root in about a 122 cycles. http://www.interstice.com/~sdattalo/technical/software/pic/picsqrt.html However, it will need some adaptation for your case since the routine is designed to take the square root of a 16-bit number. A 60 hz sine wave makes one wiggle in 16.6 ms. 100 samples per cycle allots 166us per sample or 833 instructions on a 20Mhz PIC. I could go on, but that would be RMS 201. Who knows, maybe I'll see that one tomorrow. Scott -- __o I buy pizza instead of gas. \< (*)/(*)