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

![vanellope_smps](https://i.stack.imgur.com/hNyXG.jpg)

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:  

![vanellope_zc](https://i.stack.imgur.com/8kQij.jpg)

Specifically, I have added an opto-coupler [PC817](http://www.sharpsme.com/download/pc817x-eJpdf) 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](http://www.diodes.com/datasheets/ds28002.pdf)) 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?

Answer: 
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.
Andy aka is correct, but if you still want to give it a try I'd suggest the following modification

![schematic](https://i.stack.imgur.com/3nRcg.png)

[simulate this circuit](/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2f3nRcg.png) – Schematic created using [CircuitLab](https://www.circuitlab.com/)

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

![schematic](https://i.stack.imgur.com/sk0QX.png)

[simulate this circuit](/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fsk0QX.png)

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.