Low speed mosfet switching, do I need a decoupling capacitor? - Page 1
Forum section: electronics / beginners

author: AnasMalas
author_rank: Regular Contributor
timestamp: September 19, 2020, 02:52:40 pm
content: TL;DR: In the attached image driving a 12V 1A solenoid via a mosfet. Do I need decoupling capacitors to decrease the switching effect on the rest of the circuit, and if so, where? Also, will this design work reliably?Hello! I am building a little daughterboard for a project for my university that will serve students for a while and I want to learn as much as possible from it.part of this project is this schematic snippet, the references will be cleaned up laterThis is the circuit responsible to open the enclosure door. The microcontroller will send a 5V signal to the IRF7470 MOSFETs, which will then each turn on a 12V 1A solenoid which will retract the locking pin, allowing the door to open, there is no high speed switching, it'll be off for a while, then on for 3 seconds, then off. This circuit is hugely overkill, but I wanted to ensure reliability even if by some diminished returns, hence why I am using a mosfet per solenoid instead of one mosfet for both. I hope this gives enough information to answer the following:1 - I read a passing mention that decoupling capacitors were important in a similar circuit, but without any further detail. Now I don't think we want to decouple the gate, as that already has a capacitance which we use a pulldown for. Do we instead need to place a decoupling capacitor between source and drain? or source to 12V? maybe drain to 12V (across the solenoid)? Please help with that one. Also, what value of capacitor would you recommend?That was the main question, if you only answer that, id be thankful. But if you'd like to help more, please help me verify the below:2 - Is there any reason why this mosfet wouldn't work? It has a max Rds(on) of 15 mohm at 4.5 V VGS. This also gives a power dissipation of just 15 mW so no heat sinking is necessary. I am using 500 ohms in series instead of the common 330 to reduce unique components.(mosfet datasheet:https://www.infineon.com/dgdl/irf7470pbf.pdf?fileId=5546d462533600a4015355ff2fe11c18)3 - The flyback diodes seen here (ES1B-E3/5AT) are rated for 0.92V, 1A constant current, 30A surge current, and 15 ns recovery time. Is this enough for the current that will rush through once the mosfet is turned off? Unfortunately there is no datasheet to indicate the solenoid inductance and I dont currently have one to test (or the tools to do so)(Diode datasheet:https://eu.mouser.com/datasheet/2/427/es1-1768346.pdf)4 - I plan on placing the above diode close to the mosfet, and another through hole one near the solenoid terminals, with max 1 meter of wire in between. Is this a good idea?Sorry for the lengthy post, and thanks for any help!

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 20, 2020, 12:53:13 am
content: Yes, an electrolytic on +12V would be fine.Are you sure you don't want current limiting, or a protected switch likehttps://www.digikey.com/product-detail/en/stmicroelectronics/VNB35NV04TR-E/497-11686-1-ND/2746915?A TVS diode might be a good idea too, SMAJ24A or better. Won't prevent students from reverse wiring and blowing things up though, fusing and polarity protection might also be good.Presumably LockR comes from some logic circuit; if not, filtering and ESD protection is a good idea there too.Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: September 20, 2020, 08:00:15 am
content: Thanks for the reply, Tim!Quote from: T3sl4co1l on September 20, 2020, 12:53:13 amHaha I didnt know these existed, I think the part you sent might be a bit too large and costly, I found the ONSemi NCV8405ASTT3G, which is a $0.4 part with 120 mohm Rds(on) at 5V 1.4 A. and includes a temperature and current limit, and overvoltage protection. seems like a winner!https://www.onsemi.com/pub/Collateral/NCV8405-D.PDFQuote from: T3sl4co1l on September 20, 2020, 12:53:13 amAbout this, I felt like the original post was already way too long so I left out some detail, the students wont get access to the electronic board, it will be locked in an enclosure which is a book case in a library, along with some UHF RFID antennas and a reader, all to automate the library. We have a small library and there isn't an employee that stays there, so borrowing books is a pain for students, and book theft has been a pain for the administrators. That being said, I do want to protect the circuit, so thank you! So far I had only placed a USBLC6 on the USB C port used to upload to the atmega32U4 bootloader. Should I try and protect things more? I am sure that in the coming years someone might touch a circuit, perhaps an Admin or an engineer trying to fix something, so ill research more on this (if you think this is overkill, stop me right now before I blow my deadline even further)LockR(elease) comes from the 5V atmega32U4 directly, with only the 500 ohm resistor protecting it and limiting current to 10 mA. It will be grounded via software while the enclosure is locked

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 20, 2020, 10:24:53 am
content: Oh very little current is needed, that's fine then. I was matching Rds(on).Not needing outside connections besides power, is a great help for ESD. Still have to worry about coupled noise, but you should be able to insulate against direct strikes. And using solid ground plane on the PCBs helps a lot with that.Tim

author: David Hess
author_rank: Super Contributor
timestamp: September 20, 2020, 09:43:08 pm
content: Quote from: AnasMalas on September 19, 2020, 02:52:40 pmSlow switching reduces the di/dt so high frequency decoupling requirements are reduced but can introduce a new problem; time spent in the linear operating region is increased which can encourage parasitic oscillation if the load impedance is low. So some attention to decoupling and suppression of parasitic oscillations is still required. On the other hand, the inductive load limits di/dt anyway, but it still has considerable parasitic capacitance and the wiring going to it is a transmission line. If parasitic oscillation is a problem, then an output network somewhat like a Zobel network for an audio amplifier could be used at the switch between the switch and load.The decoupling capacitors should be placed to minimize the loop area of the highest currents. See below about the diode.Since low ESR decoupling capacitors can encourage parasitic oscillation, this is a good place to use an aluminum electrolytic part. A polymer aluminum electrolytic or polymer tantalum could also be suitable.QuoteThe diode should also be place to minimize the loop area and this is a common theme whenever high di/dt is present. Unfortunately this would be at the load which may not be acceptable so usually it is placed at the switch.

author: AnasMalas
author_rank: Regular Contributor
timestamp: September 21, 2020, 08:23:14 am
content: Quote from: David Hess on September 20, 2020, 09:43:08 pmMy apologies for my poor choice of words, by slow switching I meant the period; that i'm not doing PWM. The atmega32U4 will be given the on command and will immediately set voltage to 5V, I don't quite know the rise time, but it should be fast. I also think 10 mA is adequate to charge the gate capacitance fast enough that linear region operation to not be an issue.Quote from: David Hess on September 20, 2020, 09:43:08 pmSo the gate itself will be turned on with a high frequency step input, but then the solenoid won't immediately pull its 1 A rated current, it will go up gradually with an unknown rise time as you pointed out, and a zobel network (a resistor and a capacitor in series across the lines), so pretty much we use an electrolytic capacitor (say, 100 mic?) across the output and as it has a high ESR it will do the job? I could just cut the outside solenoid wires short, include a diode and a capacitor, and then resolder the wires all the way back. Did I get all that right? dont be niceQuote from: David Hess on September 20, 2020, 09:43:08 pmOk, so placing the diode and the capacitor near the coil reduces the loop area. Thus would you not recommend that I add a second set in parallel near the switch? potentially having two loops, but redundancy in case a diode fails?

author: David Hess
author_rank: Super Contributor
timestamp: September 21, 2020, 09:01:43 am
content: Quote from: AnasMalas on September 21, 2020, 08:23:14 amI misunderstood. I thought you were referring to limiting the edge speed. Decoupling requirements depend on the edge speed and not the repetition rate.QuoteThe transistor also has to driver the transmission line capacitance and the parasitic capacitance of the solenoid.The Zobel network if used would have a lot less capacitance and likely some series resistance added. But decoupling of the supply at the transistor and a flyback immediately after should be sufficient in most cases.QuoteNo, a second set should not be necessary except in an extreme application, but I have sometimes seen the diode placed directly across the coil if that is feasible.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 21, 2020, 09:23:29 am
content: The clamp diode is strictly better, placed right beside the transistor -- it's more a matter of, it may simply be acceptable to place it elsewhere. (this threadhas a rather exaggerated case of when it's not acceptable.)Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: September 21, 2020, 03:19:22 pm
content: Quote from: T3sl4co1l on September 21, 2020, 09:23:29 amhoookay wow, to, um, borrow your example: You can imagine a spherical shell expanding away from the my brain, encompassing all space that can possibly know about it being blown. Think of the shockwave from an explosive, made visible by the refraction of air; except in this case, instead of pressure, it's the...rather abstract idea of my mind being blown.some changes:-Changed the mosfet to one that is protected like you suggested-Changed the diode to one that includes "flyback" in its specifications, high pulse current, and a low recovery time (https://eu.mouser.com/datasheet/2/389/dm00164391-1798376.pdf)-Added an SMD long life electrolytic (that doesn't mention low ESR, this: ULV2G100MNL1GS).-Changed the door lock to a 12V 2 A one that only needs a 300 ms pulse and doesn't mind friction, this type:https://www.amazon.com/Atoplee-1pcs-Intelligent-Electric-Cabinet/dp/B01IBEVV0YI guess this should work well as it is, so unless you suggest something, this is the final circuit for this part.hey quick note: why the hell doesnot work? the above was uploaded to imgurAbout the SMAJ36A, I will be opening a new topic in a couple of days if my research doesn't come up with some answers, for example, do I need to place one on every pin (~20)? Arduinos dont do this and take a lot of abuse

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 22, 2020, 04:12:07 am
content: Quote from: AnasMalas on September 21, 2020, 03:19:22 pmAn appropriate reaction from math guy Matt Parker:QuoteI don't recommend putting the capacitor there, put it on 12V instead. Or at least, not as big of a capacitor -- a 10R + 0.1uF snubber would be fine, though I don't know that it's necessary.The alternative to the flyback diode, is a TVS from ground to output. As mentioned in the other thread, peak current is no more than on-current, so you don't need much diode (well, in usual cases, like this, not so much the other thread's monster solenoid).QuoteInline attachments have been disabled momentarily because they were somehow corrupting attachments(!). Workaround: post, expand the attachment, copy its image location, then [ img ] embed that.TVS diodes are usually only needed on external connections -- you said you're putting one on USB, and there's not really anything else connecting to the box, so that should be about it. A SMAJ12A (to 18, say) might be welcome on the 12V supply rail, just in case.Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: September 23, 2020, 01:22:38 pm
content: Quote from: T3sl4co1l on September 22, 2020, 04:12:07 amOh my, for some reason my brain completely mixed inductor voltage and current. It is voltage that can go way up! The inductor will "try to maintain" the current, increasing the voltage. the diode is there to provide a path for the current and stop the voltage from rising too high, not to dissipate all the energy in one quick pulse, Hence why in the monster solenoid thread you talked about the current running for seconds. D'oh!Now when going the TVS route, id naturally assume that I will want a unidirectional one (so no CA), but why dont I go with a low breakdown voltage one, like a SMAJ8A or such? The mosfet can have upto 42V S-D and it is internally clamped, so this is more about curiosity than anything. Perhaps we want a higher voltage part to dissipate the energy faster?Quote from: T3sl4co1l on September 22, 2020, 04:12:07 amYeah, about that... Tim, for future reference, should I post every detail, even if I think its unneeded? Below I think im oversharing with a wall of text, or do you think its good for completeness? feel free to just skip to the TLDR, you've already been way too generous with your timeThere are the following connections:- USB C, which now also connects the raspberry pi (main system computer) to the 32U4 softserial (I did this to remove the level converters, the USB is right there, so use it)- A 5V I2C connection, going to an ADC in the enclosure which has ambient light and temperature sensors (accent light and fan control)- The door mosfet and door switch circuit which we have discussed- 1 connector for the security lights. This goes 10 meters to the room door, and connects 4 security lights in parallel (5 wires: 1- 5V for the temperature chip, and for the 5V speaker used for the alarm, 2- 12 V to power the LED, 3- a PWM input for the constant current driver on each board, 4- a 1 wire fault bus, the temperature sensor will turn its open collector on if it reaches 75 C with only one pullup on the last node, this is also used to automatically detect if the lights are disconnected, and ofc 5- GND). I wanted to ask if each board needed TVS diodes, as well as the main one- 1 connector for the 5V addressable RGBW strip, used to accent the returns shelves and provide feedback, 1 pin from the microcontroller- 1 connector for the 5V addressable RGB strip, used to guide the user through the steps (University ID RFID HF reader, Book tag RFID UHF reader)- 1 connector that is just 5V and ground, which powers the touchscreen- 4 4-pin fan connectors, 2 40mm fans and 2 120mm fans, they share 2 PWM signals, and give 4 tachometer signals to the 32U4- 1 6-pin programming header, to load the bootloader on the 32U4 initiallyTLDR: There are a total of 12 power (5V and 12V, without GND), and 15 signal pins (excluding USB) going out of the main PCB, across 11 connectors. One of those connectors has a 10 meter wire connected that connects security lights on their own PCBs (my design too), with 2 power and 2 signal pins, and ofc a ground pin, and is the only connector to take signals and power out of the enclosure (excluding the PI, which should be fine).

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 23, 2020, 05:09:50 pm
content: Quote from: AnasMalas on September 23, 2020, 01:22:38 pmGoing from GND to switch, you can't use an 8V part because the supply is 12V of course (mind the difference between nominal, breakdown and peak voltage ratings); but anything between 12V, and a bit less than 42V, will do.Or with the protected switches, they're fine as is -- both in one.QuoteWell, I can't speak for others, but I have no problem reading in detail. The flip side of that is: if it turns out to be more work than I can afford to do for free, well, that's a shame; on the upside, at least you'd know, rather than finding out dozens of replies down thread; and you're not at risk of putting together something half-assed from partial information. (Not that electronic gadgets are usually much if at all safety critical, thankfully.)Quote1. And it's powered by USB? Wait, is there a converter to make 12V, or does that come from another adapter..?2. We should be able to treat the RPi as a black box, but if there are connections which loop around back and forth, we might still need to consider it, or the connections around it anyway. Example, if there's a 5 & 12V supply and that runs the RPi and 32U4 boards (+5V), and the 12V for the solenoids and junk. If these power lines are routed separately, there's a loop between them, which can pick up RF noise. (When is "ground" not ground? More often than you'd think.)3. Is that ADC still on the board, or is it just a.. pendant board, something sitting off to the side but still in the enclosure (yes) and short cable (under, say, 20cm I suppose)?FYI, cables are best with lots of grounds (or supply pins, which act as grounds when bypassed to it with capacitors at both ends). Typical use, 5 wire ribbon: GND, SDA, VCC, SCL, GND. Multiconductor cable would be fine too, and I wouldn't worry about it being shielded at this length.Longer runs must be shielded. The shield needs to be tied to PCB ground plane at each end, with as little jumper length as possible (preferably use metallic connectors so the ground connection can be as wide as the connector itself).Preferably, I2C isn't used over any distance at all. It is named with good reason! You can get converters to make differential I2C, which is more robust. Better still: use a more robust standard, and build a protocol around it -- RS-422 or 485 for example, with async serial, perhaps in a packetized format. Or there are lots of protocols to choose from.A simple case, just for putting peripherals at a distance, is SPI via RS-422. Differential, noise tolerant, fast. Tons of things talk SPI, so you don't need any logic, just tack on transceivers and go. SPI, because it's unidirectional: don't have to worry about managing multiple open-collector drivers. Downside: needs four pairs (or more), and doesn't fan out well (basically point-to-point; at the very least you need more nCS pairs, one for each target).QuoteOk, so that's a point of concern. I'd worry about, like, people and carts and stuff making ESD around that cable, for example.4. Is the temp chip an analog voltage then?5. Is the speaker, well, a speaker? Where's the amplifier, and what kind? Is it simply switched (for basic beeping I guess)? Or is it actually a buzzer (emits tone while powered)?6. PWM, for the LED? It might be better to put the CCS on the source end. Driving PWM straight off a MCU pin emits a ton of noise -- the risetime is under 10ns, so expect frequency content above 50MHz. And that 10m cable will make a fine "long wire" antenna for it!Bonus, with a constant current output, you don't have to worry about:7. Voltage drop -- when is ground not ground, again?It doesn't sound like there's all that much load out here, but if the loads are dynamic (i.e. you're turning on and off the LED, speaker, etc.), they may bounce all over the place. Or if the cable is long enough, it really doesn't take much, especially when your supply is only 5V or whatever.In short, look up the cable you've selected, find the resistance per length, multiply by length, and expect that that resistance is in the ground return path (and every other connection, of course). Take maximum load current, dropped through those resistances, and, if that's a substantial fraction of your total supply... consider getting a bigger cable, or at least raising the supply voltage (so that less current has to be drawn for the same power output).More specifically, if the voltage drop causes anything to run out of juice -- the temp sensor I suppose most importantly, but also if you have minimum power requirements for the other things, you don't want them browning out. Don't want sad buzzer sounds.Conversely, the temp sensor is setting its output voltage with respect to ground (or---whatever type of sensor it is), but if ground at the far end is higher relative to the source end, you'll get the same change in the temp signal. You may consider a "3 wire" connection: run a spare ground wire to the temp sensor, but don't hard-ground it at the source end: instead, use it to sense the remote "ground" voltage, i.e. measure the temp signal differentially. Key is that the two signal wires (TEMP and TGND let's say) carry ~no current, so have no voltage drop.8. Pay attention to how much bandwidth you're using. Only use what you need. Filter the rest. Use RC filters on logic signals that don't need to deliver load current. Use LC (often the L is a ferrite bead) filters on signals that do need to be fast (say if you were doing RS-485 at a full 10Mbaud). Bypass supplies for the most part, but also keep in mind the inductance of the cable L (there'll be a uH/m figure in the spec sheet and just multiply by length, or just guesstimate something in the 0.3-0.6uH/m range), and apply damping as needed. (Most common case: you'll have some capacitance C on the board, which is low ESR, ceramic chip caps perhaps. Use C2 >= 2.5*C in parallel, with an ESR of sqrt(L/C). So you have an equivalent circuit L + (C || (ESR+C2)), if that makes sense. Tolerances are loose, 50% is fine, doesn't need to be exact, just good enough. Electrolytics are a typical choice, or ceramics with added resistors. Tantalum is fine too, if you aren't hot-plugging this cable.9. TVS on the far end isn't a bad idea. Sounds like you've got a few 5V-level signals, for which... hey, you've got that USBLC6 thing already, that'd be fine here.The 12V, eh who cares, it's just a two wire loop with the LED really (if I understand correctly?). Maybe put an antiparallel diode on the LED just to prevent it overvolting in reverse. Some have this internally (check the datasheet?).Quote10. Put a ferrite bead or series termination resistor on the data pins. Mind the length of these -- not that you can e.g. add TVSs to the strips themselves unfortunately, but also if you have so many of them lit that they start to brown out, well, that just doesn't look very good. (Blue fades first, because it requires >3V. I think the chips themselves usually keep working down to 2.7V or less?)So, if you need long strips, better to use shorter strips and wire power to them somewhat separately (still okay to daisy chain the data, as long as ground is tied in the same place).A TVS diode on the data pins (on the main board) wouldn't be a bad idea. BAT54S is another handy pick here, or you can keep using the USB part (which is basically a dual clamp diode, good anywhere). Do try to hide or insulate the strings so they can't be zapped by errant fingers.QuoteFans, might put FB or RC filters on the PWM, and RCs on the tach signals? They can draw noisy current as well, for which a nice big ferrite bead can be helpful.Hmm, 120mm, those are big fans...Consider fusing, too. If it's like a few 100 mA, that's kinda meh, but a few amperes from the power supply, would be worth. Polyfuses are quite practical here.Programming, not worried -- I assume it's a blind header, not accessible outside. Pins aren't any problem, not nearly long enough to be an antenna. Speaking of, don't be worried about adding extra pads or headers for debugging purposes.Note, if you're running short on GPIOs, you may need to use the prog pins. This is fine, but mind it may be helpful to disconnect them for programming, so nothing gets confused there. Easy enough to do with some headers and jumpers.Or get a later model AVR, I forget which of the MEGA series or if that's mainly an XMEGA thing, but they have PDI on just two dedicated pins. Or maybe the 32U4 is even one of em? Haven't looked at it exactly, shrug.Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: September 23, 2020, 06:51:29 pm
content: QuoteHaha, no. There are two power adapters, one for the PI and its peripherals like the SSD and all, and then a switching power supply rated for 5V/8A, 12V/4A. The LED strips are the biggest 5V consumer, and the door lock solenoid is the biggest 12V consumer. The 5V carried over USB goes to the VBUS pin on the 32U4 and that's it, the grounds are tied over the PI GPIO header, the GND USB pin, and the USB shield (I remember researching this for weeks with massive headaches and religious fights with contradicting information, I concluded that I should just tie them together via a cuttable pad). I know about star grounding, but honestly I don't know how I can do that with this being my first PCB ever, and ill be honest here, ive been working on this for way longer than I care to admit, most of the work being learning. The current plan is having as close as possible to a 1 layer layout with the second layer being a ground plane, not ideal, I know.QuoteIts a ready made adafruit board built around the ads1015, that will be on top of the enclosure, with 3 light sensors that output an analog voltage which you can calculate flux from, and a temperature sensor that also gives an analog voltage. My thinking was that it would be more accurate to have the analog signal path as short as possible. The I2C signal here would go about 1 meter, which is longer than the 20 cm you recommend, but this is pretty optional so I dont mind risking it not working, I can always disable it and have the fans and lights run at 100%, rather than needing to design my own ADC board too.Now I do have a 5V level serial port completely open (USART), I could try finding a serial ADC if this is that much better, but I wouldnt want to add extra complexity just for thisQuoteThe sad reality is that I am not able to use anything that requires a crimper (other than an 8p8c plug, which I considered, but then abandoned in favor of pluggable terminals). I dont think shielded terminals exist, so I guess this is just another thing that I wont be able to do in this projectQuoteNo, there is an analog voltage output, but that is not connected (except for a test pad). This is a "thermostat" chip that will pull its output low if a factory preset temperature is reached on the GND pin (TI LM26CIM5), so it is just a digital thing, see below photo.QuoteOk here is where youd want to come fly over here and slap me, but we will be sending the PI camera signal through a long HDMI cable, via this little monster:https://www.amazon.com/Arducam-Extension-Module-Raspberry-Specific/dp/B06XDNBM63Now the raspberry pi will produce the alarm sound via its 3.5 mm audio jack, which will then travel through thatthing, to a normal desktop 5V 0.5A speaker. Tim ive been working on this project for like a year now, I have to bodge something or ill never finishQuoteAlright, here is the board ive designed for the security light, as you see, there is a constant current driver (That uses a transistor in its linear region), set to 40 mA. I havent seen the LED light output and am too afraid it could be too bright, so the PWM is a failsafe. but now that you pointed this out im changing over from PWM to digital 0/1, and if too bright i'll just add a tinted window.QuoteHaha they arent really, they are just 0.1A computer fans.Everything else is noted, thank you Tim, I really appreciate your help. I am in your debt

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 23, 2020, 09:35:51 pm
content: Quote from: AnasMalas on September 23, 2020, 06:51:29 pmAlright. You can at least reduce loop size, by routing the 5/12 from the PSU beside the RPi and bundle it with the USB cable and such. There can still be voltages between them (particularly due to current flows), but at least there should be less due to external noise.Yeah, ground the USB shield, and ground it in multiple points.Best 2-layer design approach is to pour ground on both sides, and stitch frequently with vias. Avoid placing components on both sides, in any given location; this allows ground to pour above or below any given component, trace or bus. Stitch around trace/bus crossings, minimizing the area where both top and bottom ground are excluded. (Traces can be grouped into buses, even when unrelated; probably the easier ground routing is worth the somewhat increased crosstalk in most cases.)QuoteIt's actually easier to filter slow analog signals, than to filter digital signals that have some minimum bandwidth requirement (like I2C at ~100kHz or whatever the default slow setting is).Downside: you need to bring back all the analog signals individually. Or multiplex them somehow at the one end, at which point it's not a big deal putting the ADC out there anyway.QuoteOh, no need for that, you can solder the shield onto a very short pigtail lead for example, not ideal but it's something. Better if many ground leads are used in parallel, all terminated to the shield. Can also terminate the shield with a fuse clip of the right size, tied to ground: strip back the outer jacket a bit, and wedge it into the clip. Place the clip near the edge of the board, and the connector somewhat inside from there. (If you can't find fuse clips of the right size, maybe try holders like here,https://www.mcmaster.com/tool-holders/holders/holders-6/)Or there's the fancy circular and rectangular connectors with solder-pot terminations... tend to be pricey though.Hmm, good old DE-9 may be an option. Lots more pins than needed, but highly available.As for cable, just about any of these will do, for example:https://www.digikey.com/short/z2d84mQuoteHmm, flex goes to the RPi? And you'd put in an extended flex? Or use the short one that comes with it, and a longer HDMI ( = shielded) cable?The latter is nice, if you put a ground clip between the HDMI jack and other grounds.The former is probably still fine, if you don't depend upon the camera, and don't mind it dropping out briefly. Or persistently, for that matter.If you need it up all the time... maybe good idea to put a shield on it. Which potentially is as simple as a strip of foil (copper tape?), bonded to board/enclosure grounds at either end of course. Preferably foil that wraps around (basically making a flattened multiconductor coax), and even more preferable, foil that terminates to a solid metal enclosure. (The shielded connectors on the RPi are probably the next best option.)So you can potentially do anything from just the adapter board nearby (without, or preferably with, a ground linking the connector shields together), to a full shielded flex cable.Also make sure the tape you get, is EMI tape with some manner of conductive adhesive or something like that. The most common kind of foil tape just has whatever adhesive; if it makes contact, it's by coincidence only.Also, can always goop some solder over the tape, to make a solid connection. Which is nice about copper, unlike aluminum foil which isn't solderable. Obviously, this assumes you don't mind having solder gooped up over your RPi...QuoteSo, a powered speaker? The jack is line level then, not amplified?If it's a linear amp, that's perfectly fine. If it's a class D type, ehh, it might be fine but it may also emit more noise after hacking it up. Or, well, you might not need to hack it much, just adapt the connections.Well, if youaregoing to hack it up -- at least check if it's a shielded/metallized/conductive enclosure, and try to keep shielding similar to what it had. It might have just a ground lead to the speaker frame, or maybe not even anything. Just keep that as it is.QuoteAhh, it runs quite slow, at least 200Hz I guess, so you can afford quite a bit of filtering on it. Like a series 1k resistor and shunt 10nF capacitor. Which should be enough for 1 or 2% minimum duty at 200Hz, not horrible. Wouldn't go much below 1nF I think.Can also swap out the shunt resistor, light output is inverse to its value.Cheers!Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: October 04, 2020, 10:13:30 am
content: Hey Tim! I had to prioritise another part of the project, so I left the PCB for a little while.I had a very wrong idea about how a TVS diode works, I did some reading and I think im getting to the right ballpark now, so thanks! Anyway, to the point, I have added all the relevant TVS diodes, but there are two places where id like confirmation if you dont mind.QuoteSo while a flyback diode effectively just makes its own little loop with the solenoid and the cabling, adding the TVS diode here instead bypasses the switch, so the current continues going from 12V, to solenoid, now through the reverse biased diode, to ground.Say we choose the SMAJ15A, the moment the switch closes, it sees 12V, which instantaneously goes up as charge accumulates on the switch terminal. The TVS diode, being fast, will start conducting the 2A at say 20V (12V of these are contributed by the PSU, and 8 by the solenoid). The current will decay, following the IV chart of the diode, until both the current and voltage are small (say, 1mA at Vbr = 17V)Now as the application isnt the closing of a relay contact, we dont require the current to stop at once, it can persist for a while, so what I am thinking about is adding the TVS diode from ground (mosfet source) to drain, and then a flyback from the drain to 12V. This will allow the TVS to immediately start conducting, lowering the voltage, until the normal diode decides to wake up and close the connection, lowering the voltage further, stopping the TVS diode from conducting, which in my mind could be more reliable, if maybe unneeded. Did I get anything wrong here?The second thing I would like to ask please, is if I can use a TVS diode as a normal diode too. I have a 6 pin programming header for the 32U4, and in many designs they show a normal diode being used, going from ~reset to 5V, this is to stop a voltage spike from activating high voltage programming mode (also that pin does not have ESD protection for this reason). The 5V TVS diode I chose for the IO connections (SMF5V0TR, it has low leakage compared to the SMAJ5A) has a forward voltage of 0.8V, so should I use that, or should I use the same flyback diode as I am planning to use, or maybe add an entirely different part?Thanks again!

author: S. Petrukhin
author_rank: Super Contributor
timestamp: October 04, 2020, 04:00:38 pm
content: I think a protective diode parallel to a transistor is not a good idea. It will work, but it is better if this diode is installed parallel to the load in the immediate vicinity of the load connection point.In the first case, the protective diode will drop the self-induction EMF into the power circuit and you will need another capacitor to eat it. In this case, the currents will walk along the entire path to the transistor. If the protective diode is installed directly near the terminal for connecting the inductive load, it will completely destroy the self-induction wave, without interfering with the circuit to live.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 04, 2020, 04:39:49 pm
content: Quote from: AnasMalas on October 04, 2020, 10:13:30 amRight. TVS, the path isn't any longer, voltage is clamped perfectly, transistor is happy. The clamp diode has to return to +12V through a wire, or needs a bypass cap to close the loop nearby.The solenoid has much more inductance than the wiring, it's certainly true that the clamp diode will clamp a vast majority of loop inductance. But we're not concerned about fractions, we're concerned about absolute value: the transistor has some current flow, turn-off rate, and maximum voltage: three quantities that define a maximum safe inductance.If the fraction of loop inductance in the wiring is greater than the maximum safe inductance, the transistor will avalanche, and eventually fail.(Or again, the protected switch can be used, which behaves reliably as a TVS.)QuoteErm, opens? When the switch closes, the voltage is pulled down to GND and nothing interesting happens.Yes, that's how the solenoid will discharge. The voltage jumps up to the maximum, whatever that is under the condition (in this case, 2A load current), and will fall slightly as current decays (17-20V is pretty plausible for a TVS, yeah).When current goes to zero, the voltage just hovers in place -- there's no current to charge the node capacitance (transistor C_oss, diode C_J, and whatever the coil and wiring contribute) back to the idle 12V level. So the inductance actually discharges "too far", current dips slightly negative and the voltage swings down towards 12V. But it swings too far because now there's some current stored in the inductor. And so on and so forth: in short, it's just ordinary ringdown and it's a high impedance, nothing to worry about.QuoteThere's no point in using both; the clamp diode is strictly worse, in many respects. It's just a handy expedient when suitable. (And a few exceptional cases where it is better, or both are needed.)For example, if you already have 12V on this board, with a bypass cap, then a clamp diode to that can have a short enough loop that the transistor is happy. You can save, a few cents I suppose, omitting the TVS.Exceptional cases would be like that really-big-solenoid thread, where the energy of the solenoid itself would destroy most TVSs, and either a big stack of them is necessary (or MOVs, which can handle more energy, at the expense of looser Vbr tolerance), or a clamp diode is necessary to let that energy decay through the solenoid's own resistance (which clearly it is capable of dissipating). But the current is high enough that wiring inductance is destructive, so a TVS is necessary as well.QuoteSure, a unidirectional TVS is just a zener diode, same modest Vf (0.6V or so) as a rectifier that size, but with a nominal Vr.Obviously, it can also be used from GND to RST, or from RST to +5V. Again, the clamp is strictly worse, but you ought to have bypass on that supply, so it might not be worse enough to matter.And again, you can keep reusing that USB TVS, which has clamp diodes and a common 5V TVS on the power pin. It was the two-in-one version, wasn't it? Not really a whole lot of economy reusing that one, but you can get quads the same size, and just route USB straight through pairs of channels the same way.Also, I'd prefer clamp diodes (with nearby bypass!) to TVSs for IOs, because the clamping voltage is referenced to +5V, same as the MCU's input clamp diodes. When the circuit is unpowered for example, TVSs won't do very much, the internal clamp diodes will clamp it to the discharged +5V instead -- still stressing the chip. And at a time when it should otherwise be quite safe, in transport, or during assembly.But there are still other options. If you can afford a resistor (>= 10 ohms say) between outside terminal and MCU pin, and the outside terminal is TVS'd, that resistance limits the current flow between (TVS clamping voltage) and internal clamp diode. And this is true whether it's powered or not. The resistor doesn't prevent current flow in the internal clamp diode, but it helps limit it.There are several good ways to do it. Just make sure you don't pick one of the many bad ways to do it...Quote from: S. Petrukhin on October 04, 2020, 04:00:38 pmThe TVS is strictly better. The clamp diode cannot clamp stray inductance between the transistor, diode and supply wiring. (Is this the "power circuit self-induction" you are referring to?) If a bypass capacitor is provided, the loop is between transistor, clamp diode and capacitor, but this loop is still larger than the loop between transistor and TVS.Again, dI/dt and Vmax define a limiting inductance value. As long as the loop has less than this limiting value, it's fine either way.When I say "strictly better", I mean it may not bemuchbetter, just that, by strict measure, it is not equal, or worse. It might be farther inside the limiting value, but if both cases are within limits, it doesn't matter.Tim

author: David Hess
author_rank: Super Contributor
timestamp: October 06, 2020, 09:25:10 pm
content: Quote from: T3sl4co1l on October 04, 2020, 04:39:49 pmIn theory like avalanche rectifiers and avalanche rated transistors, TVSes are processed such that their junction breaks down uniformly preventing hot spots which can cause a zener diode to eventually fail when used in surge applications. I did some military design work where this came up and they were very specific about not using zener diodes for surge suppression.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 06, 2020, 10:34:50 pm
content: There's an ON Semi (nee Motorola) appnote which seems to approve such use (zeners in pulsed duty). And probably other manufacturers, that's just what comes to mind. I wonder if that was more a matter of mil spec prudence, mfg-specific specsmanship, or what.Tim

author: David Hess
author_rank: Super Contributor
timestamp: October 08, 2020, 03:01:52 am
content: Quote from: T3sl4co1l on October 06, 2020, 10:34:50 pmI have that application note sitting right here in front of me and I think it is old enough that they did not understand it as a problem yet, and it is not a problem if the maximum surge current is specified correctly. For the same power rating, a junction processed for avalanche capability can handle a much higher peak current.

author: AnasMalas
author_rank: Regular Contributor
timestamp: October 12, 2020, 09:26:09 am
content: Alright. I honestly started feeling burnt out so I took a mini 2-day vacation. Tim and the others, forgive me, upon re-reading the entire thread in detail and analyzing it, I realize that I may have made this longer than necessary... To the best of my ability I have tried to compress the following.Ok, so to answer the original question in the title:Quote from: David Hess on September 20, 2020, 09:43:08 pmQuote from: T3sl4co1l on September 22, 2020, 04:12:07 amQuote from: T3sl4co1l on October 04, 2020, 04:39:49 pmThe decoupling capacitor decouples the 12V power line going to the load. Now, do we decouple the entire 1 meter wire going to the solenoid, or do we reduce the loop area by placing the capacitor at the solenoid terminals? My thinking is as the wires are bundled, perhaps i'll also twist them, so there isn't any real loop area contributed by the wires. So the capacitor will be placed on the 12V line at the connector. Done ✅Now, this capacitor should be high ESR, but how do I generally determine its value? I have a 100μ electrolytic to filter the fans (ill come back to this). Should I just place one of these there (does the value even matter beyond inrush?)Quote from: T3sl4co1l on September 22, 2020, 04:12:07 amAs we moved from a flyback diode to a TVS diode bypassing the switch, I assume this is no longer valid, but what were we trying to accomplish here? from ground to 12V, the solenoid wont increase the voltage, and it wont get zapped by ESD, so why would we care? From output to 12V, it would act as a flyback diode.Quote from: T3sl4co1l on September 23, 2020, 05:09:50 pmNow I have a 5V 120mm fan which I noticed distorted the 5V rail when turned on in a small test, I don't have any inductor or ferrite beads, so I tried capacitors. With a 500μF capacitor the noise completely went away. I couldnt figure out which ferrite to use for an LC filter, so im thinking about just using the 100μ capacitor and hoping for the best. I dont think we care that much about the 12V rail, as it only powers the fans, the lock, and the CC LED drivers. The frequency is quite low anyway, 100Hz dipsNow when filtering the 25 kHz PWM signal, are we trying to filter out high frequencies or should I add a bandpass filter? same for the 100 Hz tachometer output (which I can instead slow down by a series resistor to the open collector, and a weak pullup)?To round it all off,Quote from: T3sl4co1l on October 04, 2020, 04:39:49 pmTIM, WHAT HAVE YOU DONEOk the stuff I said about understanding TVS better, yeah thats gone with the whole clamping diode thing lolThere are multiple places where I have two 5V signals right next to each other, where im going to use the USB chip (USBLC6, it doesnt require differential signals, does it? I couldnt find any reference to using it for non USB/Ethernet applications). Now where I needed the single 5V and 12V TVS diodes, we either have power rails (to protect chips down the line VCC pins), or we have a signal line terminated with a 500 ohm resistor (to protect the microcontroller from overcurrent). Should I just go ahead, or should I add clamping diodes to the power rails too (I though TVS worked as clamping diodes for surges)?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 12, 2020, 10:59:46 am
content: Quote from: AnasMalas on October 12, 2020, 09:26:09 amAt the connector, because doing it "out there" would put add the wire to the loop.Note that twisted pair still has an internal loop area. Less of that area (ideally none, because it all cancels out) is in common with the outside world, but it's still there.QuoteWell, modest ESR, not like memory backup capacitors (kohms ESR!). But a regular electrolytic will do.QuoteWait, what all was on 12V anymore? Just solenoids? Yeah, not a problem. For something like a regulator running off it, might want one. Fans, kinda either way I guess.QuoteAh, yeah fans tend to draw pulsating current, so a big cap can come in handy. Not so much a filtering thing as a current demand thing, but when your regulator can't keep up, the filtering of course helps as you've seen. Ferrites won't do anything about that, it's much too low in frequency.QuoteJust a little, like uh, 1k + 470pF still gives a reasonably square signal, but filters out any RF trash that might be coming in.Bandpass would be the wrong thing, you need DC to keep either the square PWM waveform, or its average level. (Except some special cases, like you can generate AM radio that way, but that's something else.)QuoteNice thing is a single supply TVS can cover for many clamp diodes. Which is how the USBLC6 is wired internally, it's a TVS as well as clamp diodes. Or if you're using multiple of them, yeah, you'll end up with distributed TVSs, even better (and I wouldn't worry about like a SMAJ5.0A in that case). So clamp diodes are pretty attractive when you have a supply handy.You can't add clamping diodes to a power rail, what would they clamp into..?Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: October 14, 2020, 10:18:16 am
content: Quote from: T3sl4co1l on September 22, 2020, 04:12:07 amQuote from: T3sl4co1l on September 23, 2020, 05:09:50 pmQuote from: T3sl4co1l on October 12, 2020, 10:59:46 amQuote from: T3sl4co1l on October 12, 2020, 10:59:46 amOh Tim, sometimes I can't help making myself look stupid on the internet. I mean, at this point I might beactuallystupid instead of just looking stupidThe concept of clamp diodes for IO pins completely escaped me, I honestly thought the USB chip had those diodes to "be cheaper" than having 3 TVS diodes. D'oh!I think I get it now. If we have a high voltage, it will be clamped to Vcc, saving the IO pin. The TVS on Vcc will then shunt the extra voltage to ground. If we get a negative voltage, now ground is at a higher potential and the bottom clamp activates (believe me I tried looking it up, but I was looking for the wrong thing). Oh man, Tim you are a saint for putting up with me, Thanks!Based on everything, I believe the following circuit is complete now.Quote from: AnasMalas on October 12, 2020, 09:26:09 amESD for the whole circuit. Thats what we are trying to accomplish, dumbo!

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 14, 2020, 02:58:40 pm
content: We're talking about lots of bits and pieces, and it can take some time before they all fall into place. Cheers.Yes, that looks good. I think I would change... R31-32 to more like 1k, say? And optionally move R28 to the right, but as long as its value is much larger than R31+R32 it doesn't really matter. Then C16, that's an awfully big value, do you really need debounce that long (~1s)? 0.1u would be plenty (contact bounce is usually on the order of 1-10ms), and you can always filter it further in digital. The analog filter only needs to filter it down to something you can easily handle in software.Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: October 16, 2020, 01:15:24 pm
content: I may or may not have just copied the circuit provided by digikey, lolhttps://www.digikey.com/en/articles/protecting-inputs-in-digital-electronicsAlright, lets do this the right way. The switch (Alps SPPB2A0100) requires 50 μA minimum, and there will be two in parallel. Thus a max resistance 50k to Vcc. The 32U4 needs to see below 0.9 V to register 0, and so I edited the circuit. When the switch is open, the micro sees 5V. When closed, it sees 0.45V. Rise time from 0.45V to 5V is 15.1ms, fall time from 5V to 0.45V is 6.1ms. Seems like its fine, and as you said we can always do software debounce or swap a resistor/capacitor.As for the other parts of the circuit, this is the ESD protection circuit I have made. All these components are at the connector, and then they go straight to the micro (I might add filtering tomorrow)One IO pin alone, BAT54S:Two IO pins, USBLC6:One thing though, wouldnt we want the resistors to be before the ESD device, to protect it? because im considering moving the 22 ohm USB resistors to before the USBLC6, even though all the other schematics show the resistors between the micro and the USBLC6. Should I instead keep it, and move the 500 ohm resistors in the photos to after?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 16, 2020, 06:14:43 pm
content: Quote from: AnasMalas on October 16, 2020, 01:15:24 pmSure about that? 10k into 5.1k is closer to 1.7V...Easy enough to move the pullup towards the switch, that way the rest is just filtering, no effect on DC levels.The capacitor should probably be on the other side of the series resistor, too; that way it doesn't dump into the switch every time. Still plenty of wiping current from it.Quote- Also, since you have two BAT54S across these, could use one more USBLC6?QuoteRight, you want the resistor by the MCU, so it limits whatever current is left over.Resistance on the connector side, depends on threat model. If you're concerned about accidental cross-wiring, then over/under voltage on a pin might be a concern, and preferably you should have two resistors, one to handle each factor (MCU and connector).Note that a connector-side resistor doesn't do much to limit ESD current: one, ESD is already a high impedance so a modest resistance doesn't do much, and two, any substantial resistance will just arc over from so much voltage drop, in which case you get the full brunt of the surge anyway. So the MCU-side resistor is still handy.Also, for stuff like I2C, you might find it wise to use a lower series resistance (100-200 ohms?), or a ferrite bead, to reduce DC voltage drop.Yeah, these look good, just minor things here and there -- got a full schematic together yet?Tim

author: AnasMalas
author_rank: Regular Contributor
timestamp: October 17, 2020, 05:25:45 am
content: Quote from: T3sl4co1l on October 16, 2020, 06:14:43 pmI see where the confusion is, Tim. AjarSwitch goes to the microcontroller, go back to the below if you want to see a whole photo. Do you have any tips on making it more clear, is the below image better?Quote from: AnasMalas on October 14, 2020, 10:18:16 amQuoteMakes sense! And then also, we can eliminate the 1k resistance in front of the BAT54S, and use the RC resistor for both. Now the system is directly at GND when the switch is closed, and on Vcc when open. Risetime is 15.1 ms, falltime is 5.1 ms.QuoteOk. All the 500 ohm resistors have been moved to the MCUQuoteIm trying to reduce unique BOM items, just as a learning exercise. The "pedant" I2C ADC board im using has 10k pullups, and so with 500 ohms you get 0.24 V as 0 when the 32U4 pulls the line low. I referenced this photo, from the NXP's I2C specification and user manual Rev. 6. it says that the maximum series resistor if a 10k pullup is used on a 5V system equals 1.5k. I can still just put two 500 ohm ones in parallel if you still see a reason toQuoteYeah at that point I have done all I can do. I choose the much more expensive pluggable terminals just so no one has to rewire everything if they need to disconnect the board. If they want to tinker with removing the wires from the connectors, they better do it right (ill attach an extensive-ish manual on the inside of the enclosure with everything one would need)QuoteOh, ive had a very incomplete one for a while, I didnt think youd be interested. Sure! Ill clean up all the comments I left for myself, complete a couple of circuits, and post it in an hour or twoEdit:QuoteI went to mouser to check quickly, I was about to just replace all the BAT54S chips with USBLC6 and bunch up the unrelated single IO connections into pairs, but apparently one USBLC6 at 10 qty costs $0.364, while the BAT54S is 3 times cheaper at $0.12 (the price difference is even more drastic at 3000 qty, $0.145 vs $0.023) So I dont see a reason to do this, especially that it would make the design slightly more complicated, and id still need that decoupling capacitor so I wouldn't even save on component count.Only reason I can think about is if we want that TVS diode from ground to VCC at all the connectors individually, which I dont think we do, right?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 17, 2020, 06:17:10 am
content: Quote from: AnasMalas on October 17, 2020, 05:25:45 amYeah, not a problem with the total pullups as is. And you can always reduce pullups (with the DNPs shown) if needed for noise immunity or speed.QuoteNiceQuoteThis is a one-off, right? You've spent orders of magnitude more just discussing it, let alone designing and building it... economics are very different, this far from production.Also, typical assembly cost might be ballpark $0.10/part, making the BAT54S not as attractive in comparison, plus it's a new BOM item. Or even more if you're doing it by hand (assuming labor isn't discounted to zero, and come on, you deserve better than that).Incidentally, BAT54S is probably fine on USB, up to Full Speed. So you could probably go the other way, if cost were a huge priority...Also consider resistor packs: a 1206 quad costs about as much to purchase and assemble as a single! Don't go crazy, you still want to be able to place specific values in most places, of course. Stuff like pullups and series limiting, it's not a bad idea.Probably not very interesting on such a small project, but when you get into the hundreds of components, it can be a convenient savings.Tim