On infrequent occasions, I am asked to design a circuit to measure the RMS value of a current or voltage for some kind of power measurement. Since the work I do is hardly unique, I thought some of you may like to hear about some of the options.
There are several techniques to measure the instantaneous values of AC voltage or current. For the voltage, you could measure it directly (taking great care if it is high voltage), through a voltage transformer, or with an isolation amplifier like the Avago ACPL-C870.
For current, you can measure it by passing it through a resistor and measuring the voltage drop across it, you can use a Hall-Effect transducer like the Allegro ACS714, or you could use a current transformer.
What is an RMS voltage or current? The RMS measurement is meant to indicate that the heating effect of the AC voltage (or current) is the same as the heating effect produced by the equivalent DC voltage (or current). There is a concept of RMS power, but it is purely a mathematical exercise and does not have a practical application. There is a passionate discourse on the topic here.
It is often easier to measure average values as opposed to RMS values, so what is the difference? If you have regular sinusoidal waveforms, the two are related by a constant factor, and you can use the average and scale to RMS, but as the waveform deviates away from a sine or square wave, the relationship changes and is non-linear to boot. The RMS is the effective value and so of the two, is the meaningful measurement.
You may have seen the term "Crest Factor" (CF) used when talking about AC waveforms. Sometimes a source is not sinusoidal -- consider a stepped quasi AC waveform produced by an Uninterruptable Power Supply. Many times a load will affect the waveform produced from a source by introducing voltage transients or spikes. The CF is a measure of the peak to the RMS value. This peak places additional demands on the power supply and so the CF is used to scale the RMS value so that the power supply can be uprated to provide sufficient power.
Now, how can we accurately measure RMS values? There are dedicated integrated circuits, and some of them have been around for so long, they were made when manufacturers still made second-sourced devices. I have used the venerable AD736 from Analog Devices with great success. There are several other ICs from Analog Devices and from Maxim that use the same approach. The advantage of these parts is that they have the ability to measure signals with a moderate CF, and, of course, have no need for microprocessor or microcontroller (MCU) support.
One approach to RMS conversion: an RMS converter board based on the AD736.
Aside from the disadvantage of additional hardware (and the not insignificant cost of these devices), you typically have to condition your signal to match the IC's input limitations, rather than modify its input to meet your signal. In other words, it has a fixed input and you have to scale your detected signal to this input. Also, its response time can be hundreds of milliseconds since the ripple is smoothed by fairly large capacitors needed at 50 or 60Hz. And just one more little detail: It requires a bipolar voltage supply.
There are newer devices like Linear Technologies LTC1966 that appear to have improved the approach. I have not personally used this device, so I cannot comment on it.
Unless you are creating a completely analog design with a 4-20mA loop on the back end or a limit detector, you are going to need to convert the signal from a dedicated RMS converter via an ADC. This would offload the AC measurement from the MCU -- it would simply be measuring a proportional DC voltage. However, if you do use an MCU to measure the instantaneous AC voltage directly, you can use it to do the RMS calculation as well. (Thinking out loud here, I wonder if the analog circuitry of the PSoC can be tailored to make the RMS measurement? I will put it on my to-do list.)
Another approach to RMS conversion: a converter board based on a PSoC MCU. Both products had about the same features. There is a slight (although not significant) difference in board area.
The disadvantage is that if you have a very narrow spike you may miss it entirely if your conversion sampling is not fast enough. Obviously, the calculations involving the square root can be computationally intensive and challenging for a small micro, but it does allow you to measure the RMS signal within one cycle. I have worked on several projects where the decision based on the current had to be made within 2-3 AC cycles, even if the speedy response sometimes made no sense at all.
In several of the projects where I have used the micro approach, I decided to measure the AC waveform from zero-crossing to the second zero crossing after that so that I had a full cycle. Then I would do the mathematics in the half cycle between this second zero-crossing and the next one with the opposite sense. My program followed this sequence:
- Initiate a variable representing the sum of squares and wait for the zero cross
- Synchronise the ADC conversion timer to start the conversion with as many reading as practical given the need to read each conversion and some minor processing
- At each complete conversion, the ADC reading is taken and squared and added to a running total of the squares. A record of the number of readings is also incremented. Catering for a variable number of readings means that you can work with different input frequencies allowing an automatic adjustment from 50 to 60Hz
- When the second zero crossing is detected, the conversions are suspended and the RMS value can be calculated. First, using the sum of squares that has been accumulated and the number of readings, it is possible to calculate the mean (sum_of_squares/number_of_readings), and then the square root is calculated using the bisection method (see reference in the next paragraph). This is the RMS value.
The best explanation on how to calculate the square root with limited resources was an article entitled "Rooting Around" by Michael Dvorsky in the February 2006 edition of Circuit Cellar. According to the article, the fastest implementation of this approach is when you have access to a hardware multiplier, which, fortunately, I did.
Sometimes, the above approaches are not sufficient. A unique approach was suggested by Jim Williams where the current is converted to heat through a thermistor, and then the resultant resistance changed is measured. Refer to Linear Technology's Application Note 5, "Thermal Techniques in Measurement and Control Circuitry." See the section entitled "50MHz Bandwidth Thermal RMS [to] DC Converter" starting on page 4.
My thanks to Curt Carpenter whose "Do You Do the Math?" (on the former Microcontroller Central site) provided the inspiration for this blog.
Have you ever needed to calculate RMS values?