AnalogRead has a speed of about 1ms. I have a question here. How can I measure the power using analogRead()? The value of analogRead() has not changed.
That is very slow; there must be something wrong with your testing. As said, an AVR does a single analogRead() in approximately 100 microseconds and I expect your board to be a lot faster.
I do not understand. I did not say that you had to use analogRead(); I just needed you to understand where the slowness of your code comes from.
Did you have a look at what calcIrms() does? It simply uses analogRead().
double EnergyMonitor::calcIrms(unsigned int Number_of_Samples)
{
#if defined emonTxV3
int SupplyVoltage=3300;
#else
int SupplyVoltage = readVcc();
#endif
for (unsigned int n = 0; n < Number_of_Samples; n++)
{
sampleI = analogRead(inPinI);
// Digital low pass filter extracts the 2.5 V or 1.65 V dc offset,
// then subtract this - signal is now centered on 0 counts.
offsetI = (offsetI + (sampleI-offsetI)/1024);
filteredI = sampleI - offsetI;
// Root-mean-square method current
// 1) square current values
sqI = filteredI * filteredI;
// 2) sum
sumI += sqI;
}
double I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
Irms = I_RATIO * sqrt(sumI / Number_of_Samples);
//Reset accumulators
sumI = 0;
//--------------------------------------------------------------------------------------
return Irms;
}
According to the processor datasheet, the processor on your board can achieve 350 ks/s, so roughly 3 microseconds for a sample.
I do not know the processor on your board. You can change the resolution using analogReadResolution() - Arduino Reference; a lower resolution should speed up the reading (but you will never reach the theoretical maximum).