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

0 Members and 1 Guest are viewing this topic.

Offline DamonTopic starter

  • Newbie
  • Posts: 6
  • 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: 1432
  • 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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12866
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: 6
  • 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: 5031
  • 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: 263
  • 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: 263
  • 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: 6
  • 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: 263
  • 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!
 

Online themadhippy

  • Super Contributor
  • ***
  • Posts: 2591
  • 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: 263
  • 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

  • Regular Contributor
  • *
  • Posts: 163
  • 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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12866
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: 263
  • 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!
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12866
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 »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19544
  • 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: 367
  • 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: 6
  • 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 »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19544
  • Country: gb
  • 0999
Re: Dimming signal 0-12V from microcontroller (logic level to 12V PWM)
« Reply #18 on: Yesterday at 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: Yesterday at 10:40:40 am by Zero999 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf