title: Any Faster RMS Value Calculation in C?
body: <p>I am writing a software for a small 8-bit microcontroller in C. Part of the code is to read the ADC value of a current transformer (ZCT), and then calculate the RMS value. The current flowing through the ZCT is sinusoidal but it can be distorted. My code as follow:</p>
  
  <pre><code>float       adc_value, inst_current;
  float       acc_load_current;           // accumulator = (I1*I1 + I2*I2 + ... + In*In)
  double      rms_current;
  
  // Calculate the real instantanous value from the ADC reading
  inst_current = (adc_value/1024)*2.5;    // 10bit ADC, Voltage ref. 2.5V, so formula is: x=(adc/1024)*2.5V                           
  
  // Update the RMS value with the new instananous value:
  // Substract 1 sample from the accumulator (sample size is 512, so divide accumulator by 512 and substract it from the accumulator)
  acc_load_current -= (acc_load_current / 512);       
  inst_current *= inst_current;          // square the instantanous current
  acc_load_current += inst_current;      // Add it to the accumulator
  
  rms_current = (acc_load_current / 512);  // Get the mean square value. (sample size is 512)
  rms_current = sqrt(rms_current);         // Get RMS value
  
  // Now the &lt; rms_current &gt; is the real RMS current
  </code></pre>
  
  <p>However, it has many floating point calculations. This adds a large burden to my small MCU. And I found that the <code>sqrt()</code> function does not work in my compiler.</p>
  
  <p>Is there any code that could run faster?</p>