Dimming signal 0-12V from microcontroller (logic level to 12V PWM) - Page 1
Forum section: electronics / beginners

author: Damon
author_rank: Newbie
timestamp: April 17, 2024, 05:26:25 pm
content: Greetings fellow nerds,I want to use a µC to dim a light fixture. Its power supply already supports dimming,it currently has DIM input that's driven through a pot, sourced from its own V_aux (12V) supply.- DIM accepts 0-12V DC (measured 1V @ lowest / 11V @ highest brightness)- V_aux delivers 12V DC @ 200mAThe µC will most likely be a ESP32 variant, definitely something with 3V3 GPIO output and PWM support.My first idea was to drive DIM+ with a PWM signal of 12V amplitude.Is an MCP1402 (non-inverting mosfet driver) suitable for that task?Are there better-suited ICs?Other suggestions to output 0-12V DC from a 3V3 microcontroller, given the existing 12V supply?MCP1402 Datasheet:https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/20002052D.pdfI'd appreciate any and all suggestions, thank you!

author: MathWizard
author_rank: Super Contributor
timestamp: April 18, 2024, 03:34:46 am
content: You could make some little BJT circuit and drive it's base with PWM. If I'm reading that right, and this 12V PWM signal doesn't power the light, but just sends the brightness info, then yeah, a BJT would be very easy, since you don't have to worry about big mosfet gate voltages.

author: Ian.M
author_rank: Super Contributor
timestamp: April 18, 2024, 04:25:40 am
content: Does the light's manual say its DIM input supports PWM dimming? If not you need to filter your logic level PWM from your MCU to get an analog voltage then amplify it to a 0V-12V (or better 0.5V-11.5V) range using an OPAMP.

author: Damon
author_rank: Newbie
timestamp: April 18, 2024, 06:21:25 pm
content: @MathWizard it's just a control signal, I assume high impedance or a transistor gate/base at most.The manufacturer replied to my email saying it's a "0-10V PWM A-Type power supply",so it should do fine with PWM but they couldn't give me a recommended frequency or min/max duty cycle.I did some research today, 0-10V seems to be an industry standard for LED lights.@Ian.M I like the Op Amp idea, since I've never used one before.Can you recommend any specific part numbers? Or will just about any LM321 do?I added a solder bridge for the capacitor so I can change the output to either PWM or "analog".Would pull-down resistors anywhere make sense to have a fail-safe off (0V) output on the OpAmp?

author: mariush
author_rank: Super Contributor
timestamp: April 18, 2024, 07:09:46 pm
content: How many "steps" do you need between 1v and 12v?You could easily make a DAC from resistors, and use a few p-channel mosfets or pnp transistors to put 12v on the individual input bits ... seehttps://www.electronics-tutorials.ws/combination/r-2r-dac.htmlor just make the dac and then use an opamp to 3x-4x the voltage

author: TrickyNekro
author_rank: Frequent Contributor
timestamp: April 18, 2024, 08:12:02 pm
content: I think the idea of using an Op-Amp to drive such an input is not bad. If you are using a microcontroller then your input to the op amp is only going to be 3v3 or 5v. Just find the equations for non-inverting op amps.So you will need to to amplify your signal. There are fast and better Op-Amps for the task. Search for one that is at least RRI or plays well with inputs near zero ( even beyond rail - no phase inversion ones ).Also search for one that is doing pretty well driving the output near the lower rail, meaning either do RRO or find one that the output swing can go near the negative rail and around V+ - ( 1V ~ 1V5 ).There are some from TI that are quite cheap and will have a GainBandwidth product of around 1MHz. That will be more than enough for your 10 - 25kHz signal. Usually such drivers accept signals around a couple kHz,so you don´t really have to even worry about that.If you go for an analog filter like that, place a resistor ( 10k would be good enough, or 4k7 like the one you use for the filter itself ) between the capacitor and the op-amp, so that the capacitor does not dischangethrough the protection diodes of the op amp when you switch off the power.It´s always nice to add a bit of protection on the output also. 1k resistor and protection diodes along with a 12v zener is always nice. It could be the difference between 1 year of operation and 10 years. Although a resistor at theoutput of the Op amp to driver your LED driver is more than enough, especially when the wires are short.

author: TrickyNekro
author_rank: Frequent Contributor
timestamp: April 18, 2024, 08:15:07 pm
content: Quote from: mariush on April 18, 2024, 07:09:46 pmBetter use a DAC IC in all honesty if he ( she? ) is going for a DAC. It all depends though of how granular they want the control to be.Good question actually! How many steps does the OP need?

author: Damon
author_rank: Newbie
timestamp: April 18, 2024, 10:07:22 pm
content: I need enough steps to produce a visually pleasing, smooth fade between "daylight" and "chill" modes.BTW, through some searching (should've done that before) I discovered that the ESP32-S2 variants have a 8bit DAC built in,but while I have 2 DevKits, those are C3 and S3 variants without a DAC.The S2 DevKit is dirt cheap so I'll likely buy one too while I'm at it,but I'll take any excuse to dust off the Hameg HM-205 again, so low-pass + op-amp seems to be the winner.If you have any useful design tools / resources / search terms, then please link them in.

author: TrickyNekro
author_rank: Frequent Contributor
timestamp: April 18, 2024, 10:28:04 pm
content: I´ve heard the ESPs had some problems with their analog peripherals...Then again, I have never really used them, so bewarned, search a bit about if that´s the case. I will not deter you, but also won´t encourage youwithout doing some search first. Maybe PWM is just fine and will give you even more step ( if they have 16bit timers ).8 bit is 255 steps, duh, but it´s should be more than enough. Then again, neither LEDs nor human eyes are linear,so you´ll need the extra steps to produce something pleasing, with relatively not too many steps ( 20 - 25 steps should be anyhow enough ).Your driver is probably a current driver, but LED brightness is not linear with current. You´d have to linearize the LED power, probably with aninstrument ( there are 40 - 60€ ones, look like multimeters and will probably give you a good enough reading based on your installation also ).Then you got to logarithmize your data from your readings to match the human eye. Humans are logarithmic creatures.Example Op Amp for your case seems to be TS321CX5. Single Channel, good at near negative rail.These should be more than enough for now to be give you a head start.

author: themadhippy
author_rank: Super Contributor
timestamp: April 18, 2024, 10:40:31 pm
content: QuoteT'is what the entertainment world has been using for a good few years .

author: TrickyNekro
author_rank: Frequent Contributor
timestamp: April 19, 2024, 10:56:24 am
content: Quote from: themadhippy on April 18, 2024, 10:40:31 pmGuess that would be a reference to DMX.Yes, true but if the OP has to normalize brightness with software, then the OP would need more steps.I am not aware whether or not the lights in the entertainment industry are calibrated, or how they are calibrated.

author: xvr
author_rank: Frequent Contributor
timestamp: April 19, 2024, 02:19:23 pm
content: LED brightness really very NOT linear to current/PWM duty cycle. I had an experiment with dimmable RGB led. I run it with PWM in 0-255 duty cycle range.Values of 255-128 were almost indistinguishably (but PWM work as expected - mean consumed current dropped linear).Values 128-64 where distinguishable, but not much. And only when PWM duty cycle drops to 20-10 per 256 each change in it became clearly visible.

author: Ian.M
author_rank: Super Contributor
timestamp: April 19, 2024, 02:32:58 pm
content: The problem with LM321 TS321 etc. is their max. output is typically 2V below the positive supply, but you need <1V below the positive supply to get 11V for full brightness. That means you need a RRIO OPAMP rated for >15V supply voltage (for some safety margin at 12V).TI's LMC7101 looks like a good candidate, or try this parametric search @Mouser:https://mou.sr/3vQ6qefAttached are my idea of the circuit (omitting any output protection), and a LTspice sim of it. The third order passive low pass filter with a -3dB corner frequency of 18Hz is a compromise between speed of response (approx 22ms to 90% of new level after a step change) and ripple rejection at fairly low PWM frequencies. The resistor ratios are chosen to minimise loading effects while maintaining acceptable input and output impedances and using E6 series capacitor values. If you need a faster response, try 3.3K, 10K, 33K for R1-R3. If your PWM frequency is high enough, a second order filter may be good enough - delete R2,C2.R4 sets the offset at 0% duty cycle. If you alter the fiter resistors you'll need to adjust it as well to maintain a 0.5V min.output It has no effect at 100% duty cycle and the max output is set by the OPAMP gain (R7+R6)/R6 and the logic Vcc.

author: TrickyNekro
author_rank: Frequent Contributor
timestamp: April 19, 2024, 02:48:38 pm
content: I might be the spoilsport here but...If you can drive it with a PWM signal... And the Dimmer supplies it´s own power rails etc.Why not a pull up and a NPN / N Channel transistor? That´s by far the easiest and cheapest.

author: Ian.M
author_rank: Super Contributor
timestamp: April 19, 2024, 02:58:36 pm
content: Yes, that *IS* the simplest way, if there aren't going to be any nasty beat effects between the LED driver's internal PWM and the control PWM. Therefore you need to check you can meet the driver's PWM input frequency restrictions, and also check with real hardware.The ESP32'sLEDC(LED control) PWM peripheral has a max. input clock of 80MHz, which for 16 bit resolution limits the max. PWM frequency to 1220Hz. You want 16 bit resolution to have enough resolution at the low end of the brightness range for smooth dimming after correcting for the eye's logarithmic response.

author: Zero999
author_rank: Super Contributor
timestamp: April 19, 2024, 05:21:44 pm
content: The MCP1402 appears to be fine for just level shifting the 3.3V to 12V. It's possibly a bit overkill. A single BJT will probably do.Level shift bi-direc BJT 3.3V 5V.asc

author: MarkT
author_rank: Frequent Contributor
timestamp: April 19, 2024, 05:41:38 pm
content: The MOSFET driver is a perfectly capable level shifter, probably too capable as it will have hard edges and generate a fair bit of EMI as a result if driving a long cable. So I'd say use it if its close to the PSU, otherwise find a lower EMI solution like smoothed PWM.

author: Damon
author_rank: Newbie
timestamp: April 28, 2024, 04:49:57 pm
content: I've ordered several OpAmps (TLV272ID, MCP6H81-E/SN, TS912D, LMC6482IM, basically every Rail-to-Rail output capable 12V tolerant OpAmp below €2 that Reichelt had in stock).After completely wasting my time yesterday because I didn't realize my breadboard has separate power rails left/right along the long side...I managed to get a smooth voltage controlled via PWM using this circuit:I've tested it with +5V supply on the MCP6H81 and it works as expected.Good thing I bought some trimmers, since the fancy metal layer resistor kit have flimsy leads that barely make a connection with the breadboard...Next I'll test it with the 12V aux supply from the lamp and then I'll connect it to the dimming input,if that works well I'll try to design a proper PCB with some off-the-shelf 12V to 3V3 DC/DC converter module as a supply for the ESP32 devkit.Maybe there will be a rev.2, I just found an old LDR and I have some spare OpAmps (2-channel ones too),but currently I have no idea where I could mount that thing to expose it to ambient light.Now my last concern is protecting the dimming port. The highest voltage I've measured was 11.2V with the stock pot.I can't imagine an additional .8V would hurt, but just to be on the safe side, I'd like to add a zener diode for protection across the V_DIM output to ground.That won't interfere (below 11V) with the OpAmp output, does ist?Edit: BTW I don't know why I constantly mix those up, my Oscilloscope is an Hameg HM203-4, not a 205. Crusty but trusty.

author: Zero999
author_rank: Super Contributor
timestamp: April 29, 2024, 08:48:14 am
content: I thought you said the dim input is 12V tolerant?The ratio of R3:R2 is wrong.AV= 1 + R2/R3You need R2 to be 22/3times the value of R3 for a gain of 31/3.TryR2 = 56kR3 = 24k

author: Damon
author_rank: Newbie
timestamp: May 04, 2024, 03:32:14 pm
content: The magic smoke escaped from the MCP6H81 because 12.5V is greater than its rated maximum of 12V(duh, but the router wall wart was the most convenient 12V supply I had kicking around),so good thing I also ordered some TLV272s which are 16V tolerant.The ESP32-C3 GPIO measured 0.25V when it's LOW, with x3.3 amplification that's 0.825V.V_OL Low-level output voltage MAX = 0.1 x VDDhttps://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf#subsection.4.4Would this circuit with a BJT to shift 3.3->12V,settle to 0V (or at least "near" 0) when the GPIO9 is low (worst-case 0.36V)?

author: xvr
author_rank: Frequent Contributor
timestamp: May 04, 2024, 04:47:27 pm
content: This schema will not work at all.1. Q1 used as emitter follower. It will not bring output to 12V. and instead of Zero output voltage it will turn off Q1 and bring output to high impedance.2. No way to discharge C1. It will be charged to 2.6V (3.3-0.7) and will stay at this voltage.3. If output from IC1 will raise more than rated voltage of D1 that D1 effectively shot IC1 output. You need at least add current limiter resistor.

author: KrudyZ
author_rank: Frequent Contributor
timestamp: May 04, 2024, 05:22:23 pm
content: Keep the PWM voltage between ground and whatever IO voltage your micro uses, e.g. 3.3V.This is a simple RC filter to the non-inverting input of the OPAMP.Then put the gain into the OPAMP wiring it up as a non-inverting amplifier.Resistor between the inverting input and ground, e.g.10k and one between the inverting input and the output (20k).This will give you 0 - 9.9 V nominal on the output.This is just like you have shown earlier, only with correct resistor values...

author: Ian.M
author_rank: Super Contributor
timestamp: May 04, 2024, 10:34:54 pm
content: While you could rework my reply#12 circuit to move the offset resistor R4 to the OPAMP -in, then adjust it to trim out the PWM low offset, the ESP32-C3 GPIO low voltage will vary with how much power the ESP32 is using. The best option would be to buffer the PWM with a 74LVC1G17, which will give an output that swings to within 0.1V of its supply rails at 100uA load current, then filter and amplify that. You may need to increase your filter input resistor to keep the load on the gate output low enough to get close enough to rail-to-rail swing.

author: soldar
author_rank: Super Contributor
timestamp: May 05, 2024, 06:27:05 am
content: Quote from: xvr on April 19, 2024, 02:19:23 pmLED brightness probably is much more linear and what is not linear is the human eye's response which I expect to be close to logarithmic.So these would be steps of equal perceptible change:1.001.592.524.006.3410.0615.9725.3440.2163.81101.26160.69255.00

author: Damon
author_rank: Newbie
timestamp: May 05, 2024, 10:42:18 am
content: Quote from: Ian.M on May 04, 2024, 10:34:54 pmWhere do you get those numbers from? The datasheet I found says max V_OL @ VCC=3v & I_OL=16mA = 400mV, worse than the µC:https://www.ti.com/lit/ds/symlink/sn74lvc1g17.pdf?ts=1714851964968#%5B%7B%22num%22%3A64%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2Cnull%2C718.13385%2Cnull%5DIs it just common knowledge that for low currents, the output will reach lower levels?The TLV272 I'm using is a DUAL OpAmp, V_OL max is 0.1V for 5V supply voltage at low current (1mA).From the datasheet, it's obvious that V_OL depends on supply voltage and output current.With my current test setup (12.5V supply, no load) I measure 7mV - 12.5V using the 1st (A) OpAmp as a "comparator"(?) and the 2nd (B) OpAmp as a buffer:(R1 is again some other value, it's a pot in my test setup which I didn't measure yet)

author: Zero999
author_rank: Super Contributor
timestamp: May 05, 2024, 07:52:24 pm
content: Quote from: Damon on May 04, 2024, 03:32:14 pmOnly when run off a 16V supply, otherwise the maximum rating of the inputs is 0.2V above the positive supply.https://www.onsemi.com/pdf/datasheet/tlv271-d.pdf