Isolated zero cross detection w/ AC mains - Page 1
Forum section: electronics / projects

author: iroc86
author_rank: Regular Contributor
timestamp: October 05, 2019, 12:24:29 am
content: I'm working on a hobby circuit that requires an isolated zero cross detector based on AC mains voltage. I've seen this done many different ways, often using an optocoupler and full-wave rectifier. I've also seen transformers used to step down the voltage to something more reasonable, like 15 V, which is then fed into an op-amp or TTL switch. The latter approach seems to be more common when a transformer is already being used in a power supply, since the component is already there.How do these two methods compare to one another? When would one be more suitable than the other? Is it ever common practice to combine both techniques, stepping down the high-voltage AC and then running that through an optocoupler? I know it's tough to make generalizations without seeing schematics, so I'm just looking for a rule of thumb.

author: coppice
author_rank: Super Contributor
timestamp: October 05, 2019, 01:15:04 am
content: Do you just want to see that crossing are occurring, or do you need a low latency means of detection so you can see the exact time of each crossing?

author: floobydust
author_rank: Super Contributor
timestamp: October 05, 2019, 01:18:06 am
content: What are you doing with zero-cross?AC mains is always dirty, so you need transient protection and low pass filtering.Any delay or phase-shift from a LPF or transformer needs to be corrected for.Mains is high voltage so you need safe isolation unless your device is referenced to neutral.

author: iroc86
author_rank: Regular Contributor
timestamp: October 05, 2019, 02:20:04 am
content: Sure, I can provide some more details. I'm using the zero cross detection to fire a solid state relay for a certain number of AC waveform periods. The zero cross will be used to determine the starting point and then count a number of full cycles. I don't need this to be super accurate, but within 5% of a period would be good... I'm in the US, so that'd be around 1 ms for 60 Hz.Thanks for the reminder about transients and filtering, floobydust. Many of these DIY circuits on the Internet don't take that sort of thing into account.

author: floobydust
author_rank: Super Contributor
timestamp: October 05, 2019, 05:41:18 am
content: A textbook method is an opto-coupler fed from mains. But this is highest cost and risk as far as wiring and the opto's pcb traces. You have to be mindful of proper clearances for mains.Assuming your project is powered from a small transformer, it's easiest to use the secondary AC as the transformer did all the work of safely lowering and isolating mains for you. There is a small phase-shift due to the transformer but you can check with a scope if it is significant. Zero-cross switching SSR's can trigger above 20V so they are a little late already.You need an even number of 1/2 cycles so the big transformer core does not saturate andmany 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.https://www.electronics-lab.com/project/mcu-controlled-spot-welderZero Crossing Detectors and Comparators - Rod Elliott (ESP)Your firmware should trigger on a zero cross and ignore anything for almost 1/2 cycle say 7-8 msec, as any incoming zero-cross in that interval is going to be noise, unless you initially have triggered on noise. I wasn't sure if you are only counting cycles, or also doing phase-control for start or control.

author: Ian.M
author_rank: Super Contributor
timestamp: October 05, 2019, 06:34:51 am
content: Errr.... Where did the O.P. say the load is a transformer?However if you are switching a *LARGE* resistive load, its also a good idea to keep positive and negative half-cycles balanced, to avoid any risk of saturating the utility company's pole pig if you are the only active consumer on it.

author: floobydust
author_rank: Super Contributor
timestamp: October 05, 2019, 08:25:29 pm
content: I assumed OP is doing spot-welding, the application is unknown and that is the only place I have seen cycle-counting used.Large resistive heaters (many kW) don't seem to use cycle-counting PWM because the thermal time-constant is huge. I find they use many seconds on, many seconds off for proportional control. Even a kiln or air heater has a many second time-constant to heat up the element. There is further science comparing "nucleate poolboiling and film boiling local to the heaters" I think if fluid circulation is poor, where you'd want higher PWM (carrier) frequency.I remember a high kW electric (water) heater standard mentioning the PWM freq. limits, as far as to not upset the power grid's voltage regulation on tap-changers.

author: nctnico
author_rank: Super Contributor
timestamp: October 05, 2019, 08:31:36 pm
content: Quote from: iroc86 on October 05, 2019, 02:20:04 amHow about using a solid state relay with a zero cross detection built-in? That way you just turn it on for the duration of N cycles and be done with it.Otherwise I'd use this:I've used this circuit in a (one off) design but I still need to test it.

author: iroc86
author_rank: Regular Contributor
timestamp: October 05, 2019, 10:42:48 pm
content: Ah yes, you all guessed correctly--this is for a pulsed spot welder. Didn't mean to hold back info to begin with, but I wanted to keep my request as generic as possible for applicability to other situations. This controller will be attached to a Miller LMSW 220 V spot welder which had its main transformer rewired as per the 110 V model. The extra current was too much for the thin nickel material being welded. Even so, it's interesting to think about the resistive load scenario.floobydust and Ian.M, I didn't consider balancing the half-cycles to avoid saturation. An earlier version of my welder used a monostable 555 timer (no zero cross detection) to pulse the output through a solid state relay, and the weld quality was often inconsistent. 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.nctnico, I didn't know there were SSRs with built-in zero cross detection--that's pretty cool! That would be an easy solution, although I'm probably going to continue with the separate detector for educational purposes. With the schematic you posted, what about including some MOVs on the input side? I see that you're already implying fusing with the "L_FUSED" hot line.Quote from: floobydust on October 05, 2019, 05:41:18 amI had planned on some phase control to test various welding scenarios, although switching on the peak, as you mentioned, is probably the best bet. I mostly need to ensure that full cycles are outputted to the welder. I actually wanted to avoid using time delays in the controller and rely entirely on the line frequency to dictate the start/stop sequence based on the number of cycles requested by the user. I figured I could double the frequency from the zero cross detector to catch the wave at a peak instead of a cross. Then, send that back to the control circuit and count the number of periods until the preset limit is reached. (Not that this'll ever be used outside of 60 Hz, but there's a certain elegance in a feedback loop.)So, going back to the original question of transformer vs. optocoupler for zero cross detection, it seems that both options are doable and have different pros/cons. I will probably use a sealed AC-DC converter to power the controller, so using a transformer "because it's already there" may not be an option. However, as flooby mentioned, a straight opto would require some additional consideration for the PCB design due to the high voltage. This is a one-off design, and cost isn't a big deal, so I'm leaning towards the separate xformer+opto solution and just account for any phase shift as necessary. Thoughts on that idea for this particular application?FYI, you've all given me some good ideas to think about. Thanks!

author: amyk
author_rank: Super Contributor
timestamp: October 05, 2019, 11:30:34 pm
content: "It depends how much isolation you need"...A lot of designs I've seen for detecting the crossing of the mains uses nothing more than a high-value resistor chain.

author: glentek
author_rank: Regular Contributor
timestamp: October 06, 2019, 08:38:06 pm
content: What I used in a 1200W battery charger years ago"Mains to 2x 33k 1W resistors in series, 400V 1A bridge rectifier, 4N28 opto isolator

author: beduino
author_rank: Regular Contributor
timestamp: October 06, 2019, 09:56:51 pm
content: Quote from: glentek on October 06, 2019, 08:38:06 pmMains 230VAC or 110VAC?

author: glentek
author_rank: Regular Contributor
timestamp: October 07, 2019, 12:06:16 am
content: Quote from: beduino on October 06, 2019, 09:56:51 pmThis was for 240vac.

author: wraper
author_rank: Unknown
timestamp: October 07, 2019, 12:14:16 am
content: Quote from: nctnico on October 05, 2019, 08:31:36 pmIt's easier to use optocouplers specially made for AC. Like H11AA1

author: beduino
author_rank: Regular Contributor
timestamp: October 07, 2019, 10:45:38 am
content: Quote from: wraper on October 07, 2019, 12:14:16 amIsn't those 33k resistors too low for 230VAC? It looks like something around 0.4W loses on each of them?I've used for 230VAC 4 x 100k - (2x 100k in parallel) x 2 in series, so 2x 50k, then we have something like: 0.00115^2*100000 ~ 0.132W losses on each of 100k resistors.BTw, I've used two PC817 to have configuration similar H11AA1, but in this case I could detect on two pins not only zero crosing but also which part (top/bottom) of sine wave which might be sometimes helpfull in some applications.

author: wraper
author_rank: Unknown
timestamp: October 07, 2019, 12:32:48 pm
content: Quote from: beduino on October 07, 2019, 10:45:38 amYou calculate power loss. But do you even consider current and power through optocoupler? 100k in series means0.232.3 mA RMS current through emitter LED which BTW has forward voltage of only 1.2 V. For example H11AA1 has minimum 20% CTR. If you want to use higher resistance resistors, you would need to use otocoupler with higher CTR like H11AA4.

author: schmitt trigger
author_rank: Super Contributor
timestamp: October 07, 2019, 02:08:18 pm
content: Quote from: wraper on October 07, 2019, 12:14:16 amDitto for using the H11AA1. It makes life simpler.Also since it has a base connection, you may want to experiment with a small capacitor (C <15 pF) to ground, to reduce noise susceptibility which as others have noted, is prevalent around the zero crossings.

author: beduino
author_rank: Regular Contributor
timestamp: October 07, 2019, 11:19:27 pm
content: Quote from: wraper on October 07, 2019, 12:32:48 pmMaybe someone of us missed orders of magnitude of RMS current, so lets do the math with two 51k resistors in series (51000 Ohm 1W I've used in mains zero crossing three pin probe shown below):(230VAC-1.2Vf)/(2x51k)= 0.002243 A ~2mAIn this DIY probe below I've used mentioned 2xEL817 with its input diodes in antiparallel of course,so I'm capable sense near zero crossing to positive and negative part of mains sinewave if needed thanks to three pins instead of twoI use MPU in my spot welder, so I can compensate for zero cross based on logic analyser output from this probe and hall effect current sensing pure resistive load during the testsUPDATE: Of course mains connection shown above is not only hot black glued, but additional insulation put first on those exposed mains wires brown and blue, so do not try this unless you know what you are doing

author: wraper
author_rank: Unknown
timestamp: October 07, 2019, 11:39:13 pm
content: Quote from: beduino on October 07, 2019, 11:19:27 pmYes I messed up one decimal place. Still 2 mA with 20% CTR (=0.4 mA) sucks, especially for zero cross. 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.

author: beduino
author_rank: Regular Contributor
timestamp: October 07, 2019, 11:58:07 pm
content: Quote from: wraper on October 07, 2019, 11:39:13 pmWhen we use 33k instead of 51k we get ~3.5mA instead of ~2mA, so is it much better use 33k instead of 51k?In the case of 51k we get ~0.5W power disipation on both resistors, so ~0.26W per resistor - I used 1W resistors anyway.Quote from: wraper on October 07, 2019, 11:39:13 pmYep, so that is why I use MPU to calculate average period instead of making decisions only based on zero cross pin state, so hopefully also filtering some noisy zero crosses in software.

author: Ian.M
author_rank: Super Contributor
timestamp: October 08, 2019, 02:36:30 am
content: Here's an idea that gives you one pulse per AC cycle on the falling zero crossing. It doesn't give you the rising zero crossing, but that's not a problem if you have a MCU doing the phase control. It only presents a 1 Meg load to the line, but stores charge to slam the optocoupler LED with a 50mA pulse for a nice sharp output rising edge.Its also got input filtering to remove fast transients, but the phase shift (lag) due to the filtering is approximately compensated for by triggering early, at about +13V. Its setup for 240V, 50Hz operation. The filtering would need to be tweaked for 60Hz and/or 120V operation to maintain the compensation.LTspice sim attached.

author: eliocor
author_rank: Unknown
timestamp: October 08, 2019, 08:45:07 am
content: https://web.archive.org/web/20150226043505/http://www.dextrel.net/diyzerocrosser.htm

author: coppice
author_rank: Super Contributor
timestamp: October 08, 2019, 11:06:34 am
content: Quote from: eliocor on October 08, 2019, 08:45:07 amThat circuit looks OK, but "all components can be low voltage SMD" in the features list is wrong. Use low voltage 220k resistors for R1 and R2 and you'll be in trouble, especially with 240V mains. Most small SMD resistors are only rated for 50V. You need to either use high voltage resistors, or split the 220k into multiple smaller resistances, and make sure you lay out the board to keep them from arcing across in a surge test.

author: wraper
author_rank: Unknown
timestamp: October 08, 2019, 11:32:42 am
content: Quote from: coppice on October 08, 2019, 11:06:34 amIf you go with 1206 size for those, you should be fine with general purpose resistors.

author: coppice
author_rank: Super Contributor
timestamp: October 08, 2019, 01:35:09 pm
content: Quote from: wraper on October 08, 2019, 11:32:42 amEven 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.

author: wraper
author_rank: Unknown
timestamp: October 08, 2019, 01:51:05 pm
content: Quote from: coppice on October 08, 2019, 01:35:09 pmThey usually have 1.5-2 times of that as surge rating.http://www.royalohm.com/pdf/product2017/GeneralPurpose.pdf

author: coppice
author_rank: Super Contributor
timestamp: October 08, 2019, 01:53:29 pm
content: Quote from: wraper on October 08, 2019, 01:51:05 pmYes, but when you try something like the standard fast pulse transient tests they can arc very badly.

author: wraper
author_rank: Unknown
timestamp: October 08, 2019, 01:58:09 pm
content: Quote from: coppice on October 08, 2019, 01:53:29 pmIf you don't use MOV, you can say the same about say PCB connector for mains input.

author: beduino
author_rank: Regular Contributor
timestamp: October 09, 2019, 12:14:35 am
content: Quote from: wraper on October 07, 2019, 11:39:13 pmI'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 voltageHowever, 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?I've used EL817 with cut off frequency around 80kHz shown in its datasheetI'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?

author: schmitt trigger
author_rank: Super Contributor
timestamp: October 09, 2019, 12:23:37 am
content: 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.

author: iroc86
author_rank: Regular Contributor
timestamp: October 09, 2019, 01:42:48 am
content: 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...?

author: beduino
author_rank: Regular Contributor
timestamp: October 09, 2019, 10:15:50 am
content: Quote from: schmitt trigger on October 09, 2019, 12:23:37 amI 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:Quote from: schmitt trigger on October 09, 2019, 12:23:37 amI'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 mainsNow, 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

author: Ian.M
author_rank: Super Contributor
timestamp: October 09, 2019, 10:35:54 am
content: @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.

author: beduino
author_rank: Regular Contributor
timestamp: October 09, 2019, 10:05:46 pm
content: Quote from: floobydust on October 05, 2019, 05:41:18 amSo, 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.htmQuoteIsn't it will depend on needed welding power accuracy, how accurate zero crossing or voltage peak maximum timing needed in given design?

author: iroc86
author_rank: Regular Contributor
timestamp: October 10, 2019, 11:10:53 pm
content: Quote from: Ian.M on October 09, 2019, 10:35:54 amAw, 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.

author: dmendesf
author_rank: Frequent Contributor
timestamp: October 11, 2019, 05:05:54 pm
content: 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

author: langwadt
author_rank: Super Contributor
timestamp: October 12, 2019, 12:07:46 am
content: there's also the crazy one, two optos, LEDs anti parallel, the two transistors arranged as push-pull

author: beduino
author_rank: Regular Contributor
timestamp: October 15, 2019, 12:39:53 am
content: Quote from: floobydust on October 05, 2019, 01:18:06 amMy 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)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

author: Circlotron
author_rank: Super Contributor
timestamp: October 15, 2019, 01:52:09 am
content: Quote from: iroc86 on October 05, 2019, 10:42:48 pmIf 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.

author: floobydust
author_rank: Super Contributor
timestamp: October 15, 2019, 02:04:41 am
content: 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.

author: uer166
author_rank: Super Contributor
timestamp: October 15, 2019, 02:05:20 am
content: 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.pdfIt 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..

author: iroc86
author_rank: Regular Contributor
timestamp: October 15, 2019, 02:49:28 am
content: Quote from: Circlotron on October 15, 2019, 01:52:09 amAh, 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 atanyzero 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).Quote from: floobydust on October 15, 2019, 02:04:41 amI'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 switchoffthe triac at a peak?Quote from: floobydust on October 15, 2019, 02:04:41 amYep! Two-stage operation with a preheat pulse is on my list of project requirements, too.

author: beduino
author_rank: Regular Contributor
timestamp: October 15, 2019, 06:56:41 pm
content: Quote from: floobydust on October 15, 2019, 02:04:41 amMy 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.Quote from: floobydust on October 15, 2019, 02:04:41 amI 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.

author: chris_leyson
author_rank: Super Contributor
timestamp: October 15, 2019, 08:33:08 pm
content: 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 264VACandyou 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.

author: beduino
author_rank: Regular Contributor
timestamp: October 15, 2019, 10:23:29 pm
content: Quote from: floobydust on October 15, 2019, 02:04:41 amYep, 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 periodOf 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

author: schmitt trigger
author_rank: Super Contributor
timestamp: October 16, 2019, 01:10:42 pm
content: 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.

author: Unixon
author_rank: Frequent Contributor
timestamp: October 16, 2019, 05:08:33 pm
content: I would recommend to try the circuit from figure #11 of ONS app.note AND9282, works perfectly.

author: beduino
author_rank: Regular Contributor
timestamp: October 16, 2019, 08:17:56 pm
content: Quote from: schmitt trigger on October 16, 2019, 01:10:42 pmProbably something like this I've already implemented in my spot welder software, mentioned also in ABB Gate-drive Recommendations for Phase Control Thyristorshttps://www.5scomponents.com/Pdf/5SYA2034-01.pdfFirst 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.

author: schmitt trigger
author_rank: Super Contributor
timestamp: October 16, 2019, 11:58:41 pm
content: You got it!BTW: how are you galvanically isolating the gate driver from the SCR itself?

author: iroc86
author_rank: Regular Contributor
timestamp: October 17, 2019, 02:37:31 am
content: 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?Quote from: iroc86 on October 09, 2019, 01:42:48 amQuote from: iroc86 on October 15, 2019, 02:49:28 am

author: Circlotron
author_rank: Super Contributor
timestamp: October 17, 2019, 07:54:49 am
content: To switch off the triac at the peak you would have to force commutate it, and trials are lousy at that. You can do it with an SCR but it is a bit of work. If you are interrupting current in an inductive circuit you need to have some sort of snubbing to deal with the energy in the inductance. Possibly not worth the effort.

author: Ian.M
author_rank: Super Contributor
timestamp: October 17, 2019, 12:45:47 pm
content: Why would you even want to force commutate at the peak?TRIACs naturally commutate when the current through them falls to zero, which is when you would want to switch off an inductive load anyway to avoid a massive back-EMF 'kick' from stored energy. Assuming an iron core inductive load, switched off at zero current, that leaves it with the residual magnetization from the previous half-cycle.N.B. immediately after switched off, it will *NOT* have zero volts across it as for an inductive load the current lags the voltage, so it wont reach zero current till somewhere in the half-cycle after the one you last triggered the TRIAC in.It would be a *BAD* *THING* to switch it again at a voltage zero crossing, because with no current flowing initially it has a whole cycle to build up, to what would be more than double its normal max. flux. This of course results in saturation and a massive surge current at switch on. Ignoring remnant magnetization, switch on at peak voltage, when the current would be zero for a perfect inductor and the flux buildup in the first half cycle is halved.However to make sure the flux in the first half cycle OPPOSES the residual magnetization, switch on during the OPPOSITE phase half cycle to the last whole half cycle it was on for. This can be critically important if your transformer is running right on the ragged edge of saturation, e.g. microwave oven transformers with the original primary, and if the application permits it, is good practice. Otherwise if the application doesn't permit a delay to let it choose the half cycle, it may be advisable to move the switch-on to a little after the voltage peak.Edit: corrected choice of half cycle to switch on

author: schmitt trigger
author_rank: Super Contributor
timestamp: October 17, 2019, 01:31:06 pm
content: Iroc;if you choose a SSR from a reputable company (for instance Crydom) they will be very robust, and they will already have built in all the isolation and protection that you require.Most times, all you require is an external fuse and/or a thermo-magnetic breaker. Just follow the datasheet recommendations.The Crydom SSR example linked below has an output rating of 24 to 280 volts. If you are switching 120 volts then you have nothing to worry about.https://www.digikey.com/product-detail/en/sensata-crydom/EZ240D5R/CC2235-ND/752094

author: beduino
author_rank: Regular Contributor
timestamp: October 17, 2019, 07:30:50 pm
content: Quote from: schmitt trigger on October 16, 2019, 11:58:41 pmIn my spot welder with bulky quite big transformer, I use two 2N6504 SCRs in inverse parallel with AC mosfets switch instead of optotriac MOC3020 in similar circuit shown below, so I can use eg. TLP351 optoisolated mosfet gate driver to turn AC mosfet switch on/off powered from galvanic insulated power supply eg. small transformer.

author: Ian.M
author_rank: Super Contributor
timestamp: October 17, 2019, 09:03:28 pm
content: Hmmm. The2N6504 datasheetsays they only have a 50V repetitive blocking voltage rating. I don't see how that's going to be compatible with a 240V RMS supply.Mouser have ST branded 40A 600V TRIACs in stock at under $5 USD e.g.T4050-6PF, which is in an isolated TO3 package so can directly bolt to a grounded heatsink. Its supposedly snubberless, so with a suitable snubber should commutate at least as well as the paired SCRs. To maintain the 600V blocking voltage rating, I would suggest aMOC3052random phase OptoTRIAC to trigger it.

author: iroc86
author_rank: Regular Contributor
timestamp: October 17, 2019, 11:44:39 pm
content: Quote from: Circlotron on October 17, 2019, 07:54:49 amGotcha! I had read about forced commutation and it did seem like a bit of work. Going to Ian.M's comment about this...Quote from: Ian.M on October 17, 2019, 12:45:47 pmIt was based on the idea of switching on equal half-cycles from a few posts up. I figured that if we switched the transformer on at a peak, we'd want to switch off at a peaknperiods into the future. Maybe I was confusing half-cycles with periodic symmetry? What you say about back-EMF and residual magnetization at zero current makes sense, though. This is what I was originally thinking:So, based on your description of switching above, would the ideal transformer switching waveform look something like the following? This would minimize inrush current at t=0, minimize back-EMF at shutoff, and support the triac's natural tendency to stop conducting at a zero cross. Or am I still confusing things?Quote from: schmitt trigger on October 17, 2019, 01:31:06 pmSorry, I should have clarified my question--I actually meant on the zero cross detector itself, not the SSR/SCR/triac. Most of the circuit designs we discussed here just run mains voltage straight through a few high-value resistors into the optocoupler. Would it be necessary to include some input protection on the front end of the detector, or would that be overkill for a 120-240 VAC application? It's not like a multimeter with CAT ratings, but that's just where my mind went since we're dealing with dirty AC and the potential for all sorts of surges and spikes.

author: Ian.M
author_rank: Super Contributor
timestamp: October 17, 2019, 11:59:40 pm
content: Re: second diagram in reply#55,Not quite. Remember the current lags the voltage in an inductor, so depending on the load resistance on the secondary side which 'reflects' to the primary scaled by the square of the turns ratio, the primary resistance and the primary inductance, it will reach zero current and commutate anywhere between the voltage zero crossing after the last firing pulse and the voltage peak of the next half cycle. If you add a trace for the primary current to your plot, you'll get a better idea of what's going on.

author: beduino
author_rank: Regular Contributor
timestamp: October 18, 2019, 05:19:44 pm
content: Quote from: Ian.M on October 17, 2019, 09:03:28 pmNope, eg.Freescale Semiconductor (2N6509) datasheetsays:"SCRs 25 AMPERES RMS 50 thru 800 VOLTS".I've 800V SCRs for sure, since no magic smoke so far

author: floobydust
author_rank: Super Contributor
timestamp: October 18, 2019, 08:31:25 pm
content: Many firmware examples (i.e. Atmel app note) do not debounce the zero-cross signal. They just make an interrupt based on every zero cross (falling) edge.This is not good if turning on the transformer makes a glitch on mains (due to inrush) and you get extra zero-cross falsely detected.The best systems, for 3-phase power phase control have a software PLL where the MCU synchronizes a timer to mains, so mains noise does not cause a retrigger or upset.After detecting a zero-cross, you would not expect another seen in under a 1/2 cycle time.Instead of counting AC cycles, you can just use a timer with multiples of mains frequency. Trigger on a zero-cross and make a pulse for n*1/50Hz duration.

author: TimNJ
author_rank: Super Contributor
timestamp: October 18, 2019, 09:01:01 pm
content: Quote from: iroc86 on October 17, 2019, 02:37:31 amAs of yesterday, I started designing a peak-firing inrush current tester for switch-mode power supplies. When testing inrush current, the worst case is taken at the peak of the line, so this is similar to your thought.This discussion here has brought up many good ideas. Just a few thoughts that might apply to you, though I'm not completely sure.1.) Consider keeping the main sensing/firing circuitry non-isolated, while using an isolated human interface. There may be some difficult to predict/correct errors associated with sensing via a step-down transformer. (Phase shift mostly, though maybe it's not that bad.)2.) My first idea for a peak-firing circuit is the following:Rectifiers + high voltage resistor divider chainEnvelope detector + filter to create a DC voltage based on the line voltage. The DC level follows the input voltage. If 100VAC, the DC voltage might be 5V. If 230VAC, the DC voltage might be 12V. This way it works irrespective on line voltage.With a comparator, compare the stepped-down, half-wave rectified (pulsating DC) signal to the DC level above. When the pulsating DC passes through the DC level, the AC wave is at its peak. If you want to sense both positive and negative peaks, use full wave rectified.D-flip flop (I think) to accept user input to stop. Flip-flop only goes low once a peak signal is detected.Isolated user interface (trigger, knobs, buttons) can possibly be implemented with optocouplers. Bias current/voltage for the optocouplers can be derived from a low power isolated power supply. Can probably use a tiny isolated 100KHz push-pull converter, maybe something like SN6501.

author: Circlotron
author_rank: Super Contributor
timestamp: October 19, 2019, 02:23:59 am
content: Or what about just stick a reduced version of the AC voltage through an op amp integrator to phase shift it by 90 deg and then to a normal zero crossing detector. Bonus is the integrator would function as a low pass filter, stopping any noise pulses getting through and causing false triggering.Or even easier still, just shove the raw AC through an RC network that would reduce the waveform to signal level, give very nearly 90 deg delay, and filter out noise, and then to the ZCD. What’s not to like about that?

author: TimNJ
author_rank: Super Contributor
timestamp: October 19, 2019, 03:52:15 am
content: Quote from: Circlotron on October 19, 2019, 02:23:59 amSounds good too.

author: beduino
author_rank: Regular Contributor
timestamp: October 19, 2019, 06:58:55 pm
content: Quote from: floobydust on October 18, 2019, 08:31:25 pmYep, I do something similar in my spotwelder MCU - mains ZC statistics are made, than when we need fire welding pulse train, ZC sensing ISR is disabled and this way we have more spare MPU cycles for other tasks like for example sensing current using galvanic insulated Hall effect sensor, manage pulses power, etc.BTW: That is interesting if there are any AC mains power grid standards like for example accuracy of clean mains 50Hz/60Hz period?

author: schmitt trigger
author_rank: Super Contributor
timestamp: October 19, 2019, 11:34:29 pm
content: You will be interested in the following:http://fnetpublic.utk.edu/index.html

author: beduino
author_rank: Regular Contributor
timestamp: October 21, 2019, 08:17:19 pm
content: I've already found functional specyfication of power grid in my country in europe and one of those documents mention among others thataverage frequency mesured within 10 seconds in mains contact should be in the ranges:1. 50 Hz ± 1% (49,5 Hz - 50,5 Hz) during 99,5% of the week2. 50 Hz ± 4% /-6% (47 Hz - 52 Hz) during 100% of the week.This might help detect inrush disturbances in ZC crossing software I believe in, since when looked at realtime country mains grid frequency data available on web site, this frequency does changes now and is something between: 49.990Hz - 50.020Hz at depends on actual demand of power in grid as I know.That is interesting

author: iroc86
author_rank: Regular Contributor
timestamp: October 23, 2019, 12:01:17 am
content: Quote from: Ian.M on October 17, 2019, 11:59:40 pmOkay, I think I got it... so the behavior would be something like this? The "region" being based on the variability of transformer design with respect to primary and secondary interaction.

author: Ian.M
author_rank: Super Contributor
timestamp: October 23, 2019, 01:11:50 pm
content: Again not quite, as the current waveform is phase shifted from the voltage by an amount that depends on the ratio of the load resistance to the load inductance. 0 deg for pure resistance, 90 deg lag for pure inductance. Therefore the red line is the LIMIT for the current phaseshift and the actual current waveform will have a phaseshift in-between the voltage and the red line. As you are building a spot welder the load is largely resistive when its working OK, so I would expect a large phase shift between making good welds and if there is poor contact with the work.Assuming you stop the gate firing pulses well before the end of the previous voltage half-cycle, the commutation time limits will be as you sketched, and the actual commutation point will be where the actual current waveform crosses zero, within that time range.

author: iroc86
author_rank: Regular Contributor
timestamp: October 26, 2019, 01:39:54 pm
content: Quote from: Ian.M on October 23, 2019, 01:11:50 pmGotcha. I think that's how I was understanding it, but my image maybe wasn't the most clear way of depicting it. I probably should have blurred the red current waveform from 0-90 degree phase shift to show that it could fall anywhere in that range based on the specific characteristics of the circuit.So, back to the earlier discussion about turning on the transformer, it sounds like the ideal "on" point would not necessarily be at the voltage peak, but rather at the current zero crossing point according to the actual phase shift characteristics of the load and transformer? I think this is what beduino was describing in his circuit in Reply #44 with being able to adjust the offset time.

author: beduino
author_rank: Regular Contributor
timestamp: October 26, 2019, 05:27:10 pm
content: Quote from: iroc86 on October 26, 2019, 01:39:54 pmNope, by offset time I mean between voltage peak maximum and next zero crossing, which is for 50Hz mains with T=20ms period T/4=5ms time span, but to ensure to do not triger thyristor in the case zero crossing missing, my idea is to limit this offset time to predicted 1ms before next ZC, so in reality for example by adjusting potentiometer between 0%-100% offset time will be in my case 0ms-4ms from voltage peak and additionally I'm able detect to fire pulse train from the same polarity since I can ditinguish which part of T/2 we are while I've sense positive/negative AC.Maybe, It is more visible in my post #47, when we do offset lets say half of T/4 lets say 2.5ms offset.In my software potentiometer will be used to choose spot weding program rather than set this offset directly, while sometimes we would like to do some kind of preheat or other things depending on what we spot weld, so MPU will be programmed to change those offsets in real time within e few seconds spot weld time in fully automated way.I'll heve some real data soon, since now I'm working on redesigning mechanics of spot welder to make it ready for testing new software.

author: iroc86
author_rank: Regular Contributor
timestamp: October 29, 2019, 01:23:37 am
content: Quote from: beduino on October 26, 2019, 05:27:10 pmSo, kinda like the way a triac dimmer switch works with incandescent bulbs? You'd be outputting a clipped wave based on the starting offset time. This is a little different than the welder design I've been thinking about, where the user would selectnnumber of full 60 Hz cycles to apply to the work piece.

author: beduino
author_rank: Regular Contributor
timestamp: October 30, 2019, 08:23:27 pm
content: Quote from: iroc86 on October 29, 2019, 01:23:37 amDepending on spot welder program choosen maybe I'll also apply full 50Hz cycles when more power needed, but I will always start welding somewhere close to mains peak voltage and the same +/- period.I'm not expert in this field, but based on very usefull documents mentioned in this thread about inrush currents in the case of inductive load this is a way I'd like to drive my spot welder transformer, which so big, that I consider liguid cooling on its secondary made of copper pipes instead of wires.

author: Circlotron
author_rank: Super Contributor
timestamp: October 30, 2019, 08:42:13 pm
content: Just thinking about it, seeing a spot welding transformer is meant for a specific purpose, not simply on continuously like most transformers, but dotted on and off, you would think that they would be wound for double the nominal voltage so that there would be no inrush current from saturation. They would then be able to tolerate a full half cycle of input voltage with the core magnetising beginning from zero instead of opposite polarity maximum and therefore not saturating when turned on at the voltage zero crossing. Seeing they are used that way they should be designed that way.

author: Ian.M
author_rank: Super Contributor
timestamp: October 31, 2019, 01:01:51 am
content: Why would you do that, which is more expensive in copper and iron, when its relatively simple to avoid saturation at no extra cost if there's a MCU controlling the pulse timing? It may have made sense back in the days of mechanical timers, but it certainly doesn't in the 21st century.