# Will this zero-cross detection circuit work?

I have a 10W SMPS circuit powering a home appliance like this:

I need to extract a zero-crossing pulse from this circuit which would then be fed to a micro-controller. To this end, I am considering the following modification to the circuit:

Specifically, I have added an opto-coupler PC817 whose input LED would be driven from the rectified ~340V (0 to peak) through R16 (330k, 1/2W resistor). The maximum input current to the opto-coupler would thus be ~1mA. Considering the CTR to be 0.8, from the datasheet, the collector current would be ~0.8mA. Accordingly, I am considering a 33k resistor for R17. Have also added D10 (1N4007) to isolate it from the smoothing capacitor.

1. Are the calculations correct? Will the circuit work?
2. Is it okay to drive the opto-coupler LED from ~340V? Would it damage the components or make the circuit less reliable?
3. How to estimate and minimize the pulse width at the zero-cross output so that it is closer to the zero-crossing?
• With only 1 mA peak going through the LED, it will probably do a decent job of detecting the peaks of the AC waveform, but when the input voltage is more like 20V near the zero-crossing, there will only be a few tens of uA going through the LED and the transistor, which will give you a very sloppy indication of the timing at best. – Dave Tweed Jan 12 '15 at 12:44

The speed of the phototransistor optocoupler is possibly a problem, as Andy has already flagged.

Also consider what threshold you are trying to achieve. If you want a zero-crossing pulse centered about the zero crossing and turning off at (say) +/-10V then you need to supply sufficient current to the LED to make that happen. Say that's 5mA. You now need to limit the current at the AC peaks to some reasonable value, and with a resistor it will be ~33 times higher, of course ($\frac {230\sqrt{2}}{ 10}$).

To get the width (ignoring the speed of response of the circuit) we know that the voltage is about 325 sin($\omega$t) where $\omega$ is the angular frequency of $2\pi 50$ radians/second.

So the width of the pulse will be pw = (2/$\omega$)$sin^{-1}$(Vzc/325),

or, in general

pw = ($1\over\pi f$)$sin^{-1}(\frac{Vzc}{Vline \sqrt 2})$

For example, if the voltage is +/-10V, then the pw will be about 200usec. For small voltages it will be approximately proportional since the rate of rise of a sine wave is almost constant near the zero crossing. So, a +/-5V voltage will give you a 100usec pulse, ideally preceding the zero crossing by 50usec and following the zero crossing by 50usec.

To make a precision zero crossing detector, you would be best to derive a power supply from the mains (maybe the TNY has some voltage you could borrow) and use a comparator of some kind (I've often used discretes because they're more immune to nasty stuff on the mains) to actuate a high speed logic-output coupler, so the LED in the opto sees only 5mA or 0mA.

• I'll try to do this backwards since the requirement here is a high-to-low transition close to the zero-cross to trigger a micro-controller interrupt. If I want the pulse centered at 100us on both sides of the zero-cross, then the threshold voltage would be 10V with the above calculations. How do I get the value of sufficient current then (5mA in your example)? The datasheet doesn't seem to mention this. The comparator solution sounds more precise, but I'm keeping it simple as a beginner for now. – Sohail Jan 13 '15 at 8:24
• If you're using a logic output opto, as I recommend, the current and propagation delay will be specified right in the datasheet. It will not be simple to get a pc817 to work. – Spehro Pefhany Jan 13 '15 at 12:23

The rise/fall time of the opto is about 20 microseconds (1000 ohm load) and the time when the rectified voltage is close to zero is maybe 2 degrees of one cycle. At a 20ms period of AC, a couple of degrees is about 100us. It's getting to close to not working is my impression.

Looking at the frequency response graph on page 8, with a collector resistor of 33k you'll be lucky to get 1kHz through this device so I reckon you won't see much of a signal. Even with a 100 ohm load the bandwidth is only going to be about 50kHz and will probably just about work. This would mean a rehash to your optical receiver circuit.

None of this takes into account the reverse recovery time of the bridge rectifier and 1N400x diode or any stray capacitance that might slug the shape of the full-wave rectified signal you hope to have.

• Just never thought of the rise/fall times... It's over 30us apparently for a collector resistance of even as low as 3k. This device is probably not meant for this kind of application. But I'm not sure I understand the part about the frequency response. If the input LED would only be driven by 50Hz mains, should the frequency response be considered? – Sohail Jan 13 '15 at 6:52

Andy aka is correct, but if you still want to give it a try I'd suggest the following modification

simulate this circuit – Schematic created using CircuitLab

ETA - Please ignore this paragraph - The reverse diode corrects the immediate flaw in your design - reverse voltage on the LED. The opto data sheet, oddly, has no spec on maximum reverse voltage, but I'll guarantee you that your LED would not survive a single cycle of the mains voltage.

By putting the optocoupler on the input of the bridge, you get a more positive zero indication than when you look at the output. It's not a panacea, though, since optos are famous for having different turn-on and turn-off times. To get around this, you can try

simulate this circuit

with two optos back to back and the outputs wire-or'ed. Even this is not guaranteed, though, since if the turn-off time is too much greater than the turn-on time, you'll get no output pulses at all.

Actually, your idea has merit, but if you want to try it, you need to look at faster optocouplers. They do exist.

• How do you reckon the LED is going to see any reverse voltage? – Spehro Pefhany Jan 12 '15 at 17:20
• Oh, bother. I confused my circuit with his. Oh well, that's what edits are for. – WhatRoughBeast Jan 12 '15 at 20:56
• Hmm... I'll try that for a new design. But I already have a prototype of the SMPS (in which I forgot to incorporate a zero-cross detector and hence this grind :-P). Plus there are TWO opto-couplers. Actually a faster opto-coupler would help in either solution yeah... – Sohail Jan 13 '15 at 8:32