Good day everyone. I also didn’t understand the purpose of ‘offsetV = ADC_COUNTS>>1;’ and ‘offsetI = ADC_COUNTS>>1;’, but managed to understand them after finding this thread on google.
In addition, I would like to ask the meaning of additional line. Please let me know if I should open a new thread instead of replying on this one. Thank you.
The first one is related to the following command:
(line 99) lastFilteredV = filteredV; //Used for delay/phase compensation
I noticed that this is the first time ‘filteredV’ and ‘lastFilteredV’ is defined in ‘EmonLib.cpp’. I am still new in arduino. If the arduino runs this line for the first time, will ‘filteredV’ and ‘lastFilteredV’ will be assigned as ‘0’ (zero) by default for the first time?
The second question is related to the following commands:
(line 111) offsetV = offsetV + ((sampleV-offsetV)/1024);
(line 112) filteredV = sampleV - offsetV;
(line 113) offsetI = offsetI + ((sampleI-offsetI)/1024);
(line 114) filteredI = sampleI - offsetI;
I have no idea how this digital filter filter works. May I know what is the purpose of ‘((sampleV-offsetV)/1024)’ in line 111? After that, may I know why ‘((sampleV-offsetV)/1024)’ have to be added to ‘offsetV’ (also in line 111)? Then, may I know why we have to perform ‘sampleV - offsetV’ (in line 112), which I believe is also similar to ‘sampleV - (offsetV + ((sampleV-offsetV)/1024))’ (the combination of line 111 and 112). Please let me know if there is any related material available related to this.
The third question is related to the following commands:
(line 131) phaseShiftedV = lastFilteredV + PHASECAL * (filteredV - lastFilteredV);
(line 136) instP = phaseShiftedV * filteredI;
I am also have no idea how does this part works. If anyone have reading material related to this, I would like to ask you to let me read it. One more thing, if it is the first time the arduino is going to run this loop, the value for ‘lastFilteredV’ will be ‘0’ (zero) by default, right?
The fourth question is related to the following commands:
(line 158) double V_RATIO = VCAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
(line 159) Vrms = V_RATIO * sqrt(sumV / numberOfSamples);
(line 161) double I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
(line 162) Irms = I_RATIO * sqrt(sumI / numberOfSamples);
May I know why the SupplyVoltage hac to be divided by 1000.0 in line 158 and line 159?
I think that is the question that I would like to ask at this moment. Thank you very much and have a nice day.