Author Topic: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)  (Read 2719 times)

0 Members and 1 Guest are viewing this topic.

Offline DamonTopic starter

  • Newbie
  • Posts: 8
  • Country: de
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 @ 200mA

The µ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.pdf



I'd appreciate any and all suggestions, thank you!
 

Offline MathWizard

  • Super Contributor
  • ***
  • Posts: 1625
  • Country: ca
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #1 on: April 18, 2024, 03:34:46 am »
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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13132
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #2 on: April 18, 2024, 04:25:40 am »
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.
 

Offline DamonTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #3 on: April 18, 2024, 06:21:25 pm »
@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?

 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5143
  • Country: ro
  • .
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #4 on: April 18, 2024, 07:09:46 pm »
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 ... see https://www.electronics-tutorials.ws/combination/r-2r-dac.html

or just make the dac and then use an opamp to 3x-4x the voltage
 

Offline TrickyNekro

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: gr
  • Drinking Frappé on the way to Isomnia!
    • Youtube channel, electronics and more ;-)
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #5 on: April 18, 2024, 08:12:02 pm »
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 dischange
through 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 the
output of the Op amp to driver your LED driver is more than enough, especially when the wires are short.
If you are an engineer and you are not tired...
You are doing it wrong!
 

Offline TrickyNekro

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: gr
  • Drinking Frappé on the way to Isomnia!
    • Youtube channel, electronics and more ;-)
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #6 on: April 18, 2024, 08:15:07 pm »
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 ... see https://www.electronics-tutorials.ws/combination/r-2r-dac.html

or just make the dac and then use an opamp to 3x-4x the voltage

Better 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?
« Last Edit: April 18, 2024, 08:17:13 pm by TrickyNekro »
If you are an engineer and you are not tired...
You are doing it wrong!
 

Offline DamonTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #7 on: April 18, 2024, 10:07:22 pm »
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.
 

Offline TrickyNekro

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: gr
  • Drinking Frappé on the way to Isomnia!
    • Youtube channel, electronics and more ;-)
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #8 on: April 18, 2024, 10:28:04 pm »
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 you
without 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 an
instrument ( 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.
If you are an engineer and you are not tired...
You are doing it wrong!
 

Offline themadhippy

  • Super Contributor
  • ***
  • Posts: 3025
  • Country: gb
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #9 on: April 18, 2024, 10:40:31 pm »
Quote
8 bit is 255 steps, duh, but it´s should be more than enough.
T'is what the entertainment world has been using for a good few years .
 

Offline TrickyNekro

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: gr
  • Drinking Frappé on the way to Isomnia!
    • Youtube channel, electronics and more ;-)
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #10 on: April 19, 2024, 10:56:24 am »
Quote
8 bit is 255 steps, duh, but it´s should be more than enough.
T'is what the entertainment world has been using for a good few years .

Guess 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.
If you are an engineer and you are not tired...
You are doing it wrong!
 

Offline xvr

  • Frequent Contributor
  • **
  • Posts: 433
  • Country: ie
    • LinkedIn
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #11 on: April 19, 2024, 02:19:23 pm »
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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13132
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #12 on: April 19, 2024, 02:32:58 pm »
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/3vQ6qef

Attached 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.
« Last Edit: April 19, 2024, 02:35:04 pm by Ian.M »
 

Offline TrickyNekro

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: gr
  • Drinking Frappé on the way to Isomnia!
    • Youtube channel, electronics and more ;-)
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #13 on: April 19, 2024, 02:48:38 pm »
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.
If you are an engineer and you are not tired...
You are doing it wrong!
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13132
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #14 on: April 19, 2024, 02:58:36 pm »
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's LEDC (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.
« Last Edit: April 19, 2024, 03:02:11 pm by Ian.M »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19997
  • Country: gb
  • 0999
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #15 on: April 19, 2024, 05:21:44 pm »
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
« Last Edit: April 19, 2024, 05:25:45 pm by Zero999 »
 

Offline MarkT

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: gb
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #16 on: April 19, 2024, 05:41:38 pm »
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.
 

Offline DamonTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #17 on: April 28, 2024, 04:49:57 pm »
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...  :palm:
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.
« Last Edit: April 28, 2024, 04:56:56 pm by Damon »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19997
  • Country: gb
  • 0999
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #18 on: April 29, 2024, 08:48:14 am »
I thought you said the dim input is 12V tolerant?

The ratio of R3:R2 is wrong.

AV = 1 + R2/R3

You need R2 to be 2 2/3 times the value of R3 for a gain of 3 1/3.

Try
R2 = 56k
R3 = 24k
« Last Edit: April 29, 2024, 10:40:40 am by Zero999 »
 

Offline DamonTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #19 on: May 04, 2024, 03:32:14 pm »
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 VDD
https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf#subsection.4.4

Would 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)?

 

Offline xvr

  • Frequent Contributor
  • **
  • Posts: 433
  • Country: ie
    • LinkedIn
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #20 on: May 04, 2024, 04:47:27 pm »
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.
 

Offline KrudyZ

  • Frequent Contributor
  • **
  • Posts: 293
  • Country: us
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #21 on: May 04, 2024, 05:22:23 pm »
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...
« Last Edit: May 04, 2024, 05:23:57 pm by KrudyZ »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13132
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #22 on: May 04, 2024, 10:34:54 pm »
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.
 

Offline soldar

  • Super Contributor
  • ***
  • Posts: 3540
  • Country: es
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #23 on: May 05, 2024, 06:27:05 am »
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.
LED 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.00
1.59
2.52
4.00
6.34
10.06
15.97
25.34
40.21
63.81
101.26
160.69
255.00
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline DamonTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #24 on: May 05, 2024, 10:42:18 am »
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.

Where 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%5D
Is 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)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf