Zero-Crossing Detector and Mains Sensing with the SFH620A

Ürün İncelemeleri Advanced 10 min read Published:
SFH620A ile sıfır geçiş dedektörü ve şebeke algılama: DIP-4 kılıf, şebeke sinüsü ve çıkış darbeleri

The simplest way to read mains voltage into a microcontroller with galvanic isolation is an AC-input optocoupler. The input of the SFH620A contains two infrared LEDs connected in inverse parallel, so the phototransistor turns on during both half-cycles of the mains, and the output is released only briefly as the voltage approaches zero. This short pulse serves both as a zero-crossing detector and as a “is mains present?” sensor. In this article we walk through the internal structure of the SFH620A, the key datasheet values, and the series resistor and pull-up calculations for 230 V mains, step by step.

What is an AC-input optocoupler?

An AC-input optocoupler is an optical isolator whose input side has two LEDs connected in inverse parallel, so it emits light whichever direction the current flows. The output side is an ordinary phototransistor. In a conventional DC-input optocoupler (for example the PC817), the LED conducts in one direction only; if it is to be connected to the mains, it needs a separate diode or a bridge rectifier to protect it against reverse voltage. In the AC-input type, this protection is already built into the package.

The H11AA1 is one of the most sought-after parts in this class. The SFH620A, which does the same job, is an AC-input optocoupler with phototransistor output made by Vishay in a 4-pin DIP package. Its surface-mount version (SMD-4, option 9) is sold as the SFH6206.

SFH620A pin diagram: two inverse-parallel LEDs between pins 1 and 2, phototransistor with collector on pin 4 and emitter on pin 3
SFH620A internal structure and pin connections. Pins 1 (A/C) and 2 (C/A) are the input, 4 is the collector, 3 is the emitter.

How does the SFH620A work?

The input pins are 1 and 2. One LED conducts during the positive half-cycle and the other during the negative half-cycle. In both cases, the infrared light falls on the base of the same phototransistor, and current begins to flow between the collector (4) and the emitter (3). There is no electrical connection between input and output; the signal is carried by light alone.

Because the mains voltage is sinusoidal, the LED current is also largest at the peak and zero at the zero crossing. During the short interval in which the absolute value of the voltage falls below a certain threshold, the LED current cannot drive the phototransistor, the transistor turns off, and the pull-up resistor at the output pulls the line to logic 1. On a 50 Hz mains, this produces a pulse around the zero crossing every 10 ms, that is, 100 times per second.

SFH620A key parameters

The values below are taken from the Vishay datasheet (Rev. 2.4, 07-Mar-2023) and apply at 25 °C ambient temperature unless otherwise stated.

Parameter Condition Value
Input DC forward current (IF), absolute max. – ±60 mA
Surge forward current (IFSM) tp ≤ 10 µs ±2.5 A
LED forward voltage (VF) IF = ±60 mA typ. 1.25 V, max. 1.65 V
Collector-emitter voltage (VCEO) absolute max. 70 V
Emitter-collector voltage (VECO) absolute max. 7 V
Collector current (IC) continuous / tp ≤ 1 µs 50 mA / 100 mA
CTR, SFH620A-3 VCE = 5 V, IF = ±10 mA 100% – 320%
CTR, SFH620A-3 VCE = 5 V, IF = ±1 mA min. 34%, typ. 70%
Saturation voltage (VCEsat) IF = ±10 mA, IC = 2.5 mA typ. 0.25 V, max. 0.4 V
Leakage current (ICEO), SFH620A-3 VCE = 10 V typ. 5 nA, max. 100 nA
Isolation test voltage (VISO) UL1577, t = 1 s 5300 VRMS
Isolation withstand voltage (VISO) UL1577, t = 1 min 4470 VRMS
Maximum repetitive peak isolation voltage (VIORM) DIN EN 60747-5-5 890 Vpeak
Creepage / clearance standard DIP-4 ≥ 7 mm
Operating ambient temperature – -55 °C … +100 °C

CTR (current transfer ratio) is the ratio of the output collector current to the input LED current. The SFH620A is made in three CTR grades: -1 (40–125%), -2 (63–200%) and -3 (100–320%), all measured at ±10 mA. The SFH620A-3 we use as the example in this article is the highest grade. We covered CTR theory and its role in design in detail in our article on optocoupler resistor calculation.

The typical switching times in the datasheet (turn-on 3 µs, turn-off 2.3 µs, rise and fall 2 µs) are given for a non-saturated test setup such as RL = 75 Ω, IF = ±10 mA and VCC = 5 V. In a zero-crossing circuit with a pull-up resistor in the kilohm range, the edges are noticeably slower than this. That is not a problem at 50 Hz, but don’t use these times in timing calculations until you have seen them on an oscilloscope in your own circuit.

Typical application: 230 V zero-crossing detector circuit

The circuit consists of four parts: two series resistors on the mains side, the SFH620A, and a pull-up resistor at the output. The line (L) conductor goes through R1 and R2 to pin 1, and the neutral (N) conductor goes to pin 2. On the output side, emitter pin 3 connects to the microcontroller ground, and collector pin 4 connects through R3 to 3.3 V and, from the same node, to an input pin of the microcontroller.

230 V zero-crossing detector schematic with the SFH620A: two 47 kΩ series resistors on the L line, input to pins 1 and 2, 47 kΩ pull-up to 3.3 V on collector pin 4 and microcontroller input
Example zero-crossing detector for 230 V mains. The dashed line marks the isolation barrier; the left side is at mains potential.

Series resistor calculation (R1 + R2)

The calculation must be based on the peak mains voltage; the RMS value does not give the largest current the LED sees. The peak of a 230 VRMS mains is 230 × √2 ≈ 325 V. With R1 = R2 = 47 kΩ (94 kΩ total):

  • Peak LED current: (325 V − approx. 1.1 V) / 94 kΩ ≈ 3.45 mA (we took the LED forward voltage as approx. 1.1 V for this current range from the datasheet’s 25 °C curve). With the mains 10% high (253 VRMS, peak ≈ 358 V), this becomes ≈ 3.79 mA. Both are far below the ±60 mA limit.
  • Total resistor power: VRMS² / R = 230² / 94,000 ≈ 0.56 W. At 253 V it is ≈ 0.68 W, i.e. ≈ 0.34 W per resistor.
  • The peak voltage across each resistor is ≈ 179 V on a 253 V mains.

At 0.34 W per resistor, a 0.5 W resistor runs continuously at around two-thirds of its rating. That is why 1 W resistors are the more comfortable choice. The main reason for splitting the resistance in two, however, is voltage: check the maximum working voltage (limiting element voltage) in each resistor’s own datasheet, and don’t expose a single small resistor to the full mains voltage.

Pull-up resistor calculation (R3)

The datasheet gives the minimum CTR at IF = ±1 mA: 34% for the SFH620A-3. This means that when at least 1 mA flows through the LED, the transistor can sink about 0.34 mA even in the worst case. This value is measured at VCE = 5 V and 25 °C; in our circuit the transistor operates close to saturation, and with a 3.3 V supply VCE never reaches 5 V. So we treat the calculation as an estimate and leave a wide margin. Below 1 mA, the datasheet gives no value.

With R3 = 47 kΩ and a 3.3 V supply, the current the transistor must sink to pull the line to logic 0 is approximately (3.3 V − 0.4 V) / 47 kΩ ≈ 0.062 mA. 0.34 mA is about 5.5 times this value. This margin is left to cover the variation of CTR with temperature and the aging of the LED over time. Had we chosen 10 kΩ for R3, the required current would be ≈ 0.29 mA, very close to the guaranteed 0.34 mA.

How wide is the pulse?

Based on the datasheet’s worst-case CTR, the region in which the output is expected to stay at logic 0 is the region in which the LED current exceeds 1 mA. This occurs when the absolute value of the mains voltage exceeds approximately 1 mA × 94 kΩ + 1.1 V ≈ 95 V. On a sine wave with a 325 V peak, this threshold corresponds to an angle of about 17° on each side of the zero crossing, or about 0.94 ms at 50 Hz. The result is an upper estimate: on a 230 V nominal mains at 25 °C, the logic 1 pulse lasts at most about 1.9 ms. With the mains 10% low (207 V, peak ≈ 293 V), the same calculation gives about 2.1 ms; if 5% tolerance resistors increase the total resistance, the pulse widens slightly further. In the real part, the transistor saturates at LED currents below 1 mA as well, so the pulse is usually narrower and varies with the CTR grade.

Mains voltage sine wave and zero-crossing pulses at the SFH620A output: the output goes to logic 1 inside the ±95 V threshold band
Mains voltage (top) and optocoupler output (bottom), 230 V nominal. The output rises at the latest when the voltage enters the approximately ±95 V band; the pulse width shown is a worst-case estimate.

Software on the microcontroller side

  1. Zero-crossing instant: The pulse forms around the zero crossing. The rising edge comes before the zero crossing, the falling edge after it. The middle of the pulse gives the best estimate of the zero-crossing instant: capture both edges with a timer and take their average.
  2. Mains present/absent detection: When the mains fails, the LEDs stay dark and the output remains at logic 1 continuously. Since the interval between two pulses is 10 ms at 50 Hz, the mains can be considered absent if, for example, no new falling edge arrives for 25–30 ms.
  3. Frequency measurement: The pulses arrive at twice the mains frequency. Measuring the time between two consecutive pulses lets you distinguish 50 Hz from 60 Hz.

The datasheet does not state that the CTRs of the two LEDs will be equal. The pulses in the positive and negative half-cycles may differ slightly in width. For precise phase control, this difference must be measured and corrected in software.

If you will use the zero-crossing information to control a TRIAC load, you can find the TRIAC and opto-TRIAC side in our article on testing TRIACs.

Selection and usage considerations

  • Choose the right version. In the ordering table, the SFH620A-3 is the standard DIP-4 version with UL, cUL and BSI approvals and creepage and clearance of ≥ 7 mm. The IEC 60950 reinforced insulation statement in the datasheet (up to 400 VRMS working voltage, > 8 mm spacing) is written for the 400 mil wide-lead “option 6” version. VDE (DIN EN 60747-5-5) approved versions come with separate ordering codes; for standard DIP-4, codes with an X001 suffix such as SFH620A-3X001 are used.
  • Isolation must also be maintained on the PCB. The optocoupler’s internal isolation is useless if the board does not leave enough spacing between mains and low-voltage copper. Don’t route traces under the package; if necessary, cut a board slot between the two sides.
  • Resistor ratings. Select the series resistors for both power and voltage. Parts on the mains side must be enclosed so that they cannot be touched.
  • Leakage current. The maximum leakage current of the SFH620A-3 is 100 nA at 25 °C (VCE = 10 V); leakage current increases with temperature. Across 47 kΩ this causes a drop of a few millivolts at most and does not affect the logic level. If you raise the pull-up to the megohm range, leakage current and slower edges start to become a problem.
  • CTR grade. In circuits of this kind that run on low LED current, the -3 grade leaves the widest margin. If you use the -1 grade, the minimum CTR at IF = ±1 mA is 13%; recalculate the pull-up accordingly.

Common mistakes

  • Calculating with RMS. The peak current calculated from 230 V comes out at about 70% of the actual peak value. The peak voltage is 325 V.
  • Using a single 1/4 W resistor. With the values in the example, a total of 0.56 W is dissipated. A single small resistor both heats up and may exceed its voltage limit.
  • Choosing a pull-up that is too small. With 1 kΩ or 4.7 kΩ, the output may not go fully to logic 0 at LED currents around 1 mA. The pulse widens and becomes inconsistent.
  • Mistaking the pulse edge for the zero crossing. The edges are threshold crossings; the zero crossing is near the middle of the pulse.
  • Connecting a probe to the mains side. Connecting the ground of an earthed oscilloscope to the mains side is dangerous. Make your measurements on the output side of the optocoupler.

Measurement steps for the engineer

  1. Before connecting the circuit to the mains for the first time, power the output side from 3.3 V, connect a low-voltage AC source (for example, the secondary of an isolated transformer) to the input, and temporarily reduce the series resistance to suit that voltage.
  2. Watch the output on an oscilloscope: you should see one pulse every half-period. Note the rise and fall times.
  3. When you move to the mains circuit, measure only on the isolated output side. Measure the mains voltage, recalculate the upper limit of the pulse width for that voltage (≈ 1.9 ms at 230 V, ≈ 2.1 ms at 207 V), and verify that the measured pulse stays below this limit.
  4. Measure the pulses of the positive and negative half-cycles separately and record the difference between them.
SFH620A-3Vishay · EE00537$0.8598 In StockView

Frequently asked questions

What is the difference between the SFH620A and the PC817?

The SFH620A has two inverse-parallel LEDs at its input and senses AC current in both directions. The PC817 has a DC input; if it is to be connected to the mains, it needs a separate diode or bridge rectifier to protect the LED from reverse voltage. When protected by an inverse-parallel diode, it produces an output on only one half-cycle; to see both half-cycles, a bridge rectifier must be added.

Can the SFH620A be connected directly to 230 V?

No. The LED current must always be limited by a series resistor. In the example in this article, two resistors totaling 94 kΩ hold the peak LED current at about 3.5 mA.

What is the difference between the SFH620A-1, -2 and -3?

The suffix indicates the CTR grade. At ±10 mA, -1 is in the 40–125% range, -2 in the 63–200% range and -3 in the 100–320% range. The package and pinout are the same.

Why does the zero-crossing pulse arrive every 10 ms?

On a 50 Hz mains, one period is 20 ms and the voltage crosses zero twice per period. Since both LEDs can conduct, a pulse is generated at each crossing.

Is there an SMD equivalent of the SFH620A?

Yes. It is listed in the same datasheet as the SFH6206 in an SMD-4 (option 9) package, and its CTR grades are the same as the SFH620A. There are also SMD versions of the SFH620A with the option 7 code.

Conclusion

The SFH620A offers a bidirectional LED input, a 70 V phototransistor output and a 5300 VRMS (1 s) isolation test in a single 4-pin package; it is the short route to monitoring the mains with isolation and without an additional rectifier. For 230 V, two 47 kΩ / 1 W series resistors and a 47 kΩ pull-up to 3.3 V leave a margin of about 5.5 times relative to the datasheet’s worst-case CTR, and the zero-crossing pulse lasts at most about 1.9 ms at 230 V. Before starting your design, you can review the SFH620A-3 product page, and for other options browse the transistor-output optocouplers category.

References

Products in this article

More from Ürün İncelemeleri