6
\$\begingroup\$

I'm designing a digital phase-controlled light dimmer, and I need a zero-crossing detector circuit. From what I've read, it's a bad idea to wire the AC main directly to the microcontroller through a resistor, and folks have suggested using optoisolation instead. However, I don't know how the circuit actually falls together.

It would seem elegant to me if the zero cross circiut's output is a 5V logic pulse for use as a rising-edge interrupt. But I'm not married to that idea if some other output is easier to use.

Input: 120V AC @ 60 Hz
Output: 5V pulse at zero crossing

Interesting related post, with not enough detail for me: detecting zero cross in ac?

\$\endgroup\$

4 Answers 4

7
\$\begingroup\$

Why not use an optocoupler? Vishay's SFH6206 has two LEDs in anti-parallel, so it works over the full cycle of the mains voltage. If the input voltage is high enough the output transistor is switched on, and the collector is at a low level. Around the zero crossing, however, the input voltage is too low to activate the output transistor and its collector will be pulled high. So you get a positive pulse at every zero crossing.

enter image description here

The most important parameter for an optocoupler must be its CTR or Current Transfer Ratio, which gives you the ratio between output current and input current. You can compare it with the \$H_{FE}\$ of a common BJT. But while \$H_{FE}\$ for a small signal transistor is often higher than 100, CTR is low. So low that it's expressed in %, like 20%. That's not 20, that's 0.2.
A CTR of 0.2 means that you have to drive the input LED(s) with 1mA to get a mere 200\$\mu\$A out. Usually that's not a problem, since the output is often only used to get a logic level, which will connect to a high impedance input. In that case a high value pull-up resistor can be used, like > 27k\$\Omega\$ in a 5V system. Then the 200\$\mu\$A is sufficient to drive the output low.

Detailed calculations can be found here.

\$\endgroup\$
2
  • \$\begingroup\$ What's this? No description of the link besides "Detailed calculations"? Man steve, you sure have to taste your own medicine. \$\endgroup\$
    – kevlar1818
    Commented Jun 1, 2012 at 13:02
  • \$\begingroup\$ I used this exact same circuit a few years back. Works like a champ to this day on this project: bradgoodman.com/dimwatt Only advise is that I needed about 6k of resistance - across 120V input. That means you need to use resistors rated at 2.5 watts (in this example). \$\endgroup\$
    – Brad
    Commented Nov 30, 2017 at 19:27
5
\$\begingroup\$

A while ago I created the exact same thing... a light dimmer using a triac with the timings calculated from the zero crossing signal send to the interrupt pin on a pic16f877a.

I took the zero crossing signal from the PSU that powers the circuit before it's smoothed and regulated. There are a few components to change the rectified humps of the AC into very short +5v pulses of around 200uS. Most of the time, the transistor (shown as Q in the diag) is conducting pulling the RB0/INT pin low, but when the AC dips below 4.7V briefly it stops conducting and the signal is pulled high by the resistor R.

Zero Crossing Schematic

The pulse is centred around the zero crossing, and it should be short enough to roughly detect the zero crossing moment. But you can fine tune this in software, by first detecting the rising edge of the pulse, then timing when the falling edge happens, then dividing this in half and adding this time period to the next rising edge... this will give you the exact zero crossing.

\$\endgroup\$
12
  • \$\begingroup\$ What are the specs for the transformer you're using here? What reasoning did you use to determine the values for R1 & R2, and for the capacitors? \$\endgroup\$ Commented Jan 7, 2011 at 4:18
  • \$\begingroup\$ Well I'm in the UK so my mains is 230v 50Hz, so my transformer would be different, I can't remember exactly but it would likely have been a 230v primary, 2 x 12v secondary 3VA transformer. The circuit will work just as well with your voltage / frequency though. \$\endgroup\$
    – BG100
    Commented Jan 7, 2011 at 4:22
  • \$\begingroup\$ The capacitors don't have any bearing on the zero crossing circuit as they are just for smoothing the supply. I think the resistor values were chosen by trial and error to get them right, the other important components are the Zener diode and transistor. If you put a scope on the output of the zero cross circuit, you'll get a very short quick 5v pulse at exactly the zero cross time. \$\endgroup\$
    – BG100
    Commented Jan 7, 2011 at 4:27
  • \$\begingroup\$ Also, I notice that your concerned about the safety of working with mains voltage, with this circuit as long as you have all the wires insulated properly up to the transformer before you plug it in and switch it on, then everything else is at a safe voltage... Apart from the triacs of course but they are out of the scope of this question. \$\endgroup\$
    – BG100
    Commented Jan 7, 2011 at 4:39
  • \$\begingroup\$ While this will work to some extent, there's much more that could be done. You'll find that there's a lot of noise around the zero cross point in some buildings so you could get multiple transitions. Filtering will help but then you have a delay problem, the edge you see with micro is delayed from the actual zero crossing. The transformer is also adding a delay, which will be load dependent (load on the secondary side). This is actually a very hard problem to solve, search for Lutron's patents on RTISS. \$\endgroup\$
    – Martin
    Commented Jan 7, 2011 at 16:41
1
\$\begingroup\$
  • It is possible to make a ZCS in < 1mA.
  • You need to buffer with an external supply.
  • Leakage to ground is < 1µA
  • Safety Agencies require it to be < 500µA.
  • External wiring shows connect to Line and ground only...
  • Neutral is not required but may be used instead.

All passive parts must be rated for 1.5kV. Any small signal silicon bridge will do. Schottky diode powers the Schmitt inverter to provide noise free hysteresis. Input cap and ferrite bead to inverter input will assist with RF rejection.. 100pF without phase shift.

  • Use trailing edge of +ve ZCS pulse to activate a pulse to Triacs or latches as the pulse staarts before zero and finishes after zero V. Pulse width depends on resitor ratio and Zener voltage for chip or use 3V white or blue, LED 3mm or 5mm. It will not illuminate much , just a cheap zener.enter image description here

If target device is grounded to AC ground, you must use a simple signal pulse transformer or OptoIsolator with different bridge divider resistors and no inverter then.Bridge to opto darlington directly with ceramic input current limiting resistor.

\$\endgroup\$
0
\$\begingroup\$

I needed a similar solution. I happened to also require 3.3V to power a microcontroller, through a non-isolated supply. In this case it provides a square wave at 50 or 60 Hz; a rising or falling edge signals a zero crossing point.

Danger of Death - Non-isolated power supply, trained people only.

alt text

\$\endgroup\$
3
  • \$\begingroup\$ I've opened a question to clarify what is meant by "trained" in this context: electronics.stackexchange.com/questions/8678/… \$\endgroup\$ Commented Jan 6, 2011 at 23:20
  • \$\begingroup\$ Why did you use a non-isolated solution? \$\endgroup\$
    – tyblu
    Commented Jan 7, 2011 at 7:39
  • \$\begingroup\$ @tyblu, Targetting a very low cost price range. In future I would probably use a non-isolated ViPER-12A or similar buck converter due to higher efficiency. \$\endgroup\$
    – Thomas O
    Commented Jan 7, 2011 at 9:22

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.