Hi all
it seems to me that there is a bug in the proposed initialization for the function "SINEANALYZER_DIFF_F", comprised in "SolarLib" application library.
Because the initialization function "SINEANALYZER_DIFF_F_init" simply clears to zero internal fields and the description of the library suggest to initialize only the fields "SampleFreq" and "Threshold",
the fields "nsamplesMin" and "nsamplesMax" remains = 0, while they are used in the processing function to validate the detected zero-cross point.
I think they should be initialized, after the call to "SINEANALYZER_DIFF_F_init" and before the use of the computation function, to something like:
nsamplesMin = sample freq / max grid frequency
nsamplesMax = sample freq / min grid frequency
In fact, the file SolarLib.pdf suggest this initialization for the "SINEANALYZER_DIFF_wPWR_F" version of the routine (the one that calculates also the power), but these values are used also in the "lighter" version:
if(v->nsamplesMin < v->nsamples < v->nsamplesMax)
{
// computations @zero-crossing point
}
and for this reason they need to be initialized.