Mains Zero Crossing Detection - Page 1
Forum section: electronics / projects

author: Bryan
author_rank: Frequent Contributor
timestamp: February 17, 2021, 07:10:36 pm
content: All:For a project I am looking for a mains zero crossing detector, zillions of schematics out there, but I have read that only certain optocouplers are suitable due to the LED diode characteristics they are not true zero voltage detectors. Voltage drop of the LED is 1.2 to 1.6v. I suppose with a 120v mains it would not be that critical? . Anyhow any suggestions for a correct opto-isolator or am I down the wrong path and it doesn't matter.

author: nctnico
author_rank: Super Contributor
timestamp: February 17, 2021, 07:13:03 pm
content: Get rid of the bridge rectifier and use an optocoupler with anti-parallel LEDs

author: MikeK
author_rank: Super Contributor
timestamp: February 17, 2021, 07:27:46 pm
content: Some PIC's have ZCD built in, you just need a current limiting resistor.

author: Benta
author_rank: Super Contributor
timestamp: February 17, 2021, 07:36:47 pm
content: If you want a real 0 V zero-crossing detector for 230 V, there's a lot more effort in it than what you've shown.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 17, 2021, 07:45:12 pm
content: A problem with that circuit is fairly high power dissipation in the resistors.Here is a better solution, which only fires the LED for a short pulse at the zero crossinghttps://dextrel.net/design-ideas-2/mains-zero-crossing-detector.html

author: floobydust
author_rank: Super Contributor
timestamp: February 17, 2021, 07:47:03 pm
content: What aspect is important to your design? It's good to simulate these circuits.With a 120VAC sine-wave, you get get a soft pulse about 2msec wide, +3V to -3V window considered "zero". It will vary with the opto and temperature. So it's not super precise, if you are doing phase-control. But is OK for clocks.Using a low current opto-coupler 1mA (LED) really cuts down on the heat the dropping resistors dissipate.

author: nctnico
author_rank: Super Contributor
timestamp: February 17, 2021, 08:31:54 pm
content: Another approach is to make a HV diff probe (using a couple of resistors in series + differential amplifier) and feed the signal into the ADC of a microcontroller and do the zero detection in software.

author: langwadt
author_rank: Super Contributor
timestamp: February 17, 2021, 08:49:23 pm
content: Quote from: floobydust on February 17, 2021, 07:47:03 pmcompensating for the width of the windows should be easy in software, just measure the window width

author: Bryan
author_rank: Frequent Contributor
timestamp: February 17, 2021, 09:17:48 pm
content: Project would mate to a Arduino, and the mains would be 120v. As I understand it as the LED would shutoff at below a certain voltage (~1.2) so there would not be a zero cross right at 0 and out by a small margin on the phase?Do anti-parallel leds in a opto have a certain name or specification?

author: Bryan
author_rank: Frequent Contributor
timestamp: February 17, 2021, 09:19:42 pm
content: Any chance you could post the LTspice file?. the project I would not think is supercritical, ac motor control, but I am interested in understanding actually how these controllers work. The timing I suspect is not supercritical but a inefficient zero detection I would think would have an impact. And as others have posted, the correction could be taken into consideration in the software.

author: kripton2035
author_rank: Super Contributor
timestamp: February 17, 2021, 09:21:25 pm
content: Quote from: Bryan on February 17, 2021, 09:17:48 pmH11AA1

author: ajb
author_rank: Super Contributor
timestamp: February 17, 2021, 09:29:53 pm
content: Quote from: Bryan on February 17, 2021, 09:17:48 pmYes, but the exact behavior depends on the optocoupler characteristics and line waveform. LEDs, being diodes, don't have much of a VI curve, but they do have one, and you also have to consider the CTR (current transfer ratio) of the optocoupler, which means that the pulse shape and length at the output of the opto will depend on the loading of its output. The pulse as received by a logic level input will also be offset based on the high-going and low-going thresholds of the input and the slop of the pulse edges. Increasing LED current will sharpen the edges, but also increase power dissipation. Distortion of the sine wave on the line due to non-linear loads (like the switching converters that are in everything, as well as motor loads and phase-dimmed lighting circuits) will muddy the waters here as well.Whether any of this matters for you depends on your application. If you wanted to be really precise about it you might go so far as to wrap a PLL around the phase detection, but that's a bit extreme for a lot of applications. A simple window to lockout spurious inputs is probably a good idea though.QuoteGenerally referred to as "AC Input" optocouplers.

author: Bryan
author_rank: Frequent Contributor
timestamp: February 17, 2021, 09:38:30 pm
content: Quote from: mikeselectricstuff on February 17, 2021, 07:45:12 pmQuote from: mikeselectricstuff on February 17, 2021, 07:45:12 pmExcellent article thanks for sharing.

author: floobydust
author_rank: Super Contributor
timestamp: February 17, 2021, 09:39:43 pm
content: In OP's circuit, the detection window will vary with CTR, mains voltage, the MCU DI threshold so it's not ideal but is low component count.The dextrel circuit has more components and is much better in many ways.AC-input opto-couplers have built-in dual LED's and would save the need for a bridge rectifier in the original post. Example:PC814,H11AA814andSFH628Aor olderH11A1.

author: Cerebus
author_rank: Super Contributor
timestamp: February 17, 2021, 09:52:43 pm
content: You might want to take a look at this from EDN (https://www.edn.com/mains-driven-zero-crossing-detector-uses-only-a-few-high-voltage-parts/):I've used variants of this style of circuit several times and it's reliable and accurate.An LTSpice simulation of one of the variants I've built:(The 1G resistors are just to let LTSpice work while retaining a 'floating' mains so that the neutral line isn't just a flat line.)

author: langwadt
author_rank: Super Contributor
timestamp: February 17, 2021, 10:10:47 pm
content: Quote from: floobydust on February 17, 2021, 09:39:43 pmor you could use two optocouplers (or a dual)

author: Zero999
author_rank: Super Contributor
timestamp: February 17, 2021, 10:17:42 pm
content: Quote from: MikeK on February 17, 2021, 07:27:46 pmThat's only safe if it doesn't have to be isolated. I don't see why a special zero crossing detector is required. A simple comparator will do, which plenty of microcontrollers have.

author: langwadt
author_rank: Super Contributor
timestamp: February 17, 2021, 10:32:11 pm
content: Quote from: Zero999 on February 17, 2021, 10:17:42 pmor just a gpio

author: Bryan
author_rank: Frequent Contributor
timestamp: February 17, 2021, 11:39:35 pm
content: Quote from: Cerebus on February 17, 2021, 09:52:43 pmI had to look on Digikey to see if 1Gohm resistors were even such a thing...yup can go up to 500Gohm

author: Cerebus
author_rank: Super Contributor
timestamp: February 17, 2021, 11:51:59 pm
content: Quote from: Bryan on February 17, 2021, 11:39:35 pmWell, in spice you can go up to a teraohm with no difficulty. Obviously the way I've used them in spice is just to satisfy spice's desire to have a connection to ground before it'll simulate most circuits, they're not actually part of the design. In real life most high quality capacitor microphones have real 1G or even 10G resistors in them to bias the microphone capsule. There are other practical real world uses, but I'd bet most of the 1G+ resistors made end up in microphones, and most of the rest in test equipment and other similar instrumentation.

author: fourfathom
author_rank: Super Contributor
timestamp: February 18, 2021, 03:18:53 am
content: That zero-crossing detector is quite clever. I was having trouble figuring it out until I re-drew the output portion. I replaced the LED/resistor with just a resistor for simplicity:

author: Bryan
author_rank: Frequent Contributor
timestamp: February 18, 2021, 05:52:13 am
content: I suppose I am interpreting the graph incorrect but doesn't it show that the rising edge of I(d6) at 30volts?

author: joeqsmith
author_rank: Super Contributor
timestamp: February 18, 2021, 12:22:35 pm
content: Quote from: ajb on February 17, 2021, 09:29:53 pmGood input. Attached are a couple of articles.

author: RoGeorge
author_rank: Super Contributor
timestamp: February 18, 2021, 12:35:22 pm
content: Quote from: mikeselectricstuff on February 17, 2021, 07:45:12 pmBuilt that one a couple of times and it worked very well, the pulse is symmetric around the zero crossing point.

author: Cerebus
author_rank: Super Contributor
timestamp: February 18, 2021, 05:30:35 pm
content: Quote from: Bryan on February 18, 2021, 05:52:13 amYes, if you look the pulse is centred around the zero crossing, with the component values chosen to make the pulse width ~1ms. It has a predictable and consistent delay (subject to the usual factors that effect drift in any analogue circuit, tempco of components etc.). One can adjust the component values to make the pulse narrower, subject to the capacitor holding enough charge to adequately drive the LED in an optocoupler.That it comesbeforethe zero crossing is no particular issue, a circuit that triggered exactly at the zero crossing would in practice, because of propagation delays, deliver the zero-crossing indicationafterthe zero-crossing. Having the signal trigger slightly beforehand is actually an advantage for many applications - if you want to switch somethingatthe zero crossing it's more useful to know that the zero crossing is coming up in ~500us rather than has just departed 100us ago. If you're using the zero-crossings just to measure the frequency of the mains you don't care about the delay either way as it's indication-to-indication timing that's of interest.

author: Bryan
author_rank: Frequent Contributor
timestamp: February 18, 2021, 06:47:18 pm
content: Quote from: RoGeorge on February 18, 2021, 12:35:22 pmYes, ordered the parts today from Dig along with a H11AA1.Another project I have in mind is reusing a older aquarium controller that utilized X10 for the outputs to control equipment. X10 is too unreliable so I wanted to probe the output and use a separate MCU to drive some relay boards. I suspect the output from the controller will only send out X10 data when it receives a zero detection pulse from a PL503 (wrong name?) module. At least that is my understanding of the X0 protocol

author: Bryan
author_rank: Frequent Contributor
timestamp: February 18, 2021, 07:04:25 pm
content: Quote from: Cerebus on February 18, 2021, 05:30:35 pmAnd I suspect that is consistent with any zero detection circuit. Some may zero cross at different points (phase) on the ac signal depending on design, but as long as it is consistent one could incorporate that in software or other means and yes knowing ahead of time is always better than trying to catch up in most applications. If I look at the Ltspice example and if one delayed in software by 1-2 ms or so it would be a consistent crossing at zero.

author: cellularmitosis
author_rank: Unknown
timestamp: October 08, 2022, 12:05:15 am
content: Quote from: mikeselectricstuff on February 17, 2021, 07:45:12 pmLooks like the link has changed:https://dextrel.net/dextrel-start-page/design-ideas-2/mains-zero-crossing-detectorThanks for recommending it, great little circuit!

author: Terry Bites
author_rank: Super Contributor
timestamp: October 08, 2022, 09:11:35 am
content: Its going to costy more time, effort, risk (to life and your project) and parts cost than buying a rerady rolled. BM1Z001, 4 loonies.