Community
OpenEnergyMonitor

Community

Hi im a reallly beginner in Arduino

Tags: #<Tag:0x00007fedd0a684f0>

Hi i have some question about Emonlib!!
Is there anyone who can help me?
im trying to measure CT currents with Arduino.
so im studyng Emonlib now, but i cant understand well…
could you tell me somethings??

In Emonlib code
Line number142 ~ 147

lastVCross = checkVCross;
if (sampleV > startV) checkVCross = true;
else checkVCross = false;
if (numberOfSamples==1) lastVCross = checkVCross;

if (lastVCross != checkVCross) crossCount++;

i cant understand what is this means for

and
line number 185 ~ 198

or (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;

why we need to do it again??
i think we already solve Vrms, Irms in line156~160

and…in line 201~202
is it okay we dont need to get Vrms???

i wll be really appreciate if somebody help me

Welcome, Evan, to the OEM forum.

EmonLib had two main functions (they are called “methods” in C++), calcVI( ) and calcIrms( ).

calcVI( ) calculates the real power flowing when you are able to monitor both the voltage and the current supplied to your load. calcIrms calculates only the root-mean-square average current (like an ammeter). Both calculate the average over a period of time: calcVI( ) uses a count of zero crossings of the voltage, but because you do not have the voltage for calcIrms( ), you must tell it how many current samples to read. Ideally, both these must calculate the average over a complete number of cycles to be accurate, but this can never be achieved in the real world. Therefore, for calcVI( ), we wait until the mains voltage crosses through zero before we start counting and averaging the readings. This is what lines 87 - 89 do. Notice startV - it is the last voltage sample before you decided to start - so it is close to 0 V. Then, you must count each time the voltage crosses through zero so that you know when to stop. In line 143, if the voltage is greater than startV, we set checkVCross - we have a positive-going zero crossing. Otherwise checkVCross is false and we have a negative-going zero crossing. (Line 145 sets up the first time round). In line 147, when checkVCross changes from the last time - remembered by lastVCross in line 142) we count a zero crossing.

Because calcIrms( ) is quite separate from calcVI( ). You can use either, you will never use both at the same time (although you can - but why? calcVI( ) gives you Irms, Vrms, real power apparent power and power factor, all with one set of measurements). You will normally use calcIrms( ) only when you cannot measure the voltage, for example you have an emonTx using battery power to operate because there is no mains socket.