The voltage output by the current sensor and measured by the Netduino needs to be corrected using the offset value then the RMS value calculated. This RMS value then needs to be adjusted taking into account the voltage range of the Netduino analog input (0V-3V3), the resolution of the analog input (12 bits) and the voltage output by the non-invasive current sensor (0~1V for 0~30A).

My approach appears to produce reasonable values but I will need to compare them with a calibrated reference device to check its accuracy. The 18W measurement with no current flowing is due to the noise on the analog input discussed in an earlier post.

The first version of the software used the initial offset value, the second version updates the offset value at the end of each set of samples.

int valueSum = 0;

int valueSumSqr = 0;

int offset;

AnalogInput x1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);

// Calculate the sum for initial offset

for (int i = 0; i < SampleCount; i++)

{

valueSum += x1.ReadRaw();

}

offset = valueSum / SampleCount;

…

Stopwatch stopwatch = Stopwatch.StartNew();

stopwatch.Start();

for (int i = 0; i < SampleCount; i++)

{

int value = x1.ReadRaw();

value -= offset;

valueSumSqr += (value * value);

}

stopwatch.Stop();

double rms = System.Math.Sqrt((double)(valueSumSqr / SampleCount));

double rmsCurrent = rms * (3.3 / 4096.0) * 3.3 * 30.0;

double rmsWatts = rmsCurrent * 230;

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2588 mSec 38639/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2587 mSec 38654/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

int valueSum = 0;

int valueSumSqr = 0;

int offset;

AnalogInput x1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);

// Calculate the sum for initial offset

for (int i = 0; i < SampleCount; i++)

{

valueSum += x1.ReadRaw();

}

offset = valueSum / SampleCount;

…

Stopwatch stopwatch = Stopwatch.StartNew();

stopwatch.Start();

for (int i = 0; i < SampleCount; i++)

{

int value = x1.ReadRaw();

valueSum += value;

value -= offset;

valueSumSqr += (value * value);

}

stopwatch.Stop();

offset = valueSum / SampleCount;

double rms = System.Math.Sqrt((double)(valueSumSqr / SampleCount));

double rmsCurrent = rms * (3.3 / 4096.0) * 3.3 * 30.0 ;

double rmsWatts = rmsCurrent * 230;

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Duration = 2816 mSec 35511/sec RMS 1.0 RMS Current 0.1A RMS Power 18W

Both versions appear to sample the output of the non-invasive current sensor at a more than sufficient rate.