RMS current on AVR microcontroller

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

Reply to
Jamie Morken
Loading thread data ...

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

Reply to
Fred Bloggs

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.

Reply to
MooseFET

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

formatting link

Reply to
Vladimir Vassilevsky

"Jamie Morken" skrev i en meddelelse news:cdt7j.1662$Mw6.1128@pd7urf2no...

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 ;-)

Reply to
Frithiof Andreas Jensen

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

Reply to
Jamie Morken

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

Reply to
Jamie Morken

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.

Reply to
Arlet Ottens

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

Reply to
Jamie Morken

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

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

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

RMS = HALF_SCALE; while (TRUE) { Sum = 0; for (i=0; i

Reply to
MooseFET

Jamie Morken snipped-for-privacy@shaw.ca 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?

Reply to
JosephKK

It is a 6 diode full wave rectifier like this one:

formatting link

There is no filtering on the output too.

cheers, Jamie

Reply to
Jamie Morken

Jamie Morken snipped-for-privacy@shaw.ca posted to sci.electronics.design:

formatting link

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.
Reply to
JosephKK

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.