Thanks, but i believe the microchip zero crossing detector is not suitable for detecting AC mains zero cross....for these reasons...
We are trying to do Zero Cross detection with the PIC16F18856. The schematic and LTspice sim of what we are doing is as attached.
OUT bit:
Section 21.2, page 316 of the PIC16F18856 datasheet clearly states that zero cross detection is gotten from the setting and clearing of the OUT bit. Section 21.2 states that the OUT bit is set when the current sink is active, and cleared when the current source is active. The problem is that it doesn’t say at what current threshold the sink/source is considered to be “active”.
Square wave:
If the waveform being checked for zero cross is a square wave, then the zero cross circuitry is obviously going to work. If a square wave, then the OUT bit is obviously going to set/clear right at the zero crossing. However, if its a sine wave, then we don’t know where on the rising sine wave the current is going to be great enough for the source or sink to be regarded as “active”. As such, we cant work out where exactly will be the zero crossing.
Detecting zero current:
We could pretend to ourselves that the micro will faithfully detect the exact zero of current. However, if it was capable of doing this, then why does it need the peak of the current to be 300uA? Also, concerning section 21.6, page 318 of the PIC16F18856 datasheet, why, if it is capable of detecting zero current, does it need the peak current to be at least 100uA high?
Does this mean that for the detection of current in the current sink or source, at least 100uA of current flow is needed? –If not, then why is there this 100uA minimum figure?
If the micro can detect the zero of current, then being sensitive to that low level of current would mean that it could easily be messed up by noise…chattering of the OUT bit. Microchip’s TB3138 document recommends a capacitor at the ZCDxIN pin to mitigate noise, but the datasheet makes no mention of this.
So if the ZCD circuitry in the micro can really detect zero current, then is it sub 1uA that it detects as zero Amps?, or sub 2uA?, …or sub 3uA……?.....And if it really is sensitive enough to be able to detect these low levels, then it would be very easily triggered by noise…specially with a signal originating from the mains like in our case.
Sine waves:
This is all relevant for sine waves, because if the detection of current is at some point above zero amps, then how far above zero amps is the detection threshold?.....because with a sine wave, if the current detection point is relatively high, then the OUT bit setting/clearing may well be a significant time interval away from the zero crossing…..and so we will not be accurately pinpointing the zero crossing. All this confusion never arises with bipolar square wave zero crossing…because a square wave immediately rises to its peak at the zero crossing. It is my impression that the ZCD circuit in the PIC16F18856 was designed for bipolar square waves. The datasheet fails to elucidate on the required parameters needed to properly use this ZCD circuit with sine waves. We actually have a microcontroller with nothing more than an “RSERIES” resistor connecting to the ZCDxIN pin and use it with sine waves as in the attached schematic. (ltspice simulation also included). The circuit appears to be working. However, it may be just that we’ve been lucky. –Maybe we have been narrowly operating at the edge of a “tolerance cliff” and are just lucky to not have gone over it……maybe with a different batch of microcontrollers we would not be so lucky, as maybe they would not be able to so closely detect the zero current point. As you can see, our current circuit is interfaced to the mains which is at the other side of a bridge rectifier, so for us, the current source barely operates at all….(it only sources some 2uA). According to section 21.2, page 316 of the PIC16F18556 datasheet, the OUT bit needs the current source to operate in order to be able to get cleared. For our situation, the ZCD circuitry would need to be able to detect 2uA of current flow in order to be able to clear the OUT bit. –Maybe the batchs of microcontrollers that we have so far used have been able to do this, but it is obviously going to be suspected that other batches will not be able to do this….and so we are running the risk that the ZCD circuit will not work.
Contradiction 1:
Another problem is that Microchip’s “Technical Brief” document (TB3138) contradicts the ZCD section of the PIC16F18856 datasheet. TB3138, on page 1, states that the peak current that can be sourced/sinked is 300uA. Wheras the PIC16F18556 datasheet states that this figure is 600uA. Which is it? We need to know because our mains varies from 210VAC to 265VAC, and we need to be sure that at high mains we don’t go above the maximum allowable current.
Contradiction 2:
Also, there is another contradiction…… the datasheet specifically states that it is current flow from the source that clears the OUT bit, and current flow into the sink that sets the OUT bit.
However, TB3138, on page 6, specifically states that the OUT bit changes state when the current into the ZCDxIN pin is zero….Current into the ZXDxIN pin can become zero if only one of the current source or current sink operates. This is a contradiction. According to the TB3138, only the current source or the sink need to be monitored..not both. –This is not in accordance with the datasheet.
Sine wave reference point:
All of the discussion in the datasheet and the TB3138 document concerns detection of zero cross in sine waves that are referenced to the same ground as the microcontroller. In such a case, the current source and sink would obviously alternately operate….and provide similar waveforms in the current source/sink. This is not our application case, because our microcontroller is not referenced to the same ground as the mains, and the mains is at the other side of the diode bridge. The datasheet/TB3138 document makes no mention of our application case.
I don’t think we can be sure of reliable operation of the ZCD circuitry in the micro, and therefore believe we should revert to using a anti-parallel diode optocoupler circuit instead.
The attached simulation shows our application case in the LTspice simulator.
(please note i believe microchip are usually the best at explaining tech points)
TB3138 app note on ZCD
https://ww1.microchip.com/downloads/en/AppNotes/90003138A.pdf
PIC16F18856 datasheet (page 314- discusses ZCD)
https://ww1.microchip.com/downloads/en/DeviceDoc/40001824B.pdf