Critique my LED PWMer - Page 1
Forum section: electronics / projects

author: robzy
author_rank: Regular Contributor
timestamp: October 17, 2021, 08:52:59 am
content: So I have a few LEDs that I'll be running at 1-amp so that they meet their characterised spec (i.e. wavelength of light) but I want to run them at low brightness/power.So I've come up with the following schematic which I think will achieve that. Every 6.66 milliseconds (i.e. 150Hz) it will turn the LED on for anywhere between 1 microsecond and 256 microseconds.I expect there might be some slight inaccuracies ~10% at low brightness, like for the 1 or 2 microseconds pulses, because of the turn-on time of the MOSFETs and LEDs, but I can live with that.What do you think? Have I done anything bone-headed?Links to semiconductor datasheets:MCP1404:https://ww1.microchip.com/downloads/en/devicedoc/22022b.pdfSSM3K345R:https://toshiba.semicon-storage.com/info/docget.jsp?did=55842&prodName=SSM3K345R

author: moffy
author_rank: Super Contributor
timestamp: October 17, 2021, 10:06:58 am
content: Your circuit is pretty straight forward, not much to go wrong. I assume you chose the resistors to match the different voltage drops of the LEDs, and 150Hz should be above noticeable flicker. Is it wise to use the Tx pin? Is that used for serial coms? Might want to keep that free if it is.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 17, 2021, 10:27:39 am
content: I'm only a hobbyist, so I cannot say anything about your circuit, really. The reason I'll annoy you with my opinion, is that I've got a couple of DIY LED lights (a floor-standing reading light) I'd like to dim, preferably down close to zero output if desired, but have it be silent (since I like quiet when reading; any buzzing annoys me), so perhaps my real-world observations may help. If not, feel free to ignore!For a stroboscopic effect, 150 Hz is in my opinion borderline, possibly problematic. When tired, I can definitely perceive the 100 Hz flicker from fluorescent lights, and it is not only annoying but occasionally causes headaches. Although the frequency is higher, the relatively large dead time between pulses may make it more observable. Furthermore, the switching frequency most likely yields audible noise.(I do understand that my preferred solution, something likeTPS61169which LCSC hasTPS61169DCKR(SC-70-5) in stock for under $1 USD apiece as of 2021-10-17, will probably not work for you, since your duty cycle varies from 0.015% to 3.88%, and these typically don't go that low; I think TPS61169 practical minimum is something around 1-2%.)

author: NiHaoMike
author_rank: Super Contributor
timestamp: October 17, 2021, 02:32:54 pm
content: 150Hz probably won't cause a visible flicker, but there's really no reason to not use a few kHz or more instead. Add 10 ohm or so resistors in series with the MOSFET gates to prevent ringing. Add 10k pulldowns on the MOSFET driver inputs to prevent spurious operation during boot. The decoupling capacitor seems quite small so make a provision to fit a bigger one instead.If you're making a PCB, add (spots for) extra channels on each PWM capable pin if space allows even if you have no immediate plan to use them. Break out all other remaining pins to test points. You might want to think about provisions for improvements like a spot for a light sensor and different options for the power input connector. Remember that you pay for board area and not the "complexity" of the board given the same number of layers.

author: StillTrying
author_rank: Super Contributor
timestamp: October 17, 2021, 04:22:31 pm
content: Quote from: robzy on October 17, 2021, 08:52:59 amIf it's for illumination all of those short on times at 150 Hz would be very visible and annoying, - to me.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 17, 2021, 04:22:40 pm
content: 150Hz causes almost definitely disastrously noticeable flicker, unless you only use low intensity LEDs at high duty cycles so that it doesn't matter. I don't understand how this is so difficult year after year. It's discussed dozens of times on this forum, yet all the otherwise very intelligent frequent contributors get this wrong time after time.For anything running at low duty cycles or high intensity LEDs (schematic does say "1 amp LED"), go for 1kHz bare minimum. If you don't want to hurt tooki's eyes, go for 2kHz bare minimum.And at least 12-bit PWM resolution is highly recommended.

author: NiHaoMike
author_rank: Super Contributor
timestamp: October 17, 2021, 05:46:06 pm
content: A lot of modern LCD monitors pulse at 120Hz to reduce motion blur. If 120Hz flicker really is that noticeable to most users, that feature won't sell very well. (Where that typically becomes insufficient is in 3D mode where the glasses split that to 60Hz, a big reason why 3D TV failed.)In this case, the hardware can easily go well into 10s of kHz before switching losses even start to become significant (and the upper practical frequency is likely into the hundreds of kHz), thus the frequency is a software selection that plays almost no part in the hardware design.One other thing is that by adding provision for resistors in series with the MOSFET source and a NPN transistor pulling down the gate when the voltage across that resistor gets to about 0.65V, you can make it a constant current driver. You'll also have to raise the gate resistor to 100 ohms or above to not get excessive current from the gate driver and consider the dissipation in the MOSFET which would then be operating in linear mode.

author: magic
author_rank: Super Contributor
timestamp: October 17, 2021, 05:52:04 pm
content: They don't pulse at 120Hz, they refresh at 120Hz. I'm sure their backlight PWM runs at many kHz.I found that several hundred Hz is the minimum not to see flicker even when the light source (or something illuminated by it) moves fast in the corner vision, which is where the strobe effect becomes worst.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 17, 2021, 06:42:33 pm
content: Quote from: NiHaoMike on October 17, 2021, 05:46:06 pm... at high duty cycle, not 5% for example.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 17, 2021, 06:47:56 pm
content: Quote from: magic on October 17, 2021, 05:52:04 pmThey do have this "flicker mode". The point is, as explained above by NiHaoMike, to reduce motion blur. If you just "update" at 120Hz but have continuous backlight, your eyes kind of integrate the image continuously, making the two adjacent frames "blur" together. Which isn't necessarily a bad thing. But some prefer to see crisper, sharper images during motion, in that case the answer is to add flicker deliberately by showing the image... then show some black screen... then show the next image. So blink the backlight in sync with the updates. Like the good old CRT TV did, or the good old cinema film projector did. (The film projector did show the same image twice or three times, though, causing interesting effects.)So the mentioned mode simulates old tech and adds flicker deliberately. The flicker has to be at the same frequency as the update rate, but they can still adjust the flickeriness (is that a word) by adjustingduty cycle. Go too low, and it's too flickery for most users.

author: magic
author_rank: Super Contributor
timestamp: October 17, 2021, 07:06:06 pm
content: Okay, I didn't realize it's a thing. Guess I'm not enough of a gamer

author: rstofer
author_rank: Super Contributor
timestamp: October 17, 2021, 09:49:57 pm
content: QuoteSo, the LED is only going to be on for a very small percentage of the time. It looks like about 3.8% of the time, maximum. Hm...You should breadboard this thing before getting too invested.

author: robzy
author_rank: Regular Contributor
timestamp: October 18, 2021, 03:16:16 am
content: Thanks all for your input! I hear what you're saying about the 150Hz PWM rate. I would've preferred 1kHz+, but there's a reality face when you want to scale down the 1A current to 1mA.At the end of the day the PWM module is very configurable, and I can change the current resistors, so I have a lot of freedom to experiment and fine-tune when its built. Right now I'm mostly focusing on the topology.Two questions have occured to me as I've been choosing parts on DigiKey:1) Doing 1-amp of current for 256uS of every 6666uS period. This will be an average of 1A*256/6666=38mA, but what will my USB port see? I've loaded the LEDs up with 100uF of capacitance to smooth the load on the USB port, but is that enough? I've done some Google and can't find much in the way of calculating the waveform of power that will be drawn from the USB port.2) Turns out that the gate driver IC datasheet requests a 1uF film decoupling capacitor. These are bigger than I want on my PCB. How can I determine the impact of choosing a lower value? I'm aware that the goal is to as-quickly-as-possible push charge into the MOSTFET gate to turn it on, but 1uF seems like an over-abudance of capacity.

author: magic
author_rank: Super Contributor
timestamp: October 18, 2021, 06:02:09 am
content: Quote from: robzy on October 18, 2021, 03:16:16 amMOSFETs switch in a fraction of a microsecond.Quote from: robzy on October 18, 2021, 03:16:16 amIs it some very old driver? Why not MLCC? Still low ESR, even less ESL, very small.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 18, 2021, 08:11:29 am
content: 1uF MLCC for the gate driver comes in 0402 or 0603 package, not a problem.You can easily switch the MOSFETs in 50ns, but can choose to use 100ns or so to reduce EMI a bit. Even then, 0.2µs total spent in switching is still small compared to planned minimum on-time of 1µs. It starts to show some minor non-linearity, though. Flicker will be the real problem at such low duty cycle. You may want to up the freq even if that means that your minimum on-time is even lower and the low side control steps will be even more non-linear. You want to test that out in practice. At very low duty cycles, a large part of conduction period will be partially conducting i.e. switching loss but this doesn't need to be a problem. It does kill the efficiency, but only when measured as a percentage of that already very low average current, usually this doesn't matter. (In practice, what I mean is current consumption goes down and down as you dim the LEDs, but at the few lowest steps, LED brightness goes downfasterthan the current consumption does.)150Hz frequency also has the problem of requiring significantly more bypass capacitance not to make the USB port see the 1A peak current.In worst case, capacitors alone might not do it, an LC filter would help with the ripple current the USB port sees, but likely you don't need to go that far. It's all about optimizing size and cost.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 18, 2021, 08:18:22 am
content: To get a more exact idea of the waveform the USB port sees, I suggest you simulate this in Spice, approximating the USB cable and connector resistance and inductance, ESR of the capacitors, and so on.For example, draw a 5V voltage source with 0.1ohm series resistor and 100nH series inductor, then your 100uF electrolytic capacitor with ESR set to say 5 ohms, and then the 1A current source running PWL value list going between 0 and 1A with some 100ns rise/fall times.The answer likely is to add MLCCs because the ESR of the elcap is too high compared to the ESR of the USB port. Then if you remove the electrolytic cap, you could see how the very low ESR MLCCs make the thing oscillate, at least during power-up transient. So you add the elcap back in parallel with the MLCCs and be happy with it.But try to simulate this, it'll be interesting and LTSpice is free to download.

author: robzy
author_rank: Regular Contributor
timestamp: October 18, 2021, 11:43:57 am
content: Thanks for the nods-of-approval for the 1uF MLCC, I'll switch to those. I'll also throw some across the LED's 100uF tantulum caps.Quote from: Siwastaja on October 18, 2021, 08:11:29 amYep. That's my thinking on the matter as well. The non-linearity is material and it sucks, but the good news is that it seems like there's a delay in both MOSFET turn-on *and* turn-off, which will cancel out some of the non-linearity. At the end of the day I just want to get it built and start testing. Firmware is flexible and LED current resistors can be changed.Quote from: Siwastaja on October 18, 2021, 08:18:22 amIts disappointing that it's not possible to calculate this analytically. To my naive mind the 100uF capacitor I'm using will simply form a low-pass LC filter. It's just not the usual "filtering a voltage source", instead it "filters a current sink".Anyway, I've decided that I'll just use a USB powerbank which can comfortable handle 1A. And really, most USB ports (especially USB3) shouldn't struggle with this load.

author: tooki
author_rank: Super Contributor
timestamp: October 18, 2021, 01:19:28 pm
content: Quote from: NiHaoMike on October 17, 2021, 05:46:06 pmThe flicker of an image and the flicker of an LED are different things. The only things in motion on a screen are things within the image.When LEDs are used for lighting and indication, the user is often moving, or the LED may be in motion. These cause very different issues.People REALLY need to learn that the frequencies for frame rates and the ones for PWM are in no way comparable.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 18, 2021, 03:41:47 pm
content: Quote from: robzy on October 18, 2021, 11:43:57 amAcross the LEDs? I hope that's a typo.Tantalum is a bit iffy, but USB is kinda current limited with some source resistance usually there limiting inrush so it's not a huge issue. Still, remember to derate voltage, 10V or 16V part is needed for 5V bus, and look up the inrush current specification and max ripple current from the datasheet.USB spec limits allowable bus capacitance (to limit inrush duration), if I recall correctly that's some 47µF, so you need to add a precharge circuit to be able to use more. It's getting some sort of PITA.If you don't have precharge, you can't have much capacitance, and if you don't have much capacitance, the USB sees all those 1A peaks, in which case you would need to enumerate and ask for more current, or hope everything's OK.Quote from: Siwastaja on October 18, 2021, 08:11:29 amOf course you can, but the equations get really complex when you include "everything", including cable ESR, ESL, capacitor C, ESR, ESL, and possibly C, ESR and ESL of another set of (different type of) capacitors. Spice handles coming up with all the equations and solving them for you. Tools are there to help.

author: magic
author_rank: Super Contributor
timestamp: October 18, 2021, 04:51:52 pm
content: Quote from: robzy on October 18, 2021, 11:43:57 amDelay times are determined by the amount of charge that needs to be moved before reaching the Miller plateau.The actual switching is an approximately linear ramp determined by Miller capacitance and drive current (i.e. by voltage and resistance).You can probably get it quite symmetric by driving with a voltage roughly 2x the Miller plateau voltage (3.3V may do).

author: robzy
author_rank: Regular Contributor
timestamp: October 19, 2021, 03:55:52 am
content: Quote from: Siwastaja on October 18, 2021, 03:41:47 pm"Across the capacitor belonging to the LEDs"The ownership apostrophe in LED's was important.Quote from: Siwastaja on October 18, 2021, 03:41:47 pmThanks for the reminder. Did you mean that the capacitor datahseet will have an inrush current specification and max ripple current?Quote from: Siwastaja on October 18, 2021, 03:41:47 pmOh! So it does! It looks like its actually 10uF. Eeep. I'm putting 300uF on the bus.Quote from: Siwastaja on October 18, 2021, 03:41:47 pmYeah, I'm reading a TI application report on this now (SLVA670A). It would be nice if there was a single IC that would handle all this for me. I'll do some Googling.I wonder why I can't just put a charge resistor between Vusb and my capacitors? And have the ESP32 monitor the voltage on the caps, and when the voltage hits 5v the ESP32 will turn on a MOSFET that bypasses the charge resistor? That feels promising!With a 12.5ohm resistor it should take less than 50milliseconds for the capacitors to reach 4.99v on turnon.Quote from: Siwastaja on October 18, 2021, 03:41:47 pmI don't want to include "everything", just the equivalent of the simple RC filters that students learn in college EE.

author: ejeffrey
author_rank: Super Contributor
timestamp: October 19, 2021, 04:17:41 am
content: Quote from: robzy on October 18, 2021, 11:43:57 amWhy is the non-linearity important or a problem? What is the application? The proposal (max duty cycle <5%) doesn't seem to make a lot of sense for general purpose illumination or display purposes. Non-linearity in the drive circuit wouldn't usually be important for those applications because visual perception is more non-linear. If you are doing something completely different, then the advice above is potentially not applicable.

author: robzy
author_rank: Regular Contributor
timestamp: October 20, 2021, 05:23:06 am
content: Linearly is important because I want to now how much power the LEDs are putting out. If the MOSFET's materially eat into the 1uS pulses, then it will be a pain to figure out the true output from the LEDs at 1uS.I've come up with my precharge delay circuit. It's not as simple as I was expecting it to be. I did some Googling but couldn't come up with a simpler answer. Any suggestions?The ESP32 will monitor VMEAS and enable the MOSFETs to short the resistor when the caps have charged to a high enough voltage.

author: magic
author_rank: Super Contributor
timestamp: October 20, 2021, 05:59:25 am
content: Do you realize what will happen if Vin catches some ESD while the fuse is blown?

author: robzy
author_rank: Regular Contributor
timestamp: October 20, 2021, 06:04:24 am
content: Quote from: magic on October 20, 2021, 05:59:25 amAre you suggesting that it will blow Q8? I thought that the 10k R9 would save the Q8 from ESD etc....Did I mis-identify the problem? Or is my solution not right?

author: magic
author_rank: Super Contributor
timestamp: October 20, 2021, 06:35:35 am
content: Quite the opposite: R9 provides path for ESD to reach Q8 gate when Q7 is off and break down the gate insulation. Such resistor should be connected straight to the source.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 20, 2021, 09:53:14 am
content: Seeing you seem to worry about the inaccuracy in LED current due to nonlinearity of PWM, do you realize LED Vf varies all over the place with temperature etc., and your 5V supply varies, too, so you never get regulated, accurate current with simple series resistor driver anyway. If you need accurate LED current, you need to measure it and feedback. If you need accurate output, you need to sense the light and feedback on that.

author: robzy
author_rank: Regular Contributor
timestamp: October 20, 2021, 11:44:28 am
content: Quote from: magic on October 20, 2021, 06:35:35 amOh! That's a good point! I was aware that ESD on the gate was an issue, it didn't really click with me that ESD's impact on Vgs could be an issue. In this case my chosen MOSFETs have inbuilt zener(?) diodes between gate and source, would that've saved them?Either way I'll modify my design to put the fuse before the current limiting circuitry.Quote from: Siwastaja on October 20, 2021, 09:53:14 amTo clarify my previous point - I don't need accurate LED current, but I want to know the relative change in power from nominal 1uS pulses to 2uS pulses. And its easiest to do this if the actual pulse length is close to the nominal pulse length (i.e. not eaten up by MOSFET switching time).

author: StillTrying
author_rank: Super Contributor
timestamp: October 20, 2021, 01:40:11 pm
content: Quote from: robzy on October 20, 2021, 11:44:28 amWhy don't you view the 1 & 2uslightpulses with a photodiode, a couple of us have done it here.https://www.eevblog.com/forum/chat/20w-halogen-bulb-viewed-by-a-photodiode/msg2411274/#msg2411274With 1A through the LED you wouldn't need any photodiode amp.

author: robzy
author_rank: Regular Contributor
timestamp: October 20, 2021, 11:35:19 pm
content: Quote from: StillTrying on October 20, 2021, 01:40:11 pmOh that's cool! Thanks for the link!I don't have any measurement equiptment with the required bandwidth, though, and even if I did I'd still like to invest engineering effort up-front to make sure the circuit switches fast enough that 1uS pulses are approx half the length of 2uS pulses.