0

Follow-up to: Is it okay to use a MOSFET in its resistive region with a heat sink?

I plan to use two PWMs to very slowly (exponentially) turn on an LED strip, from 0.002% to 0.004%... to 100% power over twenty minutes. 0.002% seems to be a safe brightness that doesn't seem jarring when suddenly turned on, but I can't push much higher than that. The formula I chose (for its very slow start) is: power=(2^(t*15)-1) / 2^15 where t is the normalized time, from 0 to 1. I don't care about the number of steps, so long as none is perceptually large. (So 97%→100% is fine because it's unnoticeable, but 0.002%→0.5% would be quite jarring.) 255 steps would be a great plenty if I could take a step every few seconds, but if the steps represent linear brightness increments, I need more like 51000 steps.

Both PWMs are 8-bits. The high power part PWM1 will take over when the low power part PWM2 reaches a certain level. In fact, the "low power" part of the circuit could drive the light from 0 to 100%, but that half of the circuit (left) is analog, and I can't easily model the brightness. Hence, at the level where I no longer need extremely small gradations, I'll switch over to driving the light with PWM1, which is mathematically nice but incapable of the extremely low power needed for the early steps.

Is this a reasonable circuit to drive a transistor Q2 with both a PWM signal (PWM1) and an analog voltage (after a low-pass filter from PWM2), but not at the same time?

circuit to add digital from PWM1 with analog from PWM2

Note: I will probably not be combining PWM1 and PWM2 dynamically in a "most significant digit / least significant digit" configuration, because the voltage->brightness response from PWM2 is way too nonlinear.

Potential problem:

The low-pass filter may not respond fast enough, so when PWM1 starts sending its signal and PWM2 turns off, the low pass filter may not step down fast enough to avoid a flash. (The flash would occur if the low-pass filter remains on during the early OFF portions of PWM1's signal.) This would manifest in a brief doubling in brightness.

Potential solution: maybe with a diode, capacitor, and a couple resistors, I can hold the base voltage of Q1 high when PWM1 becomes active, even during the off-portion the signal.

piojo
  • 745
  • 1
  • 6
  • 13
  • 1
    Do you *really* need that resolution? – Harry Svensson Feb 24 '18 at 13:55
  • 1
    @HarrySvensson At the lowest levels, I absolutely do, and more resolution would be even better. At the brighter levels, resolution becomes almost unimportant. If you try sleeping when a bright light suddenly turns on at 1/255 power, you'll find how serious this is. – piojo Feb 24 '18 at 13:56
  • I have run into similar problems with PWMing LEDs, and I think you'd be better off finding a PWM source that is capable of 16 bit resolution. – Dampmaskin Feb 24 '18 at 14:45
  • THe problem is you want a logarithmic ramp not a linear ...to exponential. Resolution required depends on how many dB step and smallest step size. – Tony Stewart EE75 Feb 24 '18 at 14:45
  • 1
    Look into linear-voltage-to-exponential-current converter circuits. They're common in audio synthesis applications, but might apply well here. – Russell Borogove Feb 24 '18 at 15:25
  • Simple anti-log will work – Tony Stewart EE75 Feb 24 '18 at 15:28
  • @TonyStewart.EEsince'75 Thanks, I didn't know anti-log amplifiers were a thing! Still, I'd appreciate it if someone could tell me whether the circuit I posted looks right. – piojo Feb 24 '18 at 16:31
  • Yes u-law and A-law telephony codecs are log to get > 80dB range from 8 bits. So I suggest using 1N4148 diodes and current mirror from Op Amp to convert linear V input into anti-log I output. look around rather than what you have. – Tony Stewart EE75 Feb 24 '18 at 17:50
  • How much current does your LED strip draw at full brightness? – Bruce Abbott Feb 24 '18 at 21:21
  • @BruceAbbott It'll draw 1.15 A at full power. If I take Tony's suggestion, will that be too much for most op amps (considering they will need to dissipate power for currents less than the max current)? – piojo Feb 25 '18 at 02:52
  • @TonyStewart.EEsince'75 I thought you were saying I should anti-log amplify the voltage, then use a resistor to convert to current, and a current mirror to supply the necessary current to the LED. But that wouldn't use the diodes you mentioned (and would waste 14 watts). Can you clarify? – piojo Feb 25 '18 at 11:07
  • What LED voltage,current do you need? Also what is Vcc and Vin(max)? Then I will show a suitable driver with transistor(s) and OpAmp. Anti-log driver with log eye response gives a linear brightness when more than 2 decades are needed. In monitors they use gamma control for 0 to 100. – Tony Stewart EE75 Feb 25 '18 at 15:27
  • I was thinking of something like this. http://tinyurl.com/yberceoh many alternatives depending on specs. – Tony Stewart EE75 Feb 25 '18 at 16:02
  • That's using a BAT54 diode but gain ratios need to be defined – Tony Stewart EE75 Feb 25 '18 at 16:21
  • @TonyStewart.EEsince'75 Thanks a lot for the circuit! It needs 12V for the LED, drawing 1.15 A at full power. The signal source is Arduino, so whether it's PWM or low pass filtered, the range is 0-5 V. Is that circuit supposed to come after the low pass filter? Because if the signal source is PWM, I don't see any opportunity for variation in output except on and off. – piojo Feb 25 '18 at 16:32
  • @TonyStewart.EEsince'75 I see you chose a triangle wave to show the effect of various voltages. I'll need to stare at that a while (and read about more op amp circuits) before I understand it enough to modify it to flatten out the output (in the part that's from low voltage input). Thanks again! – piojo Feb 25 '18 at 16:43
  • also answer my questions on specs – Tony Stewart EE75 Feb 25 '18 at 16:49
  • @TonyStewart.EEsince'75 Sorry, I forgot the system notifies you for the latest only if I make more than one comment. The LED strip normally takes 12 V and draws 1.15 A. My power source is 12 V, plus or minus a couple hundred mV depending on load. The input is from Arduino PWM, so it's 0-5 V, whether I use it directly or use it after a low-pass filter. – piojo Feb 25 '18 at 16:54
  • Oh, and I imagine the LED strip needs 6-7 V at minimum to turn on, since it's made of sections with 3 LEDs each. – piojo Feb 25 '18 at 17:05
  • depends on colour, the resistor will affect the antilog curve. You need better specs – Tony Stewart EE75 Feb 25 '18 at 17:06
  • also the Darlington will drop voltage too much, so use 14V or a 100mOhm FET – Tony Stewart EE75 Feb 25 '18 at 17:18
  • @TonyStewart.EEsince'75 I thought part of the plan was to have a current-controlled output, so the load's impedance wouldn't matter. As for the Darlington, my version-1 circuit uses a TIP101, and I don't mind the small drop in brightness. (I'm not sure it's a bad thing, since Vcc is 12.3 V with no load.) But thanks for all your help! I need to read a lot more about more op amp circuits before I'll be able to respond intelligently to what you've said so far. I'm very new to op amps :) – piojo Feb 25 '18 at 17:26
  • Ledstrips are usually designed for White from 9 to 14.2V from dim to automotive peak voltage so dropping 12 to 10 is significant – Tony Stewart EE75 Feb 25 '18 at 17:28
  • @TonyStewart.EEsince'75 I would have sworn I measured the transistor to not drop very much, but it's too late for me to either measure it again or read the data sheet. Thanks for all the help. You've given me a lot to think about and read about! – piojo Feb 25 '18 at 17:42
  • The Rce is about 1 Ohm so drop depends on current. Make a list of all known specs in question. For inputs and outputs, including perception and number of steps for smooth transitions at low levels PWM resolution and f. etc etc. Voltage range and current on stripleds 9 to 14V – Tony Stewart EE75 Feb 25 '18 at 17:57
  • 1
    If you don't need the frequency to be too high, you probably can use bit-banging PWM instead of timer based. What I did when building a lamp was using I2C DACs to drive LED drivers. So, a bit easier to get whatever resolution I needed. – Wesley Lee Feb 25 '18 at 18:21
  • Is increased frequency and dirtering (spelling?) an option? – winny Feb 25 '18 at 20:04
  • @WesleyLee Bit banging is a good idea, but I'm not sure if I can get an acceptable result. I saw blinking when I used the 16-bit timer and the minimum duty (1/65535). Plus, it was brighter than it should have been, for reasons I still don't understand. It's possible Arduino is simply not fast enough, or the wave doesn't fall fast enough. I didn't try to work around the problem because I thought I'd need a decent quality oscilloscope (not a sound card attachment). – piojo Feb 26 '18 at 00:14
  • @winny Dithering? Yes, that's an intriguing idea—you mean with lower duty and decreased frequency, right?—but it might make the circuit too bright. In my previous comment I mentioned two problems I encountered with ultra-low duty, which are starting to tempt me to buy an oscilloscope. With the scope, I could even experiment with components that would shorten the PWM pulse, like a comparator with a 4.9 V reference voltage. – piojo Feb 26 '18 at 00:21
  • 1
    You can go for the lowest duty cycle for one period, skip the next and so on. You can’t develop electronics without an oscilloscope. – winny Feb 26 '18 at 08:10
  • @winny Funny that I didn't know it was so obligatory. I thought being in the 'digital' world would mean I wouldn't need to be so concerned with signal characteristics. – piojo Feb 26 '18 at 13:14
  • Major incorrect assumption. I see it all the time from fresh-from-school-programmers. They learn the hard way. – winny Feb 26 '18 at 13:50
  • @winny Guilty as charged, though I'm only new to complex electronics, rather than being fresh out of school. If I may ask, does your instinct say a sound card oscilloscope or Arduino oscilloscope (160 kHz sample rate) would be able tell me about a 62.5 ns pulse repeated at 244 Hz? (1/65535 duty.) I know that the scope can make inferences without actually sampling each pulse, but I don't know how good the "smarts" are. – piojo Feb 27 '18 at 02:16
  • Though now that I've read about it, I know transistors, especially MOSFETs, can't switch that fast unless they're specifically designed for that. No need for an oscilloscope to know why it doesn't work at the smallest duty. – piojo Feb 27 '18 at 13:51
  • 1
    If your not after the waveshape as in rise and fall times, you can get away cheap and get a logic analyser or a fast 8-bit scope. – winny Feb 27 '18 at 16:12
  • Just because a MOSFET is able to switch that fast, it’s still dependent on your driving circuitry and layout. You need a scope or your fumbling in darkness. – winny Feb 27 '18 at 19:41
  • @winny Neither of my MOSFETs actually can switch as fast as I would need. The switching time would roughly equal the pulse time. I could still work around that with a scope. Thanks for the other suggestions--I didn't know about logic analyzers. I'll look into those soon. – piojo Feb 28 '18 at 00:35

2 Answers2

2

The proposed circuitry solution is needlessly complex, and will not be economical to prototype or produce. The entire premise of the question is not fully convincing, but accepting it at face value, there are far better ways.

  • As already proposed by user Dampmaskin, find a 16-bit timer. Many MCUs have these, including not only the ATmega328p in either traditional or "Arduino" forms and also very low cost Arm Cortex M0 parts.

  • Alternately, implement PWM with larger count widths in software, either entirely or by using software to trigger a one-shot hardware PWM

  • Use one 8-bit timer in repeating mode to trigger another in one-shot mode. This lets you effectively make much smaller fractions. For example, if the repeat time fires at an interval of 10 milliseconds, but the on-time timer counts from a timebase of microseconds, your maximum on time would be 255 microseconds, but your repeat is 10000 microseconds, yielding a range of 0.01% to 2.55%. When you need higher percentages, start reducing the repeat interval which functions as the divisor. This can easily let your create on time percentages too low to have any response from a typical LED at all.

The advantage all of these have is that the output to the PWM power modulator is a signal from a single MCU pin. At most, triggering one timer from another requires a single loopback wire or resistor from the output of one to the trigger input of another.

Chris Stratton
  • 33,282
  • 3
  • 43
  • 89
  • Commercial dimmers are noticably jerky. He wants to emulate smooth sunrise now. This demands more attention to specs and thus a more complex solution. It could be done in software with the right specs. – Tony Stewart EE75 Feb 25 '18 at 19:24
  • As the above schemes are ratio-based, they are variable with extremely fine granularity. – Chris Stratton Feb 25 '18 at 20:09
  • Eh, 0.01% isn't fine granularity with respect to perception. But your suggestions are workable, particularly if I buy a chip to drive the MOSFET. However, based on what I've recently read, MOSFETs just can't switch fast enough, even if they're driven with high current. I'm sure the perfect transistor exists, but I haven't found it. If I can smooth the current out (after the MOSFET), all your suggestions would work. And I should at least give that a try, but I can't predict what issues may arise. – piojo Feb 27 '18 at 14:37
1

This is not intended to be a complete DIY solution but background needed to design your specs for the desired transfer function at low levels, high levels and the entire range. You may want to test the actual current values from 9 to 14V and see what values you want for each PWM level. 10 bit resolution log resolution may be ok or not.

The eye theory http://www.telescope-optics.net/eye_intensity_response.htm Only need Photopic curve ( bright).

The psychophysics of human response gain and exponent. https://en.wikipedia.org/wiki/Stevens%27s_power_law

A 10-bit PWM software solution http://jared.geek.nz/2013/feb/linear-led-pwm

An analog lower current solution with some theory. http://www.presepioelettronico.it/Public/data/amministratore/20141214144447_AntiLogDrive.pdf

When implementing Op AMps, you must be concerned about Input & output common mode range limitations for BJT OpAmps as Rail to Rail are good but tend to have low output current.

The transfer function of a commercial Sunrise alarm clock with brightness & alertness vs alarm time. Brightness need not be full when waking up, to give time for eyes to respond. An hour may be too long for most workers.

enter image description here

This a modified S curve.

Tony Stewart EE75
  • 1
  • 3
  • 54
  • 182
  • Thanks! I just added details (like the formula and the initial acceptable step sizes) to the question. I'm keeping the formula, since I need something a bit different than linear brightness response--the goal is to not wake a person (me) up until near the end of the time interval--the brightness is supposed to sneak up on you, but not so much that your body hasn't started preparing to wake up. I don't know the theory of this, so I've been playing it by ear. I found a model of sunrise ramped up too quickly, so I wrote and tuned a formula. – piojo Feb 25 '18 at 18:50
  • that transfer function must be included in your spec ( question) You may end up with an S curve. Point form for specs is best. Like a datasheet. – Tony Stewart EE75 Feb 25 '18 at 19:16