Truncated match.
PICList
Thread
'RMS Measurement again'
2000\03\07@164614
by
Lorick
Someone suggested another way for me to measure the RMS of a sine wave by
just multiplying the samples by .707 using floating point methods and
accumulate that in just 16 bits.
How does that compare in effectiveness, speed, code size, to doing the other
method of squaring every sample, accumulating 24 bits, then squarerooting?
Whichever method I choose, how does the final answer work out with it having
decimal places? Again I find myself trying to figure out how to think in
terms of binary....but suppose I took the square root of 255, which is
15.968,
how does that look in the pic and how do I handle it?
2000\03\07@171607
by
Jeff Davis
On Tue, 7 Mar 2000, Lorick wrote:
> Someone suggested another way for me to measure the RMS of a sine wave by
> just multiplying the samples by .707 using floating point methods and
> accumulate that in just 16 bits.
For a perfect sine wave the RMS is .707 times the peak. So if you always
have a perfect sine wave this will work. This only works for the peak as
far as I know, so you'll have to find some way of determining the peak as
opposed to sampling it. If you are trying to measure the RMS value of
anything other than a near perfect signwave this will not work. This is
actually the difference between ordinary multimeters and trueRMS ones.
The ordinary ones assume a signwave input and multiply the peak by .707
while the true RMS do the calculation so they work for all types of
inputs.
Jeff
2000\03\07@192554
by
Brent Brown

Lorick wrote:
> Someone suggested another way for me to measure the RMS of a sine wave by
> just multiplying the samples by .707 using floating point methods and
> accumulate that in just 16 bits.
I might be able to make a reasonable suggestion if I know a bit
more about what you are doing. There are often alternatives to the
full blown floating point megamemory approach.
 Do you want the RMS value of a typical sinewave, as someone
else pointed out thats what you get from a typical elcheapo
multimeter. That would be easiest. Or do you actually need True
RMS to give more correct readings for waveforms that are non
symteric, have DC offsets, high harmonc content, nonsinusoidal
shpe etc. Even true RMS instruments typically have frequency
limits or 'form factor' limits.
 What is the voltage range input to your A/D converter
 What is the typical frequency range of the AC voltage to be
measured
 How many bits resolution is your A/D
 Are there any time factors to be considered, eg speed of display
update or A/D sample rate.
Brent Brown
Electronic Design Solutions
16 English Street
Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile: 025 334 069
eMail: spam_OUTbrent.brownTakeThisOuTclear.net.nz
2000\03\07@194713
by
l.allen
> Lorick wrote:
> > Someone suggested another way for me to measure the RMS of a sine wave by
> > just multiplying the samples by .707 using floating point methods and
> > accumulate that in just 16 bits.
>
> I might be able to make a reasonable suggestion if I know a bit
> more about what you are doing. There are often alternatives to the
> full blown floating point megamemory approach.
>
I must admit... my first reaction is to stick an RMS
analog i.c. between the source and the A/D input if all the
specs match. In a one off/medium cost app this beats
flogging the brain cells into deeper dementia and may be
more accurate (quantizing errors come after the
conversion, not before).
_____________________________
Lance Allen
Technical Officer
Uni of Auckland
Psych Dept
New Zealand
http://www.psych.auckland.ac.nz
_____________________________
2000\03\07@201418
by
Lorick

>  Do you want the RMS value of a typical sinewave, as someone
> else pointed out thats what you get from a typical elcheapo
> multimeter. That would be easiest. Or do you actually need True
> RMS to give more correct readings for waveforms that are non
> symteric, have DC offsets, high harmonc content, nonsinusoidal
> shpe etc.
The readings are not pure sine waves, they may be safely assumed to vary
anywhere from a pure sine wave to a voice waveform...and there will be a
deliberate DC offset of 2.5v that the signal will be centered around.
Otherwise my lack of experience tells me I don't really know what it is I
need...but I guess accuracy is best.
>  What is the voltage range input to your A/D converter
0 to 5v centered at the 2.5 offset
>  What is the typical frequency range of the AC voltage to be
> measured
I'll have a band pass filter that is fixed very narrow around 330Hz and
should attenuate a 5v peak input signal by 20dB at some range maybe 50Hz on
either side of 330. The lab test on the filter was already done and results
were successful with that design.
>  How many bits resolution is your A/D
I'm using 8 of the 10 available (just because it's easiest to think of a
byte instead of a byte and part of another byte)
>  Are there any time factors to be considered, eg speed of display
> update or A/D sample rate.
There's no visual output during all the calculations, just a latched single
LED on the port, one of 8 LEDs will be on based on the reading and will
latch until a new reading is done (however long it should take) and
overwrites the port.
2000\03\07@212919
by
Brent Brown

Lance may be right, get a chip that does the true RMS conversion
for you.
But you could do it all in software, after all that is the advantage of
using a micro here instead of an LM3915 LED bargraph driver,
right? Let me try and wrap my brain around this:
Your A/D results will be centered around a count of 128 (2.5V with
a 5V A/D reference). First of all, lets get rid of the DC offset, which
I assume, rightly or wrongly, is only there for the purposes of
biasing and you don't want to measure it. Numbers greater than or
equal to 128 get 128 subtracted from them. Numbers smaller than
128 get subtracted from 128. Think about it and you will see that
this is the equivalent of getting rid of the DC and full wave recitfying.
Square the value. 8 bit x 8 bit multiply gives 16 bit result (Wish you
had an 8051 now?) Lets try a 3.3kHz A/D conversion rate and see
how it works out. Do this to 256 samples, each time adding the 16
bit result to a 24 bit accumulator. Sounds big? OK, but it's still
just integer maths so should be fairly easy/quick. That the squaring
part.
Now find the mean (average). Divide the 24 bit accumulator by 256
(the number of samples). This is the same as shifting right by 8
bits, which in turn is the same as just dropping the LS byte and
you have a 16 bit value again.
Now you need a routine that will get you the square root of a 16 bit
number. Hope there will be one out there somewhere. The answer
is an 8 bit value, 0255. This value is now proportional to the RMS
value of the input over the last 77.5ms sampling period (equals
about 12 samples per second). Reset the 24 bit accumulator and
do 256 samples again...
Sounds relatively simple, just the kind of work micros love doing.
Someone will tell me what's wrong with my idea.
Brent Brown
Electronic Design Solutions
16 English Street
Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile: 025 334 069
eMail: .....brent.brownKILLspam@spam@clear.net.nz
2000\03\07@214558
by
Sean Breheny
Hi Brent,
Your idea sounds very good. One thing additional which might be good to
note is that, AFAIK, you don't need to sample above the Nyquist rate
(Fmax/2) for an application like this, assuming the input waveform is
repetitive. Let's say that you only need an updated RMS value every second.
Since your sampling is not synchonized to the input waveform, even if you
have very few samples per period, as long as you take samples for many
periods and are sure that you have samples to cover every part of the
waveform (this is assuming the input waveform IS repetitive), I think the
result you get should be very close to the RMS value. Using this idea, it
should be possible to,say, obtain the RMS value of a 10kHz input using your
3.3 kS/sec rate.
Also, integer square root routines are very east to write. Two common algos
are Newton's method applied to the equation x^2y=0 to solve for x given y,
and the CORDIC square root method. Both should be only about 100 lines or
so in PIC assembly.
Sean
At 03:29 PM 3/8/00 +1300, you wrote:
>Lance may be right, get a chip that does the true RMS conversion
>for you.
>

 Sean Breheny
 Amateur Radio Callsign: KA3YXM
 Electrical Engineering Student
\=
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
shb7KILLspamcornell.edu ICQ #: 3329174
2000\03\07@225109
by
Scott Dattalo
On Tue, 7 Mar 2000, Sean Breheny wrote:
> Also, integer square root routines are very east to write. Two common algos
> are Newton's method applied to the equation x^2y=0 to solve for x given y,
> and the CORDIC square root method. Both should be only about 100 lines or
> so in PIC assembly.
Those may be easy to write, but they're slow. This one was hard to write
but it's fast:
http://www.dattalo.com/technical/software/pic/picsqrt.html
(There are actually two there). Andy David has versions for taking the
square of numbers bigger than 16bits, but I don't have those readily
available.
Scott
2000\03\07@225919
by
Sean Breheny
2000\03\08@012856
by
Lorick

> a 5V A/D reference). First of all, lets get rid of the DC offset, which
> I assume, rightly or wrongly, is only there for the purposes of
> biasing and you don't want to measure it. Numbers greater than or
> equal to 128 get 128 subtracted from them. Numbers smaller than
> 128 get subtracted from 128. Think about it and you will see that
> this is the equivalent of getting rid of the DC and full wave recitfying.
The 2.5 is there for the biasing, and as a result I already had plans to
shift my readings down by 128 in the way you describe so that I could deal
with smaller bit sized accumulated numbers since the lower 128 are being
wasted otherwise...and in the process, I realized I was also rectifying it
when I chose to swing the negative half up to the positive half of the 128
line...up to that eureka moment I was planning to use an op amp rectifier
circuit.
{Quote hidden}> Square the value. 8 bit x 8 bit multiply gives 16 bit result (Wish you
> had an 8051 now?) Lets try a 3.3kHz A/D conversion rate and see
> how it works out. Do this to 256 samples, each time adding the 16
> bit result to a 24 bit accumulator. Sounds big? OK, but it's still
> just integer maths so should be fairly easy/quick. That the squaring
> part.
>
> Now find the mean (average). Divide the 24 bit accumulator by 256
> (the number of samples). This is the same as shifting right by 8
> bits, which in turn is the same as just dropping the LS byte and
> you have a 16 bit value again.
>
> Now you need a routine that will get you the square root of a 16 bit
> number. Hope there will be one out there somewhere. The answer
> is an 8 bit value, 0255. This value is now proportional to the RMS
> value of the input over the last 77.5ms sampling period (equals
> about 12 samples per second). Reset the 24 bit accumulator and
> do 256 samples again...
These are the exact steps I have in mind based on the last few weeks of
asking questions on here, and I had already found Scott's square root HTML
and was considering testing it in this program once I'm ready for that part
of the program development testing.
Now I just have to figure out why the op amps in my filter will only give me
a 0.5 volt max output out of 5v rail when they should be close to 5v
out.....but I guess that's a topic for a newsgroup. But while I'm on the
subject, I'm using the TI TLV2774 quad op amp single supply 5v rail to rail
in a filter design that's been designed to have an output in the pass band
that's very minimal attenuation.
In SPICE I tried several op amps including the 741 and they did give out
almost 2.5v when I put in 2.5v, but when I use an op amp model close to the
TI chip (I can't find an exact model), the output isn't at all close to the
2.5v input, it's down to 500mv. I build the thing in the lab and indeed it
only gives out about 500mv when it's designed to give 2.5v at that point,
and other op amps do give 2.5 at that point. I don't know why so all I
know to do is look at the spec sheet again to see if there's anything that
indicates why this would be....or else just thow another op amp on the
output and scale it from 500mv to 2.5v and wave my hands over it.
...and to think the spec sheet said this op amp is ideal for a/d
inputs......
2000\03\08@043228
by
Tom Handley

Lorick, it would be hard to tell what your problem is without seeing your
circuit. One thing to note, while the TLV2774 has a RailtoRail output, the
input common mode range is around 0 to 3.7V with a 5V supply.
 Tom
At 01:28 AM 3/8/00 0500, Lorick wrote:
[snip]
{Quote hidden}>Now I just have to figure out why the op amps in my filter will only give me
>a 0.5 volt max output out of 5v rail when they should be close to 5v
>out.....but I guess that's a topic for a newsgroup. But while I'm on the
>subject, I'm using the TI TLV2774 quad op amp single supply 5v rail to rail
>in a filter design that's been designed to have an output in the pass band
>that's very minimal attenuation.
>
>In SPICE I tried several op amps including the 741 and they did give out
>almost 2.5v when I put in 2.5v, but when I use an op amp model close to the
>TI chip (I can't find an exact model), the output isn't at all close to the
>2.5v input, it's down to 500mv. I build the thing in the lab and indeed it
>only gives out about 500mv when it's designed to give 2.5v at that point,
>and other op amps do give 2.5 at that point. I don't know why so all I
>know to do is look at the spec sheet again to see if there's anything that
>indicates why this would be....or else just thow another op amp on the
>output and scale it from 500mv to 2.5v and wave my hands over it.
>
>
>...and to think the spec sheet said this op amp is ideal for a/d
>inputs......

Tom Handley
New Age Communications
Since '75 before "New Age" and no one around here is waiting for UFOs ;)
2000\03\08@064706
by
paulb

Lorick wrote:
> The 2.5 is there for the biasing, and as a result I already had plans
> to shift my readings down by 128 in the way you describe so that I
> could deal with smaller bit sized accumulated numbers since the lower
> 128 are being wasted otherwise...and in the process, I realized I was
> also rectifying it when I chose to swing the negative half up to the
> positive half of the 128 line...up to that eureka moment I was
> planning to use an op amp rectifier circuit.
The *last* time this identical question was asked was two or three
(maybe four...) weeks back. Was it you perchance? The clever
suggestion was to perform a running average (software LPF) on the signal
to derive the "zero" level without external adjustment. Just like a
series capacitor.
You then take the difference between the instant values and this mean,
make them positive (NEGate) if required, and square them.
Secondly, with an 8LED display (was it?) you don't want accuracy. It
appears you are measuring voice level. You don't want accuracy. Voice
level determination however does require an RMS or average power
measuring technique as peak power is far greater than average.
A clue: Measure average power, not RMS voltage. Beware! Some people
will refer to "RMS Power". Use of that oxymoron implicitly indicates
failure to grasp the subject.
Square the values. Average them. Display the power reading. *Don't*
use a square root to estimate voltage. You don't need it. Even if you
think you do.
The only time you *ever* need it is in a digital meter where the end
user wants RMS voltage and you give them what they want. Even though
it's almost certainly not what they need.
Do you follow this? ;)

Cheers,
Paul B.
2000\03\08@113644
by
jamesnewton
2000\03\08@153842
by
Harold M Hallikainen

On Tue, 7 Mar 2000 16:46:43 0500 Lorick <lorickspam_OUTAIR.ON.CA> writes:
> Someone suggested another way for me to measure the RMS of a sine
> wave by
> just multiplying the samples by .707 using floating point methods
> and
> accumulate that in just 16 bits.
>
> How does that compare in effectiveness, speed, code size, to doing
> the other
> method of squaring every sample, accumulating 24 bits, then
> squarerooting?
>
> Whichever method I choose, how does the final answer work out with
> it having
> decimal places? Again I find myself trying to figure out how to
> think in
> terms of binary....but suppose I took the square root of 255, which
> is
> 15.968,
> how does that look in the pic and how do I handle it?
Multiplying by 0.707 (actually, sqrt(2)/2) ONLY works for sine waves and
requires sampling of the PEAK voltage (not random samples).
Harold
FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com
________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today  there's no risk! For your FREE software, visit:
dl.http://www.juno.com/get/tagj.
More... (looser matching)
 Last day of these posts
 In 2000
, 2001 only
 Today
 New search...