Root mean square (RMS) is a fundamental measurement of the magnitude of an AC signal. Defined practically, the RMS value assigned to an AC signal is the amount of DC required to produce an equivalent amount of heat in the same load. Defined mathematically, the RMS value of a continuous signal V(t) is defined as:
For time sampling signals, RMS calculation involves squaring the signal, taking the average, and obtaining the
square root
I use equation 2 to compute RMS value of the incoming AC signal. When AC input is detected the instrument
collects 2048 samples of data if both channels are running or 4096 samples for a single channel. The data gets
processed according to equation 2 and RMS value is computed. The following is INT2 interrupt routine to compute sum of squares. The interrupt is triggered on data ready pulse from MCP3911.
void __attribute__((interrupt, no_auto_psv)) _INT2Interrupt(void) {
union {
unsigned long nvoltage; // Negative values
struct {
unsigned char voltLSB : 8;
unsigned char voltNSB : 8;
unsigned char voltMSB : 8;
unsigned char voltd : 8;
};
} negative;
unsigned long voltage_sum_p_sqr;
// Compute sum of squares
voltage_sum_p_sqr =voltage_sum_p_sqr+(negative.voltMSB * negative.voltMSB);
}
Most of AC measurement from my experience are high in amplitude, usually in Volts. So, using only MSB
byte of the 24 bit value gives me good resolution for all of the AC measurements. Once sum of squares is calculated Vrms is computed using equation 2.
v_smple_sum = (voltage_sum_p_sqr / buffer_lenght);
RMS = sqrtl((long double) v_smple_sum);
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.