Yes but you can filter the noise out quite easily without a correlation. By the 0 crossing you know were you are in the 50hz main cycle, you know also in which direction the waveform will move by the past samples. With these information and validating some 50hz main period I think that it would not so tricky to do the job.
Actually the correlation is very easy to implement into a real device, with good selection of sample rate it become even less demanding on the computing power than the filtering and diferenciation.
Only the mathematical theory behind is not as trivial, so it appear a bit more complex:
Into a look-up table you put the signal you want to find the correlation with, in our case a rectangle minus it's first harmonic content (you calculate it in an Excell or similar tool). There could be only one half of the period, as the other half would be generated as the copy and evaluated as being negative
As we know the phase of our signal we are looking for, we need to find the correlation only in some time spots, where the voltage is in phase with our "reference" signal in our LUT. If the lamp is not lit, so the measured signal is a sinewave, the result of such single point of correlation would be zero (remember, we subtract the 1'st harmonic from the reference signal - just to have this zero). If the lamp is lit and so the voltage is nearly rectangular, we get quite a strong correlation with our reference.
Now how to compute the correlation? First we have to make an internal generator of the reference signal: A phase wheel generating a pointer (actually incrementing it for each sample and let it overflow after 1 mains period; therefore it is beneficial to have the number of samples corresponding to one mains period as 2^n) into our predefined LUT.
As the measured and "generated" samples go, let's multiply the measured with the generated one and sum all the results from one period.
And viola, this sum is the desired correlation level to be evaluated. It would be good to perform some averaging across few periods (it is then processing of 50sa/s)
So each sample you do:
- Increment the phase wheel, use as the LUT pointer (7-bit operation for 128samples per period)
- Multiply the ADC result with the value from the LUT (8bit signed char arithmetic is sufficient)
- Add the result to the correlation accumulator (16 bit signed arithmetic).
You may store the LUT values in the format of the minus sign in the MSB and the absolute value in the rest, while during the multiplication use only the absolute value and with the negative sign use subtract instead of the addition in the next step. By that you eliminate the need of sign-aware multiplication, so the basic "mul" instruction could be used.
Every pisitive slope zero cross detect:
- Take the correlation result, do a low pass filtering with the values from last cycles
- Compare with a threshold, so determine, if the correlation is above or below the threshold
- Reset the correlation accumulator (so it could accumulate the correlation for the next cycle)
- Correct the phase of the Phase wheel, adjust (speed up/slow down) the exact sample rate so, the phase wheel "rotate" in sync with the voltage (so the PLL)
Sorry but you are wrong. Modern PIC like the 10F222have a power consumption of 170uA@4MHz with a power supply of 2V or 350uA at 5V. The AD converter add 80uA at 2V.
Well, you are partially right.
But if you want reasonable functionality of the ADC, the supply voltage should be high enough and quite clean, mainly from all components form the mains frequency and it's harmonics, as these would correlate with the measured signal, so cause error.
So the controller would consume about 500uA, plus you would need some active voltage regulator (large, high quality electrolytic won't fit into the starter socket), consuming another about 0.5mA, so 1mA in total, so we are at about 250mW, so indeed quite manageable...
This is for sure, but I think that with some work it would possible to do the detection with the PIC without increasing to much the cost (the PIC itself would cost 0.3-0.5$ for 5kpieces).
Well, that is quite a lot, but the current detection would need at least an optocoupler and 4 pins...