I'm trying to do a zero-crossing detector but it is only able to mark half the number of zero passings. It seems to work fine with input voltages of 10-20V, but when using a +120VRMS it checks only on certain parts of the cycle.

Op-amp datasheet.

The circuit is:

enter image description here

and the output is:

enter image description here

Another minor issue is that the LED isn't working when biasing at 5V. Will it bring any noise or saturation/heat problems if enough voltage is used to make the LED work?

  • 1
    \$\begingroup\$ You could just buy something that already does zero-cross detection for you. Or is there a reason you like TLV3701CDs? \$\endgroup\$
    – jonk
    Nov 25, 2021 at 19:36
  • 1
    \$\begingroup\$ I don't have an answer for your specific issue but for zero cross detction, you do not need to step down with a divider. You can just use series current limiting resistor and clamp diodes (like rail clamps). That will result in improved sensitivity. \$\endgroup\$
    – DKNguyen
    Nov 25, 2021 at 20:03
  • 1
    \$\begingroup\$ @riccs_0x If there is a reason to avoid boutique parts and you actually would prefer a discrete version, let me know. That's fairly easy to do, though some nodes will need to be protected from grasping hands. A simple battery can be used to supply the rail for it, as well. You'd be responsible for worrying about single failure paths, though. \$\endgroup\$
    – jonk
    Nov 25, 2021 at 20:09
  • 1
    \$\begingroup\$ I don't see how the divider is supposed to add positive feedback. \$\endgroup\$
    – DKNguyen
    Nov 25, 2021 at 20:29
  • 1
    \$\begingroup\$ @riccs_0x Consider using a simple 1st order RCR pi filter at the input and two NPN BJTs wired in such a way that the filtered and attenuated sine/cosine is clamped near ground and looks about like a square wave centered over ground. From there, you have two open collectors, active on alternating cycles, that you can then use with no more than three other parts to generate very narrow pulses. A battery voltage will be needed. I think 5 resistors, 1 tiny cap (pF), 3 BJTs + battery. \$\endgroup\$
    – jonk
    Nov 25, 2021 at 20:33

1 Answer 1


Here's a topology to consider (and improve upon):


simulate this circuit – Schematic created using CircuitLab


On the left is a spike filter and attenuator. The transfer function for this single-pole filter is the usual \$K\frac{\omega_{_0}}{s+\omega_{_0}}\$ where, in this case, \$K=\frac{R_3}{R_1+R_2+R_3}\$ (kind of obvious) is the attenuation and \$\omega_{_0}=\frac{R_1+R_2+R_3}{R_1 C_1\left(R_2+R_3\right)}\$ is the angular frequency for the low-pass cross-over point.

You should set \$K\$ such that the attenuated input to the BJTs is safely limited (\$1\:\text{mA}\$ or less, probably.) However, the more current you permit the narrower the pulse. So there is some balancing here.

You should set \$\omega_{_0}\$ so that it doesn't impact anything at the line frequency (you do not want any phase-shift as that defeats the point of the circuit), but where it also simultaneously filters out spikes. (Anyone turning on a motor [or worse, an x-ray machine] can generate spikes that ride on the AC.) Where you set it is up to you, but I'm vaguely thinking in the area of \$5 \:\text{kHz}\$, more or less. (I'm assuming you understand that \$\omega_{_0}=2\pi\,f_{_0}\$.)

Note about safety: I'm still alive after more than a handful of decades. This means I've survived the stupid things and learned enough to reduce the odds of doing too many more of them, so far. But I'm as likely to recommend the wrong thing out of over-confidence, as the right thing. So I'll avoid saying much here except that you may want to carefully consider what to do about any single part failure, short or open. This aspect is your business, not mine. There aren't a lot of parts to consider, luckily.

I mentioned the need to now clamp the AC signal that results from this filter, so I'll discuss that aspect in the next two sections.


The positive-going sub-circuit is a pretty obvious addition. It's just an NPN BJT (\$Q_1\$) arranged to clamp the AC signal when it rises positive with respect to neutral/ground and pull down hard on \$R_4\$ and cause \$V_{_\text{OUT}}\$ to be held LOW. \$R_4\$ is the obvious pull-up resistor here.

You can set this per your needs, though again details matter and making \$R_4\$ larger (a lighter load) may help \$Q_1\$ saturate a little closer to the zero-cross region you want. I'm sure you can work out reasonable values. But I'd suggest anything from about \$15\:\text{k}\Omega\$ to about \$33\:\text{k}\Omega\$ might be something to consider -- depending of course upon whatever you wind up tying to \$V_{_\text{OUT}}\$ as its load circuit.

This is a simple sub-circuit, so I'll move on to the next part.


So, the more obvious part of this circuit is dealing with the need for clamping when the AC signal goes negative with respect to neutral/ground. And \$Q_2\$ is arranged in this next sub-circuit to do exactly that. I "see" \$Q_2\$ as cascode-arranged, mentally, with the AC signal tugging down on the emitter to generate current that is delivered towards its collector.

This current, when generated, needs to also pull down on \$V_{_\text{OUT}}\$ to keep it LOW. (Remember that the pull-up, \$R_4\$, is in the sub-circuit described in the section before this one.) This can be done using a PNP BJT (\$Q_3\$) arranged as shown. Note that when \$Q_2\$ saturates, its collector will be pulled very close to its emitter voltage, which will be about a diode drop below ground. This will pull \$Q_3\$'s base down below ground, too, and cause it to saturate so that its emitter is very close to ground.

During the short moment when the AC signal is close to ground, \$Q_2\$ turns OFF. So \$R_5\$ is added to help more quickly discharge the parasitic capacitance in \$Q_3\$. This helps sharpen the pulse. Because this capacitance is small, \$R_5\$ can be large -- halfway to a MegOhm, perhaps? Maybe even higher?


That's about it. There are always improvements to consider. (Two come to mind right away.) But I think it may not be worth the bother.

Oh, and \$V_{_\text{BAT}}\$ can be pretty much any available battery voltage that's convenient. A \$9\:\text{V}\$ battery would work, for example. But for the above circuit, to allow me to avoid discussing possible problems with AC mains-driven DC power supplies, I'll stick with recommending that you only use a battery. Otherwise, the safety of your choice is again on your shoulders.

  • \$\begingroup\$ I'm very sorry that I haven't worked enough, and after your great advise and information. I lacked the time, but I'm still working at it. I don't want you think less of me. Thanks again. \$\endgroup\$
    – riccs_0x
    Nov 29, 2021 at 18:16
  • 1
    \$\begingroup\$ @riccs_0x I'm just happy to hear you are working at the issue. That's the important part. And no problem. I think the above will be of some use, at least for comparing with other approaches, if nothing else. \$\endgroup\$
    – jonk
    Nov 29, 2021 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.