Hi, sorry but I can’t answer to this topic: https://openenergymonitor.org/emon/node/11143 (I don’t know why, and also I can’t register in that page)
After reading how emonlib Works, I am trying to understand it
I have seen that calcIV check zero-crossing and evalute correctly the RMS value after detecting several cycles.
Otherwise, calcIrms is calculated by number of samples.
The “problem” here is that the number of samples, as far as I know, works with one type of IC with a known frecuency of 16 MHz.
What about any other IC, or an different or externa ADC, or ATMEGA328P but at 8Mhz ?
I think the value could be calculated with these two options:
First option: calculate every loop how much time take a ADC Reading, and compute how many samples to get 10 or whatever complete cycles you want.
(pseudo code)
start=micros();
analogRead;
calculate whatever;
end=micros();
time = end-start;
samples = (1/50Hz*10cycles)/time;
counter=0;
for (counter to samples) {
analogread();
calculate whatever:
};
Second option and which I like most (the option 1 could be wrong as may be that all the readings doesn’t last the same microseconds)
This options monitorize the time so you will always get 10 complete cycles (or what you like)
(pseudo code)
totalTime = 1/50Hz * 10cycles;
counter=0;
begin = micros();
while micros() < (begin + totalTime) {
analogread();
calculate whatever:
counter++;
};
I think this way calcIrms will be ok for whatever IC or IC’s frecuency or ADC (ADS1115, ACS712, internal ATMEGA ADC, and so on). You always need to check that samples per cycle it is ok for your needs.
Also, with option 2 it won’t be necessary to dectec zero crossing in calcVI, will it ? It won’t be necessary, will it?
I have done a simple Excel with a “perfect sine wave” and evaluate the RMS value by getting samples from zero crossing point and from other point, but always getting complete cycles. The RMS calculated value is always the same.
I am sure that “I haven’t discover the wheel” so I think I am doing mistakes.
Please, tell us what you think and/or check my mistakes.
Regards,