Maker Pro
Maker Pro

RMS current on AVR microcontroller

J

Jamie Morken

Jan 1, 1970
0
Hi,

I am using a AVR microcontroller at 4MHz and have a varying frequency
(50Hz max) sine wave from an allegro current sensor, is there a low
computational algorithm to calculate a close approximation to the RMS
current for a signal like this? The signal into the allegro current
sensor is a sine wave within about +-3amps.

cheers,
Jamie
 
E

Eeyore

Jan 1, 1970
0
Jamie said:
Hi,

I am using a AVR microcontroller at 4MHz and have a varying frequency
(50Hz max) sine wave from an allegro current sensor, is there a low
computational algorithm to calculate a close approximation to the RMS
current for a signal like this? The signal into the allegro current
sensor is a sine wave within about +-3amps.

Well ... you could sample it and do the RMS calculation mathematically.

Graham
 
F

Fred Bloggs

Jan 1, 1970
0
I am using a AVR microcontroller at 4MHz and have a varying frequency
(50Hz max) sine wave from an allegro current sensor, is there a low
computational algorithm to calculate a close approximation to the RMS
current for a signal like this? The signal into the allegro current
sensor is a sine wave within about +-3amps.


If you know it's a sine then 0.707 x Vpeak seems fairly low on
computation...
 
M

MooseFET

Jan 1, 1970
0
Hi,

I am using a AVR microcontroller at 4MHz and have a varying frequency
(50Hz max) sine wave from an allegro current sensor, is there a low
computational algorithm to calculate a close approximation to the RMS
current for a signal like this? The signal into the allegro current
sensor is a sine wave within about +-3amps.

cheers,
Jamie
B
Z=X*X*Y*Y ----!!----- Z=1/X
-------- A ! ! -----
Signal --->!X Z!----\/\/---+--+---/\/\----+-+---!X Z!--Out
! Y ! ! ! -----
------- ---!-\ !
! ! >---------+
! 1V--!+/ !
! !
--------------------------------

B settles to the point where the average at A is 1V.

The mean square of A must equal the mean square of 1/B

B is "DC" so B must be a DC 1/RMS

If you were using an 8051, I would be able to suggest that a
sqrt(32bit) = 16bit will take less time than the divide needed for
this
routine.
 
V

Vladimir Vassilevsky

Jan 1, 1970
0
Jamie Morken wrote:

I am using a AVR microcontroller at 4MHz and have a varying frequency
(50Hz max) sine wave from an allegro current sensor, is there a low
computational algorithm to calculate a close approximation to the RMS
current for a signal like this? The signal into the allegro current
sensor is a sine wave within about +-3amps.

If you know that the signal is the AC sine wave, then just take the
absolute value, average it and multiply by 1.111. This will give you the
RMS value.


Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
 
F

Frithiof Andreas Jensen

Jan 1, 1970
0
Jamie Morken said:
is there a low
computational algorithm to calculate a close approximation to the RMS
current for a signal like this?

Heat something with it and measure the temperature rise above a referencce
temperature - doesn't get much simper than that and works up to GHz ;-)
 
J

Jamie Morken

Jan 1, 1970
0
Fred said:
If you know it's a sine then 0.707 x Vpeak seems fairly low on
computation...

Hi,

What is a good way to determine Vpeak from a signal without being
susceptible to noise spikes?

I am lowpass filtering a signal that is the unfiltered output of a
3phase rectifier (rectifying 3phase AC) and would like to know the cycle
by cycle peak DC voltage while still having the "safety" of using a
low pass filter if that is possible. Also what is a good way to
determine the 3phase frequency from the rectified DC ripple?

I think using a buffer and checking for voltage slope reversals could do
both, but I am not sure if this is the best way.

cheers,
Jamie
 
J

Jamie Morken

Jan 1, 1970
0
Vladimir said:
Jamie Morken wrote:



If you know that the signal is the AC sine wave, then just take the
absolute value, average it and multiply by 1.111. This will give you the
RMS value.

Is using a lowpass filter ok instead of averaging? I wrote some code
that does the abs() and then a lowpass filter, but the output current
reading is much higher than actual.

cheers,
Jamie
 
A

Arlet Ottens

Jan 1, 1970
0
Jamie said:
Is using a lowpass filter ok instead of averaging? I wrote some code
that does the abs() and then a lowpass filter, but the output current
reading is much higher than actual.

If you're sampling the signal through the ADC anyway, you may be able to
brute force it, by just summing the squares. The ATmega series have a
multiply instruction, so a square is cheap. On the smaller AVRs, you may
be able to use a lookup table, or just do it in software (8*8 -> 16 bit
should only take 25 microsecs or so). It depends on how much CPU and/or
flash memory you have left over.
 
J

Jamie Morken

Jan 1, 1970
0
Arlet said:
If you're sampling the signal through the ADC anyway, you may be able to
brute force it, by just summing the squares. The ATmega series have a
multiply instruction, so a square is cheap. On the smaller AVRs, you may
be able to use a lookup table, or just do it in software (8*8 -> 16 bit
should only take 25 microsecs or so). It depends on how much CPU and/or
flash memory you have left over.

I'm using an atmega168, still lots of memory and CPU left, I guess I
will need a buffer to do this? For signals 50Hz to DC how many points
in the buffer would be good to use, or is there a simpler way to do
a running calculation with no buffer?

cheers,
Jamie
 
V

Vladimir Vassilevsky

Jan 1, 1970
0
Arlet Ottens wrote:

If you're sampling the signal through the ADC anyway, you may be able to
brute force it, by just summing the squares.

Squaring is not a problem. But you have to compute the square root
afterwards.


Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
 
M

MooseFET

Jan 1, 1970
0
I'm using an atmega168, still lots of memory and CPU left, I guess I
will need a buffer to do this? For signals 50Hz to DC how many points
in the buffer would be good to use, or is there a simpler way to do
a running calculation with no buffer?

See my earlier post for details of one way. Here's another:

RMS = HALF_SCALE;
while (TRUE) {
Sum = 0;
for (i=0; i<SOMENUMBER; i++) {
Temp = ReadADC();
Sum += Temp * Temp;
Delay(ASNEEDED);
}
Sum /= SOMENUMBER; /* Detail A */
RMS = (RMS + Sum/RMS) / 2; /* Detail B */
Display(RMS);
}

Detail A:

SOMENUMBER is set so that an integer number of AC cycles is processed
by the for loop.

If you adjust ASNEEDED so that a power of 2 number of ADC conversions
is done in an integer number of AC cycles, the divide is just a shift

Detail B:

If you don't want to include a divide routine at all this statement
can be changed to something like:

if (RMS*RMS > Sum) RMS--;
else RMS ++;

or leaving out statement (A):

if (RMS*RMS*SOMENUMBER > Sum) RMS--;
else RMS++;

in either case in the output settles to the right answer less quickly
but still gets there.
 
J

JosephKK

Jan 1, 1970
0
Jamie Morken [email protected] posted to sci.electronics.design:
Hi,

What is a good way to determine Vpeak from a signal without being
susceptible to noise spikes?

I am lowpass filtering a signal that is the unfiltered output of a
3phase rectifier (rectifying 3phase AC) and would like to know the
cycle by cycle peak DC voltage while still having the "safety" of
using a
low pass filter if that is possible. Also what is a good way to
determine the 3phase frequency from the rectified DC ripple?

I think using a buffer and checking for voltage slope reversals
could do both, but I am not sure if this is the best way.

cheers,
Jamie

If you know the input frequency to the 3-phase rectifier and the
rectifier configuration it is easy. You could even do it
analytically from average at that point. Careful use of peak / notch
detection will enable outlier reduction. Can you post a schematic of
your rectifier?
 
J

Jamie Morken

Jan 1, 1970
0
JosephKK said:
Jamie Morken [email protected] posted to sci.electronics.design:


If you know the input frequency to the 3-phase rectifier and the
rectifier configuration it is easy. You could even do it
analytically from average at that point. Careful use of peak / notch
detection will enable outlier reduction. Can you post a schematic of
your rectifier?

It is a 6 diode full wave rectifier like this one:
http://www.sustainability.ofm.uwa.edu.au/__data/page/83883/3Phaserectifier.jpg

There is no filtering on the output too.

cheers,
Jamie
 
J

JosephKK

Jan 1, 1970
0
Jamie Morken [email protected] posted to sci.electronics.design:
It is a 6 diode full wave rectifier like this one:
http://www.sustainability.ofm.uwa.edu.au/__data/page/83883/3Phaserectifier.jpg

There is no filtering on the output too.

cheers,
Jamie

OK that is a standard 6 pulse. Draw 3 rectified sines at 60 degree
steps and look at the top over one cycle of operation. You should
get the top 60 degrees repeated 6 times. With this information
calculate the average voltage and the root mean square.

Using even a small inductor input to the filter improves the smoothing
considerably. Also the ripple strongest component is at 360 Hz for a
60 Hz system.
 
Top