Designing a Mains Quad Trailing Edge Dimmer PCB - Page 1
Forum section: electronics / projects

author: konbaasiang
author_rank: Contributor
timestamp: November 13, 2020, 04:04:15 pm
content: Howdy!I started making circuit boards last year and I'm getting progressively better and more daring.Here's myfirst everboard.My last two boards have had 220v mains on-board, but only in a corner, power in/out controlled by a relay.This time, for my 7th board, I'm trying to make a dimmer. Why? Because I'm a sucker for punishment, and I really want to get better at this. I do not however wish to burn my house down, so I was hoping you guys could look this over and let me know what horrible mistakes I've made.On my previous PCBs, I was able to keep the HV section single sided,like so (board 5).Or like thismuch smaller (board 6)board.Alas, for the dimmer, considering thatbasically the whole darn thing is mains tied, it's of course not that easy, and I feel I'm out of my depth.Here's what I have so far. Schematic, PCB pictures, and the EasyEDA files.It's a quad trailing edge dimmer with WiFi control, with an STM8 doing the dimming work (frequency agile!) and an ESP-01 telling it what to do. I've written the STM8 and ESP8266 code myself.The zero crossing detector usesthis schematicverbatim, built it on a perfboard, works beautifully.The MOSFET part of the circuit isinspiredby other designs I've found online, but I've spent significant time on it myself, and tested multiple designs on perfboard before getting it to work reliably. I use the FOD3180 opto-isolated gate driver and IRF840 mosfets, but in order to power the mains-side of the circuit, rather than resistor or capacitive droppers, I actually tie the DC output ground of a little switching power supply module to the SOURCE pin of the IRF840, mains-tying that whole side of the circuit.I havenotyet added cutouts to this board, and I do want to add ground fill for the low voltage part, but here are the questions I have so far:Is it really okay for Live and Neutral to cross each other on the opposite layer of the board?Is it really okay for either Live or Neutral tocrossa low voltage signal wire on the opposite layer of the board?The drain on the MOSFETs is live, and that means the heatsinks are live. This thing will live in a box away from human hands so I'm not too worried about this particular thing.Because such a big part of the circuit is live (notably the 12V switcher output is referenced to mains so that it can control the mosfet gate!) I wasn't able to avoid mains crossing signal wires.. but at least they're not parallel.I am a beginner in over my head but I would love constructive feedback. Please do not bite my head off, I occasionally need it for other things.Looking forward to comments, thanks very much in advance.///Leif

author: james_s
author_rank: Super Contributor
timestamp: November 13, 2020, 11:25:08 pm
content: That looks quite good for so little experience.Yes it's totally fine for live and neutral to cross on opposite sides of the board. It's also ok for low voltage signals to cross, you should avoid running them parallel to mains voltage stuff when possible, especially high current paths. Live heatsinks can be ok when everything is enclosed but it is preferred when possible to avoid that, if you can live with a small reduction in heat transfer mica or silicone insulating pads and shoulder washers can be used to isolate the heatsink. Be careful about using small surface mount resistors with line voltage, many of them are only rated to handle a few tens of volts.

author: konbaasiang
author_rank: Contributor
timestamp: November 14, 2020, 03:20:33 am
content: Wow, thank you very much for that @james_s! That makes me feel a whole lot better.Good point about the heatsinks. I will get shoulder washers instead, and change the footprint so the heatsink solder point is insulated rather than drain-tied.The zero crossing detector article did talk about SMD resistor voltage ratings -- this is the reason ZR1 and ZR2 are two 220k resistors rather than one resistor of twice the resistance. But, now that you mention it, I'm going to change them from 0805 to 1206. There are the only resistors on the board that perform a mains voltage drop though, the rest are all at under 20 volts potential difference.(edit) JLCPCB doesn't carry 220k 1206 in the basic library. I looked at the data sheet for the UniOhm 0805 resistors and it claims Max Working Voltage 150V and Max Overload Voltage 300V. The working voltage in my circuit would be 115 volts (230 volt mains and one resistor per leg). That's plenty of safety margin isn't it? If the mains voltage went up to 600 volts I have a feeling other things would fail first.Would you make any other changes?

author: schmitt trigger
author_rank: Super Contributor
timestamp: November 14, 2020, 03:47:36 am
content: On a sinewave, the peak voltage is 1.41 times the RMS voltage.Thus in 115 volts RMS, the peak would be 162 volts. The 150 volt resistor rating would be too narrow.Better to use a pair of 110k in series to replace the single 220k. Keeping the 0805 size.Other than that I also congratulate you on your project.

author: konbaasiang
author_rank: Contributor
timestamp: November 14, 2020, 07:18:17 am
content: Oops! As a DSP software engineer with 20 years of experience, Ireallyshould not have forgotten that... Thank you, @schmitt trigger!Here's the updated design. I've done lots of cleanup, added cutouts, added a ground plane for the low voltage part, and added holes.Anything else that comes to mind? Otherwise I think I'm ready to order the PCB and hope for the best.The SMD components (except for the FOD3180 optocoupler) will all be supplied by JLCPCB and factory soldered. I do not know how they can do it at this price.. If we ignore the design time (which we really should because that's education) then these tiny board runs are coming out much less expensive than buying finished products, plus I'm gettingexactlywhat I'm looking for. It never ceases to amaze me!

author: james_s
author_rank: Super Contributor
timestamp: November 14, 2020, 08:47:22 am
content: Watch out for the clearance around the screw holes, it's easy to not account for the diameter of the screw heads or metal standoffs if you use those, you want to make sure they don't become electrically live or mechanically interfere with connectors.I made no attempt to analyze the circuit itself, is that a verified working design?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 14, 2020, 10:03:48 am
content: Quote from: konbaasiang on November 13, 2020, 04:04:15 pmI've just finished the design of a 16-channel AC dimmer, so let me save you some time and melted parts...You can't tie the MOSFET drains for each channel together - they need to switch independently otherwise channels will interfere with each otherThis also means that you need independent isolated supplies for the HV side of the optoisolators on each channel. To avoid this, instead of the FOD3180, look at the Silabs Si8751, which doesn't require a HV-side supply. Use a 100n cap on the TT pin to get consistent turn-off timing.You don't need those diodes across the MOSFETs - when the gates are diven, they will both conduct bidirectionallyQuoteYesQuoteYesQuoteThere are probably better MOSFETS than the IRF840 nowadays , with lower RdsOn, which may not need any heatsink.Put a neon indicator on your test board so it is immediately obvious when it is live.Do NOT use a variac or isolating transformer to supply the dimmer, as the turn-off causes an inductive kickback from the secondary inductance that can kill components. If you need to use an isolating transformer, connect a few uF of 400VAC rated capacitors across live and Neutral to absorb the spike.

author: Yansi
author_rank: Super Contributor
timestamp: November 14, 2020, 10:29:24 am
content: Quote from: mikeselectricstuff on November 14, 2020, 10:03:48 amI find these two especially valuable suggestions.

author: konbaasiang
author_rank: Contributor
timestamp: November 14, 2020, 01:10:23 pm
content: Quote from: james_s on November 14, 2020, 08:47:22 amI was going to use plastic standoffs, but you're absolutely right -- it's better to increase clearance to allow for screws as well.Well, Ithoughtit was a working design, I built and tested it, but I only tested withonechannel. Mikeselectricstuff definitely burst my bubble on that, I'm trying to understand it now.Quote from: mikeselectricstuff on November 14, 2020, 10:03:48 amWhoa! Thank you, Mike. That isextremelyuseful information.I'm trying to understand where I screwed up. I builtthiscircuit on perfboard, and it works.But, I only builtonechannel. Now that you've given me the answer, I see the problem, and even then it took me quite a while! Oops. This would have been a nice puff of smoke wouldn't it?Quote from: mikeselectricstuff on November 14, 2020, 10:03:48 amThanks for the tip about Si8751! I looked it up, apparently it uses a little RF transmitter and receiver rather than using an LED. Neat! I hadn't heard of that, that must indeed save a lot of power.Some things speak against it for my particular application:I've already bought FOD3180'sI've already bought power supply modules'sFOD3180 + PSU module is actually slightly less than just the Si8751My usual suppliers (Aliexpress, mostly) don't seem to have itI'll definitely keep it in mind for the future though, more knowledge and more tools is always a good thing.So then.. What say you I redesign it to be asinglechannel dimmer?I didn't particularly need aquaddimmer, it was mostly a software engineering challenge, to learn programming the STM8 and to make the most out of a single one ($0.22 !!). That code is written and done, but there's no reason I couldn't just use it in 1-channel mode.That would also make it a much smaller board which is useful.Questions:How about I make thewhole thingmains tied? There's so little remaining on the board thatisn'tmains tied anyway. I don't need direct serial debugging, WiFi and telnet is plenty.That way I could get by with a single power supply, and a single fuse that includes the load.Of course, this would mean that the AMS1117 3.3v regulator would be starting with 12 volts rather than 5 volts. It's specced at 1 amp, and the ESP-01 peaks around 300mA, normal current use is about 100 mA.Would that be okay, you think?Also, do you have a particular suggestion for a better MOSFET?The external diode to "protect" the mosfet wasn't my idea, that was part of one of the schematics I borrowed inspiration from. Are there any limitations to the internal diode or were they just being overly cautious?I've ordered 200 neon indicators and the corresponding 560k resistors. But, the PSU module already has an LED. Do you mean for the neon indicator to gobeforethe main fuse?Quote from: mikeselectricstuff on November 14, 2020, 10:03:48 amI had no idea! Thank you.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 14, 2020, 01:39:31 pm
content: Quoteit's not about power saving, but the need to have a seperate isolated supply for each channelQuoteYou still need one PSU for the control plus one per channel for the gate driver, so there is no good reason to not isolate the low-voltage control stuff. the draw from the wifi is too much to be able to use a cap dropper, so may as well use an isolated PSU module.QuoteNo, just look at the RdsOn figures and pick the lowest you can affordQuoteThe internal diode does not conduct any significant current as the MOSFET will be on when current can flow in its directionQuoteJust something so that when you are testing it on the bench ist is very obvious when mains is on

author: konbaasiang
author_rank: Contributor
timestamp: November 14, 2020, 03:26:44 pm
content: Thanks so much for your responses, Mike!Quote from: mikeselectricstuff on November 14, 2020, 01:39:31 pmI get it now. It literallytransmitsits own power as RF from the isolated side to the mains side, and even boosts the voltage. Okay that is awfully cool. Maybe I really should go this route, this would savea lotof space compared to the PSU module.Quote from: mikeselectricstuff on November 14, 2020, 01:39:31 pmI wasn't going to use a cap dropper, I was looking at the AMS1117 3.3v voltage regulator, but it is linear and a quick google search tells me it would be wasting 4 watts of power and self destruct.. so you're right, I'll indeed need _two_ power supplies... i'm starting to see why the Si8751 was invented!Quote from: mikeselectricstuff on November 14, 2020, 01:39:31 pmYes, I got that. The PSU module already has an LED which would indicate that mains is on, unless the fuse blows, or the PSU dies. Thus my question, do you mean for the neon indicator to gobeforethe main fuse of the board, so that it stays on even if the fuse blows? Because otherwise it doesn't provide all that much indication beyond what the LED on the PSU would.Also, just one more question, since I'm already far enough down the path to have a whole bunch of FOD3180's that I will probably never get to use if not for this project..Do you think it might be possible to power the FOD3180s by individualcapacitive droppers?I wasn't going to tackle capacitive droppers yet (i've never used them so far) but plans change, and it's certainly on my list of things to learn about.. so maybe it's time?

author: james_s
author_rank: Super Contributor
timestamp: November 14, 2020, 06:39:52 pm
content: Quote from: konbaasiang on November 14, 2020, 01:10:23 pmWhoops! That's a trap most will fall into sooner or later, I certainly have. Prototype the part you think will be tricky, feel pleased that it works and then overlook a detail integrating everything together and literally fail the smoke test when you first power it up, it happens. At least this was caught before you got a nice flash & bang.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 14, 2020, 08:59:27 pm
content: Quotethis is just something to do while prototyping and bench testing, to remind you it's liveQuoteprobably not - it gets messy because the ground reference for the opto is not one of the mains live or neutral, it's a messy place in the middle of the MOSFET switchAs regards power, just use an isolated switchmode 5V module to power all the logic, and the Si8751 to drive the MOSFETs

author: Alti
author_rank: Frequent Contributor
timestamp: November 14, 2020, 11:06:28 pm
content: Quote from: konbaasiang on November 14, 2020, 01:10:23 pmAbsolute maximum rating of IRF840 for Uds is 500V and you intend to protect it with 10D471K varistor. This varistor draws about 1mA at 517V.How are you going to supply the dimmer? If from mains 230V then you won't find a commercial surge protector that limits voltage to 500V peak. Of course you can design a custom made SPD but that is even more complicated than your dimmer. Commercial surge protectors limit the voltage to around 1500V peaks in case of 8/20us mishaps.Then, there is no feedback from current there.Instead you want to use a fuses for overload and short circuit protection? I cannot see how this could happen with 1R Rds on. You need a fuse that is more sensitive than mos, that heats up faster, blows faster etc. So if mos is already 100oC and short circuit comes, it can survive only 100mJ single pulse energy. Lets say supply has 1R prospective short circuit current and rds on is also 1R so we get 325V/2R=162A. You have to limit RI2t to 100mJ which means i2t=0.1A2s The fastest fuses capable of interrupting 162A and 0.1A2s are maybe 250mA rated. And if you try to power something that has inrush (like capacitor or incandescent) then you need to derate that significantly or maybe use some sort of PWM ramp up but for that you need a feedback.

author: konbaasiang
author_rank: Contributor
timestamp: November 15, 2020, 03:48:05 am
content: Wow, this istremendouslymore complex than I had first imagined.I might not be ready for this quite yet. I appreciate everyones answers. If you guys will put up with a few more newbie questions, I may possibly be able to pull this off.Quote from: mikeselectricstuff on November 14, 2020, 08:59:27 pmI was kind of afraid of that. Okay, that makes sense now. I will give up that route, especially since .....Quote from: Alti on November 14, 2020, 11:06:28 pmOh crap. I had not paid that any mind at all. The IRF840 came fromGreatScott's dimmer design.The varistor / capacitor / resistor (AKA RC snubber) came from reverse-engineering (if you can call it that, it's only three components)this RC snubber. I do not yet have the skill and experience to verify the soundness of those designs other than a cursory inspection and trial and error. They worked as far as I couldobservebut of course that doesn't account for edge cases that I can't yet see at my low experience level. This must mean GreatScott's trailing edge dimmer design is unsound as well, considering it doesn't even include the RC snubber. Speaking of... the RC snubber is a low pass filter -- it'll short out high frequency spikes won't it? So yes, if the mains voltage becomes a continuous 600 volts then this dimmer would blow up, but so wouldeverything elsein my house. On the other hand, if there's a narrow spike (meaning high frequency, by necessity), wouldn't the RC snubber eat it?Okay, so assuming I go with SI8751 as the driver.. How aboutthis mosfet? RdsOn 0.36, Vds 700 V.I don't know what level of voltage spikes wereasonablyhave to handle in a mains-connected appliance? Is there a general rule for what "most" appliances are designed to tolerate?

author: Alti
author_rank: Frequent Contributor
timestamp: November 15, 2020, 10:30:28 am
content: Quote from: konbaasiang on November 15, 2020, 03:48:05 amYes, snubber is a filter and it is going to pass some of the current on transients. Unless you design it to limit voltage to 500V on transients, it won't affect miserably short life of unprotected mos.Ragarding 600V - it seems you do not understand the difference between overvoltages and transients. Also, for killing this mos you do not need 600V because 501Vismay be enough (according to datasheet).Similartopic.

author: konbaasiang
author_rank: Contributor
timestamp: November 16, 2020, 02:47:20 am
content: Heeey, wait a minute here.Quote from: Alti on November 14, 2020, 11:06:28 pmYes, the IRF840 has absolute maximum Vds of 500 volts -- and I havetwoof them basically in series, each handlinghalfthe waveform. Each one sees 120 VAC RMS (170 V PEAK). That's a safety margin of3. Are you saying that is still not enough?The MOV isn't there to protect the FETs from mains transients, a mains transient would have to be extremely high current to make it that far, not sure how to even protect from that.. This MOV was part of the RC snubber design I borrowed, and I believe the RC snubber protects the FETs from transients from aninductive loadsuch as a dimmable LED bulb. I don't know whether it's the MOV or the RC filter or both doing the job, but my oscilloscope tells me the jobisbeing done with the RC snubber in circuit -- andnot at allif I disconnect the snubber, which is on a separate PCB in the perfboard prototype.I've now changed my plan for the quad dimmer board -- when I design it in the future, I will use the Si8751 and a better mosfet.Fornow, since I already have a bunch of FOD3180s and IRF840s and SMPS modules... what about doubling up on the IRF840s? I may as well use them forsomethingat this point -- if I don't they'll eventually end up in a landfill years down the line, after languishing in my parts drawer forever. Using two inparallelought to help, by halving RdsOn?This way I could at least have some WiFi-controlledsingle channeldimmers.

author: Yansi
author_rank: Super Contributor
timestamp: November 16, 2020, 08:42:45 am
content: I it not enough, because dimming using mosfet is problematic by itself, as you are switching off loads under current - and have non-zero inductance leads to the load and given the load itself may be slightly inductive.

author: konbaasiang
author_rank: Contributor
timestamp: November 16, 2020, 09:00:35 am
content: Quote from: Yansi on November 16, 2020, 08:42:45 amI've actually scoped across the load (a dimmable Philips LED bulb) using a transformer.Without the RC snubber across the dimmer, indeed there's a huge voltage spike as tall as the AC waveform itself.Withthe RC snubber, on the other hand, it goes awaycompletely. I simply do not see it on the scope at all.Here is a video clip of averyslow and smooth dimming cycle:https://www.dropbox.com/s/opwqxms3ja1n52o/VID_20201112_101701.mp4?dl=0There wasnoother ballast in parallel with the LED bulb. You'll notice at 00:41 the E12 socket is empty, and at 00:48 you see the E12 incandescent bulb on the table not connected to anything.With an incandescent bulb as the load, the RC snubber is unnecessary, but indeed with an LED bulb it is required.

author: Yansi
author_rank: Super Contributor
timestamp: November 16, 2020, 09:21:13 am
content: Scoping through transformer is useless, unless the transformer has a bandwidth of at least 10+ MHz. Use a HV differential probe, or a setup where you can scope directly.Also, take into account load may be connected even through 50m of cable.

author: Alti
author_rank: Frequent Contributor
timestamp: November 16, 2020, 09:32:42 am
content: Quote from: konbaasiang on November 16, 2020, 02:47:20 amTransistors are not "basically in series". There is MOS + bdiode in one direction and bdiode + MOS in the other. I fail to see 2x120VAC there.QuoteThis project is far too complex for your skills.And far too dangerous. How about switching to 24VAC?

author: konbaasiang
author_rank: Contributor
timestamp: November 16, 2020, 10:00:39 am
content: Quote from: Yansi on November 16, 2020, 09:21:13 amUseless? Clearly hyperbole. The inductance spike was there clear as day without the RC snubber in circuit (through the transformer!) and gone with it. A 1st order RC filter has a response of 6 dB per octave (speaking as a DSP engineer now) so it's going to attenuate more at higher frequencies. Why would there be anything significant left to see at 10 MHz+ ?.Quote from: Alti on November 16, 2020, 09:32:42 amI measured across Drain and Source on one mosfet through the entire dimming cycle with a true RMS multimeter and it reported no more than 120 V AC -- before posting. I'm not pulling stuff out of nowhere, I'm reporting what I'm observing. It doesn't matter that it was a half rectified wave, the voltage across one mosfet is stillhalfof the peak-to-peak voltage.QuoteI will be the judge of that, thank you.

author: Yansi
author_rank: Super Contributor
timestamp: November 16, 2020, 10:12:12 am
content: Just saying, that a transformer is not the tool of choice for scopingtransients. Especially in this case, when it was likely just a plain 50Hz iron one or what.

author: konbaasiang
author_rank: Contributor
timestamp: November 16, 2020, 10:19:18 am
content: Quote from: Yansi on November 16, 2020, 10:12:12 amThatis a neutral and informational statement! Thank you. I can work with that. I will get HV differential probes, that sounds useful.Here's a question to put things in perspective, with regards to danger and such:What is the failure mode?If the MOSFETs fail short, then the light will stay on. That's not a disaster.If the MOSFETs fail open, then the light will not turn on. That's not a disaster either.The scary failure mode would be if they become resistors. That would make them very, very hot. The PCB will however be in a metal enclosure so I'm not particularly worried about that either.Am I missing any obvious failure modes?

author: Yansi
author_rank: Super Contributor
timestamp: November 16, 2020, 10:47:27 am
content: Mosfets usually fail short. Depending on the circumstances, light staying ON may not be great. For example - imagine your dimmer ruining the theater experience, because of lights stuck full blast on. Unfortunately, there is not much you can do about it, apart from overengineering it enough, so that the failure mode is very rare.Btw, Micsig sells some good priced HV diff probes and I think even Dave here sells or sold rebranded EEVblog HV diff probe, that was with a very good spec, 100MHz.//EDIT:Also note, that the transient switchoff voltage is dependent on the switched current. So you need to verify at your maximum output current. Small light bulb on the bench won't cut it, try some decent cable length and 500W halogen lamp.

author: konbaasiang
author_rank: Contributor
timestamp: November 16, 2020, 11:43:14 am
content: What a coincidence, Micsic is exactly what I ordered. Thank you.Thanks also for the failure mode info. Indeed failing short isn'tconvenientbut it's thesafestfailure mode for a dimmer -- then it may not even get hot. A light failing on isn't critical in my application. Perhaps I should add a solid state relay to the circuit as well for safety.Once I've built the first PCB I will test it with a heavier load and a FLIR One camera.

author: konbaasiang
author_rank: Contributor
timestamp: November 17, 2020, 01:55:40 pm
content: Redesigned board, single channel only.I made space to double up on the MOSFETs just to be able to use the IRF840 for something. With better mosfets (or low power load!) then not all need to be populated.Separated the heatsink solder pad from the drain pin, to be able to isolate the heatsinks.30 boards (5 boards, 6 panels) ended up costing $60 shipped including all SMT parts except the optocouplers, so if it works, great -- and if not, well that's how learning works.Thanks everyone for the wide range of replies.