# detecting zero cross in ac?

I need to detect zero crossing for a soft starter. A long while ago, I have done it using a 1 Mega ohm resistor directly connected to micro controller at one side and live power at another side. I was successful but is it advisable ? what other way I can do it cheaply and reliably ?

I have designed soft starters using the PIC16C74A/F77 processors. Zero crossing can be tricky if you also have to work in noisy environments.

If you don't need the processor to be isolated from the line, there's nothing wrong with a couple high-value resistors feeding a CPU pin. I would use a couple shottky diodes to augment the internal protection diodes just as a matter of robustness, but it'll work fine. If you need isolation, use a transistor output optoisolator. Pay attention to the switching speed of the opto and minimize the transistor collector current to maximize switching speed.

Having said that, let's move on to noise. If you're phase-controlling anything other than resistive heating you'll have noise to contend with which means it's very likely you will have zero-crossing noise to deal with. Don't do the rookie mistake of feeding the zero crossing input to an interrupt pin; that will turn your software into a smoking mass of nastiness when the processor tries to deal with a gazillion interrupts. (I speak from experience.) Throwing an RC or more advanced low-pass filter on the line will just introduce phase shift. If you can work with that, great. If not (I had to deal with 50/60 and 400Hz systems) then you have to try other means.

On my own design I took care of it in software by polling the line and essentially making a voting routine that ignored transients. The phase shift was within what I could handle, it was fast and it wouldn't crap out even in heavy noise. (Tested in a facility where they removed the filter caps from an induction furnace, I've never seen such a noisy line before!) If I were to redesign it I think I might try an external solution involving a one-shot that would "latch" the zero cross and then the microcontroller would acknowledge it before the next interrupt could be set.

All said, I think that reliably finding the real zero crossing in any practical situation was one of the trickier bits of the soft starter design. Closing the control loop was secondary, but it was mostly just tuning. It seems like a dead-simple thing to do but I learned quite a bit about the difference between theory and practice during that time. :-)

edit to describe "voting" routine:

If I remember correctly, I had an I/O line that was high when the line was above zero and low when the line was below zero. The voting routine simply polled that line and if 2 of the last 3 samples were the same, I accepted the fact that the line had crossed zero. It's very similar to a UART's voting circuit to detect mark and space. The benefit of a circuit like this is that your phase shift is fixed (2*sample rate) and you can tune it for the type of noise you're experiencing. I do not remember offhand how fast the polling was but if I were to hazard a guess I would say 8kHz, as that number sticks out in my mind.

• i used timer for measuring frequency ( in case of lag , and excel and lookup tables )...but i think i will go with low pass and opto coupler. thnks for answer. – iamgopal Oct 1 '10 at 18:01
• Can you elaborate on the voting routine? Was it just to ignore single samples different from the surrounding ones? With what frequency did you poll? – starblue Dec 12 '12 at 14:13

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.

• For more detail: here – Vorac Nov 10 '15 at 8:14

This Microchip's Application Note on page 3 suggest a 20 MOhms resistor.

I think you can use the MOC3061 that has a zero crossing detector.

But there are a lot of devices models as you can see here.

• thnks. a chip is always welcome instead of resistors and caps. – iamgopal Oct 1 '10 at 18:01
• Even if you could find a standard 20 M$\Omega$ in 1/4 W, you would have to use a few (with lower resistance) in series. IIRC a 1/4 W resistor has a breakdown voltage of 160 V, meaning that you'd need 3 resistors of 6.8 M$\Omega$ in a 230 V circuit. – stevenvh Jun 6 '11 at 14:29

I've had success with the following processing chain:

1. Resistor divider network (using MOhm value resistors) and optocoupler to couple and isolate the signal from the source
2. An op-amp comparator to rail the signal from the optocoupler to a known voltage range
3. An extremely tight, multi-stage bandpass filter using opamps (might also need some gain in here to account for filter loss)
4. An opamp phase shifter circuit to adjust for any phase offset introduced in the filtering (+/-360 degrees is a good amount of tolerance to design for, the desired phase shift can be calibrated with a pot and an oscilloscope)
5. One more comparator to get the signal to a clean digital output for a microcontroller

There are probably a LOT of ways to do this... but if I was doing it I would use a little isolation transformer just in case. It's never advisable to connect mains to a microcontroller directly, even through a large resistor.

I guess your options are to use a large resistor divider in to a micro, or a small transformer that pushing the mains level voltages down to the range of your micro. Of course, you can also use a combination of them both.

If you dont want to use a microcontroller, you can always use a comparitor and have the voltage tested against 0v. The pulse from the comparitor will be short, but there are ways to deal with that too.

• does using isolation transformer induce any lag ? – iamgopal Oct 1 '10 at 6:43
• No. (fifteen characters) – Connor Wolf Oct 1 '10 at 8:56
• If you're going to compare to a voltage, compare to a few % of full line, not zero. It moves you out of the way of most of the noise you'll encounter, and the phase shift is fixed and thus easy to account for. – akohlsmith Oct 1 '10 at 12:43
• good call Andrew :-) – Fuzz Oct 1 '10 at 13:16
• @andrew , :D nice idea!! – iamgopal Oct 1 '10 at 18:04