Author Topic: Isolated zero cross detection w/ AC mains  (Read 13205 times)

0 Members and 1 Guest are viewing this topic.

Online wraper

  • Supporter
  • ****
  • Posts: 17952
  • Country: lv
Re: Isolated zero cross detection w/ AC mains
« Reply #25 on: October 08, 2019, 01:51:05 pm »
Even 1206 resistors are only rated for 200V. Two of those gives you a 400V rating. The peak of a 264V sine wave (upper bound of 240V mains) is 373V, so they are marginal best, with no allowance for harmonic peaks or surges.
They usually have 1.5-2 times of that as surge rating. http://www.royalohm.com/pdf/product2017/GeneralPurpose.pdf
« Last Edit: October 08, 2019, 01:53:44 pm by wraper »
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10034
  • Country: gb
Re: Isolated zero cross detection w/ AC mains
« Reply #26 on: October 08, 2019, 01:53:29 pm »
Even 1206 resistors are only rated for 200V. Two of those gives you a 400V rating. The peak of a 264V sine wave (upper bound of 240V mains) is 373V, so they are marginal best, with no allowance for harmonic peaks or surges.
They have 1.5-2 times of that as surge rating.
Yes, but when you try something like the standard fast pulse transient tests they can arc very badly.
 

Online wraper

  • Supporter
  • ****
  • Posts: 17952
  • Country: lv
Re: Isolated zero cross detection w/ AC mains
« Reply #27 on: October 08, 2019, 01:58:09 pm »
Even 1206 resistors are only rated for 200V. Two of those gives you a 400V rating. The peak of a 264V sine wave (upper bound of 240V mains) is 373V, so they are marginal best, with no allowance for harmonic peaks or surges.
They have 1.5-2 times of that as surge rating.
Yes, but when you try something like the standard fast pulse transient tests they can arc very badly.
If you don't use MOV, you can say the same about say PCB connector for mains input.
 

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #28 on: October 09, 2019, 12:14:35 am »
Optocoupler reacting only to peak voltage is not very helpful for accurately detecting zero cross. There is not always ideal sine waveform in mains to allow you to accurately calculate zero cross from that. Ideally you want it to turn off only as close as possible to zero voltage. Also one need to consider that if it works now, does not mean it will work over time. Optocoupler CTR tend to degrade and one should consider that when designing things.
I've connected my "prozerocross" detector shown a few posts above to logic analyzer (Saleae) and as I said it looks like we do have two digital waveforms for positive and negative mains 230VAC sinewave, so now it should be easy in software calculate zero crossing time prediction what ever logic 0 or logic 1 we take based on its width, so it doesn't matter if optocoupler degrade over time as well as we can see that optocoupler is not reacting only to peak voltage  8)


However, there is something which is strange and didn't expected or maybe logic analyzer inverts logic level, since EL817 are connected in zero cross circuit as shown below (Vcc is Li-ion ~3.7V), so I have no idea for the moment what the hell is going there, while I'd rather expeced to see high logic levels shorter than logic low in given 50Hz time periods ~20.02ms, but it looks like optocouplers turn on its outputs for longer time?  :o
I've used EL817 with cut off frequency around 80kHz shown in its datasheet  ???


I've attached also Matlab 1s 1MHz sampled those two digital outputs pulled down via 100k resistors.
NOTE: Nope, it is not possible attach .mat or .mat.gz files ...

What is going there?   :-//

Anyway, I'm working now on MPU software to predict zero crossing based on those two (positive and negative mains sinewave) optocoupler responses and output in real time to see on logic analyser channel0 for analysis if we do hit somewhere (in the middle I hope) between rise/fall since there must be zero cross I guess.

Maybe I missed something?
« Last Edit: October 09, 2019, 12:25:25 am by beduino »
 

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 2431
  • Country: mx
Re: Isolated zero cross detection w/ AC mains
« Reply #29 on: October 09, 2019, 12:23:37 am »
If you are using emitter resistors, then don’t use collector resistors. Or viceversa.

100k is way too large an optocoupler load resistor, go for 10k or 5k.
 

Offline iroc86Topic starter

  • Regular Contributor
  • *
  • Posts: 148
  • Country: us
Re: Isolated zero cross detection w/ AC mains
« Reply #30 on: October 09, 2019, 01:42:48 am »
Well, this thread has turned into quite a good discussion! :) ... CTR, noise, transients, etc. I appreciate seeing some practical examples--it really helps to delve into the nuances of these circuits instead of just focusing on a textbook/breadboard concept. The resistor chain variant you've all been discussing is rather interesting in its simplicity; I might look into that for my own application.

Ian.M, thanks for posting up your circuit and simulation. I reviewed the waveforms in LTspice and the output looks very good; a short duration pulse with a fast rising edge. The use of jellybean parts is also a plus. Would you mind explaining the circuit operation and filtering for us? Is this something you've used in another design, or did you whip it up just now?

I'd like to introduce another topic: safety and suppression. How might some of these designs better accommodate unexpected AC spikes or the wrong input voltage? MOVs, fuses...?
 

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #31 on: October 09, 2019, 10:15:50 am »
If you are using emitter resistors, then don’t use collector resistors. Or viceversa.
I use emiter resistor since it is connected to MPU input pin and with optocoupler turned off pulls this pin to GND.
When optocoupler is turned on we have voltage divider with lower collector resistor and additional emiter voltage drop something like this:


100k is way too large an optocoupler load resistor, go for 10k or 5k.
I've changed emiter resistor 100k to 10k and collector resistor to 1k and now logic high is 9.4ms, 1ms shorter than logic low 10.6ms on 230VAC 50Hz mains  8)


Now, logic high periods are shorter (~1ms) than logic low and this what I've expected to see on logic analyser, since there must be some delays in optocoupler output.


I will try also much faster 6N137 optocoupler  :-/O
« Last Edit: October 09, 2019, 10:18:00 am by beduino »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13216
Re: Isolated zero cross detection w/ AC mains
« Reply #32 on: October 09, 2019, 10:35:54 am »
@Iroc86,
I knocked up the sim on the spot just for you.   There's another common high pulse current, low quiescent current ZC opto driver circuit that inspired me: https://www.edn.com/design/analog/4368740/Mains-driven-zero-crossing-detector-uses-only-a-few-high-voltage-parts
(which is very similar to the web archive dextrel.net one eliocor posted back in reply #21, but IMHO better thought out).
I decided it needed to be unipolar so you could guarantee to switch on the transformer on the opposite polarity half cycle to the one it was last switched off, and I wanted a snap action for a really sharp leading edge, which meant it needed a SCR or UJT.  After some playing around in LTspice, I replaced the SCR with one built from jellybean BJTs, added HF spike filtering on the input and got rid of a lot of extra parts.

R1A should be a high voltage type, as due to the filter cap C2 behind it, it is severely stressed by fast HV transients.  If you are using ordinary 200V resistors, 2x 160K would be advisable.  C2 should be a 1KV or greater HV cap.   R1B, R1C and C3 are less stressed, but if you anticipate really bad transients, keeping the same spec as R1A, C2 may be advisable.   Everything to the right of R1C is protected by it limiting the available current, and by D3 clamping the peak voltage.  Even continuous applied DC at the peak line voltage wont cause any damage (or cause any output pulses).   N.B. the circuit may false trigger during the positive half cycle  on longer large negative going transients.  The sim has both positive and negative 2us long 1KV peak triangular transients added to the AC sinewave, and no objectionable false triggering was observed. 

It tolerates a wide input voltage range e.g. 150V - 300V RMS only causes a 5% change in opto LEDdrive current, and a 70us shift of the leading edge, which is only a 1.25 degree change in firing angle, or 0.7% of a half cycle.   

However it doesn't do line voltage or frequency monitoring.  If you need that, a low pin count PIC MCU with a ZCD peripheral and an ADC input is probably your best bet, powered by a capacitive dropper supply, and driving two OPTOs, one for 'Line Good' (i.e. in valid range for voltage and frequency) and the other for a squarewave synchronised to the ZC, so you get both rising and falling ZC events and can discriminate between them.

I may build up my simmed circuit and test it as I have a *VERY* long duration timekeeping application that would benefit from PLLing its timebase to the mains supply.  I'm looking for something like 1ppm/year max drift, but don't have a sky view for a GPS.   However I'm more likely to go for a linear PSU and taping the secondary side AC for timekeeping as that lets me use an off-the-shelf AC output wallwart.
 
The following users thanked this post: iroc86

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #33 on: October 09, 2019, 10:05:46 pm »
You need an even number of 1/2 cycles so the big transformer core does not saturate and many examples (fig.3a) show it's best to switch in on the AC peak, not at zero cross, to have lowest inrush current by exploiting the transformer's inductance.

So, depending on application maybe we do not need very accurate zero crossing eg. in the case of switching on iron core spot welder transformer, since we are very close to AC mains voltage peak (flat) maximum based on mentioned article:
https://sound-au.com/articles/inrush.htm
Quote
In some cases, it's best to apply power when the mains is at its maximum value (peak of RMS =Top nominal voltage × 1.414), and with others it's far better to apply power as the AC waveform passes through zero volts. Iron core transformers are at their best behaviour when the mains is switched on at the peak of the waveform, while electronic loads (rectifier followed by a filter
capacitor for example) prefer to be switched on when the AC waveform is at zero volts.

Isn't it will depend on needed welding power accuracy, how accurate zero crossing or voltage peak maximum timing needed in given design?
 

Offline iroc86Topic starter

  • Regular Contributor
  • *
  • Posts: 148
  • Country: us
Re: Isolated zero cross detection w/ AC mains
« Reply #34 on: October 10, 2019, 11:10:53 pm »
I knocked up the sim on the spot just for you.

Aw, thanks so much! I'm going to play around with the circuit in LTspice some more. Might have a few more questions for you. I'm in the US, so I'd like to try out some different filtering scenarios for 120 VAC / 60 Hz operation. If I were to add an isolation transformer on the front end, I presume I could just tweak the input resistors and filters to maintain the same level of triggering as per the mains-voltage version? (Ignoring any phase shift of the transformer, at least for the purposes of simulation...)

Using this circuit for your long-duration timekeeping application sounds pretty neat. I can see how this'd be one way of reliably locking onto the mains frequency.
 

Offline dmendesf

  • Frequent Contributor
  • **
  • Posts: 342
  • Country: br
Re: Isolated zero cross detection w/ AC mains
« Reply #35 on: October 11, 2019, 05:05:54 pm »
This is a zero cross circuit recommended at Time Nuts as being robust to noise... I've used it myself and works very well:

https://web.archive.org/web/20180209111314/http://www.dextrel.net/diyzerocrosser.htm
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4857
  • Country: dk
Re: Isolated zero cross detection w/ AC mains
« Reply #36 on: October 12, 2019, 12:07:46 am »
there's also the crazy one, two optos, LEDs anti parallel, the two transistors arranged as push-pull
 

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #37 on: October 15, 2019, 12:39:53 am »
AC mains is always dirty, so you need transient protection and low pass filtering.
My home mains 230VAC 50Hz is quite clean and antiparallel EL817 shown in my circuit a few posts above after ATTiny85 8MHz (no crystal during this test only calibrated OSCAL) processing close to zero crossing signals from those optos gives mains period 0.020078 s, which is only ~0.4% faster than theoretical 20ms and as we can see below, generated zero crossing waveform (green) but as pulse train is quite close to optos outputs: positive mains waveform (red) and negative mains waveform (blue)  8)


It will be interesting to see some results with 8Mhz external crystal, however probably it will be better run MPU @ 5V 16MHz external crystal, since experiments showed that, this code below which creates those zero crossing (green) waveform takes due to division by 32bit period ~90us, so looking now for a way to create zero crossing pulse train in a more efficient way  ::)



 

Offline Circlotron

  • Super Contributor
  • ***
  • Posts: 3362
  • Country: au
Re: Isolated zero cross detection w/ AC mains
« Reply #38 on: October 15, 2019, 01:52:09 am »
One of my goals with the new design is to improve the weld repeatability. I wonder if the variation was due to de-energizing the welder transformer in mid-cycle.
If the load is switched with a triac or pair of SCRs it will remain energised until the current zero crossing despite the gate drive to the semis being removed. If you needed to, you could detect this by the sudden rise in voltage across the semis as they unlatch.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 7678
  • Country: ca
Re: Isolated zero cross detection w/ AC mains
« Reply #39 on: October 15, 2019, 02:04:41 am »
Try OR'ing the optos outputs and using a high value pullup for more gain. Then compare to the actual mains sine wave.
There is a phase-shift due to the opto's actual turn on point. EL817 CTR is all over the place 5-600% so they won't be matched and there is always a deadband.
My fuzzy math, 18Vpk is 3° for 240VRMS, so a 6° deadband or 0.34msec at 50Hz.

For welding batteries, double-pulse is used where a ~1/8 time pulse clears any oxidation or plating, dirt as a weak weld- then a pause then the main welding pulse.
Your weld inconsistency can be caused by transformer residual magentization, and you don't want to zero-cross switch a transformer. You switch on during a peak for inductive loads.
 

Offline uer166

  • Super Contributor
  • ***
  • Posts: 1026
  • Country: us
Re: Isolated zero cross detection w/ AC mains
« Reply #40 on: October 15, 2019, 02:05:20 am »
Lots of over-complication happening.. I would just use somewhere between 4 and 8 1206 resistors in series with appropriate values (1-2meg total, depends on isolation requirements). Something like this appnote:
http://ww1.microchip.com/downloads/en/AppNotes/Atmel-2508-Zero-Cross-Detector_ApplicationNote_AVR182.pdf

It also works when the MCU is mains-GND referenced, but the pulses become slightly asymmetric, which can be compensated in FW if you need high resolution within an AC cycle..
 

Offline iroc86Topic starter

  • Regular Contributor
  • *
  • Posts: 148
  • Country: us
Re: Isolated zero cross detection w/ AC mains
« Reply #41 on: October 15, 2019, 02:49:28 am »
If the load is switched with a triac or pair of SCRs it will remain energised until the current zero crossing despite the gate drive to the semis being removed. If you needed to, you could detect this by the sudden rise in voltage across the semis as they unlatch.

Ah, absolutely right--I should have clarified what I meant. I was referring to having the triac unlatch between periods and not having full cycles reach the welder (in other words, shutting off at any zero cross instead of consistently at either the rising or falling crosses). This was discussed a few posts up by floobydust and Ian.M in terms of AC half-cycles and transformer saturation. My first welder used a Crydom D2425 solid state relay; without any feedback on the control circuit, I was wondering if the inconsistent weld quality was due to transformer saturation and shutting off at random zero crosses (and not necessarily corresponding to the phase angle at the "on" state).

Your weld inconsistency can be caused by transformer residual magentization, and you don't want to zero-cross switch a transformer. You switch on during a peak for inductive loads.

I'm not sure if you were referring to me or beduino, but I think you're confirming what I was just pondering in my response to Circlotron above :). I gotta remember the bit about switching on peaks--to balance the positive and negative AC cycles, how might we switch off the triac at a peak?

For welding batteries, double-pulse is used where a ~1/8 time pulse clears any oxidation or plating, dirt as a weak weld- then a pause then the main welding pulse.

Yep! Two-stage operation with a preheat pulse is on my list of project requirements, too. :-+
 

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #42 on: October 15, 2019, 06:56:41 pm »
There is a phase-shift due to the opto's actual turn on point. EL817 CTR is all over the place 5-600% so they won't be matched and there is always a deadband.
My zero crossing calculation is based on something like trying to find peak time of positive opto output, than the same minimum for negative opto outputs. Now we have time of positive peak and time of negative minimum, so by calculating average I estimate zero crossing time between maximum and minimum (next minimum maximum and so on averaging 16), so maybe slighly different CTR of those thwo not matched EL817s doesn't matter too much?
I haven't time today make experiments with MPU running external crystal, but 0.020078 s mains 230VAC 50Hz looks quite good for me while ATTiny85 is running internal oscilator 8Mhz @ ~3.9V without any voltage regulator directly from Li-ion 18650 battery.

You switch on during a peak for inductive loads.
I know that and shown something like pulse train of zero crosses was only to see that concept of two EL817 probably might be usable, since I've got quite nice mains 50Hz period based on moving average (16) zero crossing periods from those two optos.
I've in my spot welder two thyristors in antiparallel configuration on transformer primary.
« Last Edit: October 15, 2019, 06:58:45 pm by beduino »
 

Offline chris_leyson

  • Super Contributor
  • ***
  • Posts: 1549
  • Country: wales
Re: Isolated zero cross detection w/ AC mains
« Reply #43 on: October 15, 2019, 08:33:08 pm »
Just as luck would have it I've been looking around for ideas for low power zero crossing detectors. In the not too distant future regulations may recommend a 300mW AC power demand when appliances are in standby, it won't be mandatory but it's a nice feature to have. A 300mW power budget sounds like a lot but it isn't really very much.
If want to cover 80VAC to 264VAC and you also want a zero crossing detector then you have to design for low power. There is a really neat circuit published in Electronic Design April 5 1999. It's designed for 120VAC but needs an isolated DC supply. If you have a flyback as part of the overall design then you can tweek the component values and use the flyback's auxiliary supply for the DC, another alternative might be a small capacitve dropper supply. There is also a nice design from EDN that uses very few parts and if you tweek up the input resistors to 470k or so and reduce the value of C1 to shorten the pulse then you can achieve less than 100mW standby power, however, the LED drive current is only a few mA, but a few mA is all need with 100% current transfer ratio opto. Onsemi app note added for good measure. Mitigating for fast transients and surges is not so easy however.
« Last Edit: October 15, 2019, 08:42:53 pm by chris_leyson »
 

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #44 on: October 15, 2019, 10:23:29 pm »
Your weld inconsistency can be caused by transformer residual magentization, and you don't want to zero-cross switch a transformer.
Yep, that is why I start pulse (~100us)  train which lasts multiply of 20ms mains period at 50Hz in updated attiny85spot welder software always on some chosen offset from positive peak and do not rely only on zero crossing.
In one of the tests below, there is no offset from predicted peak voltage, but now I can easy change offset time in the range 0ms-4ms with 1ms margin, to do not make pulse at the begining of the next opposite mains waveform half period  8)



Of course, pulse duration also can be increased (probably should be to ensure fire eg. thyristor) or forced to last eg. up to 1ms before next predicted voltage zero crossing.

I think, it is now time add external oscilator 8MHz or better 16MHz for 5V attiny85 and make experiments with spot welder transformer  :-/O
 

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 2431
  • Country: mx
Re: Isolated zero cross detection w/ AC mains
« Reply #45 on: October 16, 2019, 01:10:42 pm »
Since SCRs like to be driven hard to ensure fast turn on, more so if you are driving an inductive load, a good practice is to provide what is called "picket fence" triggering.


Just as its name implies, it is a burst of narrow, high current pulses, that last perhaps a quarter cycle from start to finish.
Picket fence is a challenge to produce with discrete components, but with a microcontroller is a straigntforward task.

Another benefit of picket fence triggering is that you can employ a transformer as the gate driver, which ensures isolation without the hassles of an auxiliary power supply.
 

Offline Unixon

  • Frequent Contributor
  • **
  • Posts: 400
Re: Isolated zero cross detection w/ AC mains
« Reply #46 on: October 16, 2019, 05:08:33 pm »
I would recommend to try the circuit from figure #11 of ONS app.note AND9282, works perfectly. :-+
 

Offline beduino

  • Regular Contributor
  • *
  • Posts: 137
  • Country: 00
Re: Isolated zero cross detection w/ AC mains
« Reply #47 on: October 16, 2019, 08:17:56 pm »
Since SCRs like to be driven hard to ensure fast turn on, more so if you are driving an inductive load, a good practice is to provide what is called "picket fence" triggering.
Probably something like this I've already implemented in my spot welder software, mentioned also in ABB Gate-drive Recommendations for Phase Control Thyristors https://www.5scomponents.com/Pdf/5SYA2034-01.pdf

First fire pulse is 100us at given offset (0us in example above for full spot welder power) from mains peak voltage, than followed by 10kHz (100us period) pulses with 50% on/off up to 1ms before next predicted ZC.


 

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 2431
  • Country: mx
Re: Isolated zero cross detection w/ AC mains
« Reply #48 on: October 16, 2019, 11:58:41 pm »
You got it!   :-+ :-+

BTW: how are you galvanically isolating the gate driver from the SCR itself?
 

Offline iroc86Topic starter

  • Regular Contributor
  • *
  • Posts: 148
  • Country: us
Re: Isolated zero cross detection w/ AC mains
« Reply #49 on: October 17, 2019, 02:37:31 am »
OP here. Lots of good info in this thread, but much of the discussion has been related to beduino's project since he popped in (which is great to have an active circuit to discuss). I'd like to pull back a little and see if anyone can help answer some of my questions above. We've touched on these concepts, but not directly. Any thoughts? ;)

I'd like to introduce another topic: safety and suppression. How might some of these designs better accommodate unexpected AC spikes or the wrong input voltage? MOVs, fuses...?

...to balance the positive and negative AC cycles, how might we switch off the triac at a peak?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf