Electronics > Projects, Designs, and Technical Stuff
RMS calculation in cheap microcontroller
(1/3) > >>
Red_Micro:
I sometimes see that RMS calculation is done using some kind of DSP or more high end microcontroller. I'm using this STM32 microcontroller and I would like to know if it could do RMS.

I need to read 60 Hz current from a current transformer through an op-amp as shown below. I don't have values in the drawing because I'm just illustrating the concept. I've heard that one can use an external precision rectifier to sense the peak and calculate RMS from that. In my case I have the signal with a DC shift, and I think that doing RMS would be more robust against noise compared to just sensing the peak.

Any suggestions?

NiHaoMike:
Square each sample, take the average, then take the square root.
Ian.M:
Any MCU with a hardware multiplier can handle RMS measurements if there is an internal or external ADC with enough precision and a max sample rate two or more orders of magnitude faster than the period of highest significant harmonic in the input signal, and the MCU has enough MIPS to do a 16x16 bit => 32 bit multiply and a 32 bit accumulate for each input sample + some housekeeping to track time between either min. or max. peaks or zero crossings to determine the duration of a full cycle of the input waveform.   The square root only has to be handled once per input waveform period, so doesn't need to be fast or efficient.   Only really slow low end 8 bit MCUs would have a problem with processing the RMS calculation fast enough for a line frequency signal.

Therefore if a MCU has got a hardware multiplier, and doesn't need to handle other computationally intensive tasks during the measurement cycle, you can pretty much assume its capable of real-time line frequency RMS calculations.
coppice:

--- Quote from: Ian.M on June 10, 2020, 02:19:48 pm ---Any MCU with a hardware multiplier can handle RMS measurements if there is an internal or external ADC with enough precision and a max sample rate two or more orders of magnitude faster than the period of highest significant harmonic in the input signal, and the MCU has enough MIPS to do a 16x16 bit => 32 bit multiply and a 32 bit accumulate for each input sample + some housekeeping to track time between either min. or max. peaks or zero crossings to determine the duration of a full cycle of the input waveform.   The square root only has to be handled once per input waveform period, so doesn't need to be fast or efficient.   Only really slow low end 8 bit MCUs would have a problem with processing the RMS calculation fast enough for a line frequency signal.

Therefore if a MCU has got a hardware multiplier, and doesn't need to handle other computationally intensive tasks during the measurement cycle, you can pretty much assume its capable of real-time line frequency RMS calculations.

--- End quote ---
Remember that before you multiply those samples you probably need to do an accurate DC estimation and removal, because few ADCs can be trusted to have a stable offset value.
Ian.M:
Good point.  So  for each sample, there's one more accumulate to do on the signed ADC result to keep tracking the DC offset, and a subtract to remove the average offset calculated in a previous cycle before the multiply.  Sample rate vs MIPS would have to be really tight for that to be a problem.  To get the average offset, the accumulated offset only has to be divided by the number of samples per cycle once in each cycle, so it should be practical to update the average offset with no more than two cycles lag.
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod