Showing results for 
Search instead for 
Did you mean: 

Detecte zero crossing of 3 phase x 230Vac

Associate II
Posted on June 29, 2010 at 14:54

Detecte zero crossing of 3 phase x 230Vac

Associate II
Posted on May 17, 2011 at 13:56

It's generally not a good idea to feed power line voltage directly into your low power digital system. The whole system has to be seen as carrying line level then, and needs to be protected against touching metallic parts to avoid electric shock. Additionally, you will need proper grounding, to avoid the board floating towards line level.

Plus, sure you have interfaces to other electronic, where you surely don't want to risk feeding line level to?

Usually, one uses a transformer the insulate from line level and provide a safe low voltage level (everything above 40V peak is considered harmfull).

Anyway, the large resistor and Z-Diode is the way to go.

Will you need to detect the negative half-cycle too?

If you don't need insulation from line level, make sure you have 2 or more resistors in series, to reduce the risk of a strike through. Remember, 240V AC is ~400V peak! Having a peak Z current of 10mA will result in ~4W peak in the resistors.

Associate II
Posted on May 17, 2011 at 13:56

I don’t know that much about electronic hardware.  But what you suggest will likely kill your processor, debugger and possibly the PC you use for debug.  With luck it won’t kill you. 

Use optical isolation. 

Consider: high voltage to megohm resistance to high impedance analog input.  Result: high voltage on the pin.  Bad idea.  Find a hardware guy who has been dealing with microelectronics and AC power for a long time.

If this is for a cost sensitive high volume product and the processor has no way of conducting AC power to a user you might be able to get away with a voltage divider with protection diodes going both ways.

How close to the zero crossing do you have to be?  The next paragraph describes a scenario where being late by a millisecond is quite okay. 

Switching a triac at a zero crossing?  Use the kind that switch on only a zero crossing.  IIRC they only turn off at a zero crossing.  You will then only need to detect zero crossings and command the parts 4 milliseconds after a zero crossing and let the triac do its own detect.  If you know the phase order you can use one zero crossing input and timers.

I have just finished a project where I controlled (single phase) AC to two fans and a heater.  All AC was isolated.  But the h/w guy used triacs that turn on when told to rather than at the next zero crossing.  I had to put all triac on controls in my zero crossing ISR.  Switching noise and a 160 voltage gain opamp makes plenty of opportunity for trouble. 

Andrew Neil
Evangelist III
Posted on May 17, 2011 at 13:56

''I think that the distance between PA0 and 2 pins ( near him) will not sufficient to isolate''

If you're not 101% absolutely & totally sure, then just


do it!



This stuff is potentially lethal - do not mess with it!



The only truly safe way is to use proper galvanic isolation; ie, opto-isolator, transformer, etc...



Associate II
Posted on May 17, 2011 at 13:56


We have made such a system, detecting zero-point with 3x270K resistors from line to pin on uC. This will give squarewave on the input.

If you then connect a 10K input pin on the uC, whre the 270k is connected to another I/O pin, you can by this make a divider to measure voltage when the pin is low, and clipping sq.wave when it is OC.

We have only been using the internal protection diodes in the uC.

We have been using this circuit on ST7 uC for several years and on STM8 for ½ year.

The pin spacing on the uC is not problem since in this junction the voltage is clamped to GND/VCC...

BUT be aware that nothing in your desing is galvanic isolated and is DANGEROUS.

We have our isolation in the plasitc insulation of the house.


Associate II
Posted on May 17, 2011 at 13:56

Hello all,

 I think the forum have a problem, i lost all that i have written recently.

 By the way, thanks all and i'm trying the idea of Kasper, it sounds good.


Andrew Neil
Evangelist III
Posted on May 17, 2011 at 13:56

''i'm trying the idea of Kasper, it sounds good''


Are you certain that you fully understand the dangers inherent in that method?

Are you certain that you fully understand what he said about providing the safety in the enclosure - and are you certain that you fully understand how to do that yourself for your own enclosure?

And remember: if the safety isolation is provided only by the housing, then you have


protection when you are testing or debugging it out of its housing!

Also remember that there will be no isolation if you want to connect a JTAG debugger or similar...

Associate II
Posted on May 17, 2011 at 13:56

Be aware that the zero crossing is not as clean as it once was.  Utilities are now using the zero crossing to send data and using the electrical grid as a low speed network.  Expect spikes on the zero crossing.

Associate II
Posted on May 17, 2011 at 13:56

Hello Tran,

Best would be a transformer! 

Have you considered using capacitive isolation... small value, Y rated caps from line to circuit, then a larger value cap between them for a capacitve voltage divider?    It might even be legal if you use proper rated caps!

I've typically used a diff-amp with 10M input resistors, filtering, and a comparator with a lot of hysterisis, then compensate for the filter phase delay in software.  But this is a lot of parts.

Cheers, and be safe.