1. re your factor of 1.53 Note that 1.53^2 = 2.3409 And sqrt(2.5) = 1.58 Suspicious? Have you used an oscilloscope to measure the mean value of the offset sinewaves being fed into the PIC. Or - written code to determine the mean count over a longish period. I suspect this means you reference is slightly low and the 128 subtract count is too high. B,IMBW! (But, I may be wrong. 2. Re preceding stuff and your reply. I think you should read what I said carefullyish and try it - sorry to sound imperious but I think it really is what you want. B,IMBW :-) ! Subtracting 128 is fine IF your offset is exactly half converter range. IF you have an accurate max converter voltage (and if you are using 5 volt Vcc as the reference then you have more or less) and if you are shifting the signals up by EXACTLY half this supply then subtracting 128 and then doing the squaring should produce exactly the correct result. The IMPORTANT thing is that you follow the concept that offsetting by a pedestal voltage (even if only to get the signal in converter range) IS adding a second signal to your initial signal. As power is proportional to the square of the voltage (and RMS VOLTAGE is all about POWER) then increasing part of the signal by Vx and decreasing part by Vx will produce a net power change as the larger parts will increase by the SQUARE of the voltage and the smaller parts will reduce by the square so their will be an imbalance. eg say Vsamp+ = 1.5V and 180 degress later Vsamp- = -1.5V The square in both cases is 2.25 Summation Vsamp+^2 + Vsamp-^2 = 4.5 But - add a +1v pedestal. Vsamp + = 2.5V Vsamp- = -0.5V. Vsamp+ ^2 = 6.25 Vsamp - ^2 = 0.25V Summation Vsamp+^2 + Vsamp-^2 = 6.5 = a net increase in poer nd therefore RMS value. Also - minor pseudo code correction (and I've changed variable bames to avoid any confusion :-)) NB - this is a single program - ------------------------------------- SUM=0 SUMSQ = 0 For N samples SUM = SUM + sample SUMSQ = SUMSQ + sample^2 Next N SUMADJ = SUMSQ - SUM SUMDIV = SUMSQ/N RMS = Sqrt(SUMSQ) ---------------------------------------- >> AC couple sinewave >> Reference AC signal to some known +ve value Xoffs >> Take Xoffs away from each sample before squaring. >This sounds like the part (that I didn't include in my 1.53 ratio pseudocode >because I abandoned it by then thinking it was even less accurate resulting) >where I immediately subtract 128 (2.5v offset) from each sample before >squaring it, or if the result of that subtraction is negative, I subtract >the other from the other...and in my thinking, it should be like having a 0 >volt centered sine with + and - 2.5v peaks instead of the actual input sine >with 2.5v center and 0 and 5v peaks. Yep - this is what you want BUTY If the code you are using to sqyare is true 2's compelment code then you shouldn't need to swap the subtraction results if the sample is < 128 However, for unsigned arithmetic the code would look something like Get Vsample IF Vsample >=128 then Vsample = Vsample - 128 ELSE Vsample = 128 - Vsample END IF proceed with sum of squares etc. The trouble with this is that there is NO ZERO value available You have a +/- 128 range but no zero code between the 2 halves. This may not matter but I'd be more comfortable with setting the range to JUST less, say +/- 127 and allowing a true zero (at binary 128) >If the whole power level thing with the extra 2.5v DC reference on the sine >makes a difference in the RMS readings compared with a 0 reference of same >peak to peak range, I think it would be important to note also that my >original sine signal IS a 0 reference one with -2.5 to +2.5 range, and it >only ends up with that 2.5v center reference for the sake of shifting it up >between 0 and 5 so I can get it into the pic with full cycle swing. I add >the 2.5v DC via op amp non inverting input during some signal conditioning >stages. WHY you do it is perfectlky acceptable (indeed, necessary) but the PIC he don't care - he just calls it as he sees it and he sees an extra amount of power (voltage) being input. >So I'm all confused with the numbers I get when I try the RMS code that I >think SHOULD work but doesn't seem to, unless it does and I'm reading the >data wrong. Try it, you'll like it (as long as the rest of the code is correct). >When Iget time maybe I'll put the actual program on a URL along with some >measurement results and maybe someone can tell me if it's proper and I am >worrying about nothing....although I WOULD like to see the pic showing me >what the meter is showing me because if it IS ac coupled NO - the PIC WAS Ac coupled but you "DC restored" it (or DC de-restired :-) it) by addingba signal which isn't really there. We all know WHY you had to do this but you still have to remove it in the subsequent processing. ...I would think my >PIC code should still show me the same non-DC rms value after I subtract >that 128 level bias.... YES! Agree! If you do it correctly and IF the actuall offset is exactly 1/2 of Vref. An easy way to test this. Write some code to calculate the mean. This is a relatively simple revisionnof your existing code. IF the value you get for mean is NOT 128 then you are in trouble. IF the result is not 128 BUT is constant over numerous attempts then this is the value you should be offsetting by. . I don't know how you debug this sort of thing but I find it REAAAALY useful to send the results to a serial routine (bit bashed one is fine) and display it on a PC. The brain (mine anyway) is very very slow but impressively pattern parallel). Russell McMahon _____________________________ - www.easttimor.com Updated regularly: 100,000 refugees STI LL in West Timor face starvation! - www.sudan.com And you think Kosovo and Chechnya are bad! What can one man* do? Help the hungry at no cost to yourself! at http://www.thehungersite.com/ (* - or woman, child or internet enabled intelligent entity :-))