Custom RGBW driver (with some interesting features)

I finally got myself into PCB layout using EAGLE, and as my first project I developed a driver for an RGBW LED. It uses software PWM (at 2 kHz) to independently drive the 4 dies of an RGBW XM-L (or other RGBW LEDs). It uses 2* AMC7135 per die. (The back side holds another 4 AMC7135s, a protection diode and a small capacitor, and a center pad for a spring.)

I had made an RGBW driver before, a NANJG101-AK-A1 with cut traces, fine wires to get the additional connections and stacked AMC7135, but I was unhappy with that solution, as it's quite fiddly, and also I was unhappy with the UI possibilities with a clicky. So this driver uses a momentary switch for the UI (electronic switch). When off, the quiescent current is only 300nA (that's 0.3µA), that would theoretically take a thousand years to discharge a 2600mAh cell...

I modded a Small Sun ZY-T29 with it. I used multiple layers of d-c-fix diffuser to mix the colors.

The firmware got 'grown up' meanwhile and makes good use of the RGBW LED's possibilities I think. And then some...

The different main modes are accessed from off state, each with it's own click pattern. Each mode then has it's own click commands to change parameters etc. To change the main mode you have to switch it off first (with a short click).

In the following a "T" refers to a tap, i.e. a short click, while "H" refers to a press&hold. "TTH" for example then means two quick taps followed by a press&hold.

From off state, the following modes can be accessed using their respective click commands:

T (switch on by a single short click) -- color cycle
In this mode, H (press&hold) cycles forward through the chromatic circle (red>yellow>green>cyan>blue>purple>red>...), TH (short click immediately followed by a press&hold) cycles backwards, so you can easily set your desired color. There's a short pause at the pure colors (R,B,G) to make hitting them easier. TT (double click) starts or stops a much slower automatic cycling (direction can be changed by H / TH). Brightness can be changed down (TTTH, halves output) and up (TTH, doubles); not that the PWM resolution is quite bad in the lowest modes. T switches off. EDIT: New version now ramps continuously. Not that at the lowest levels the limited PWM resolution causes steps in the color transition.

H (switch on by press&hold) -- white
probably the most useful modes for everyday purpose (more for indoors due to only 700mA and the diffuser), just white (using the white die). H and TH ramp the brightness up & down, roughly visually linear and smoothly (except for the lowest modes). Low is quite low. T switches off.

TT -- simple modes and blinkies
This mode has several simple sub-modes, use H and TH to cycle through them forward and backward. The modes are red -- green -- blue -- EU yellow warning strobe -- EU blue emergency vehicle strobe -- US red/blue police strobe -- wild color strobe. T switches off.

TH -- full RGBW mode
This mode lets you change every die's brightness individually, so you can mix every possible color. H and TH increase and decrease the current channel's brightness. TT changes the channel (R>G>B>W>R...), TTT backwards; a short blink indicates the active channel. T switches off.

TTT -- lockout
TTT again to reactivate

TTTT -- battery level indicator
This mode also has 2 sub-modes (switch between them with TT), one displays the voltage simply as a color: 4.5V-white, 4.0V-blue, 3.5V-green, 3.0V-red, intermediate colors for intermediate voltages. The other mode indicates the voltage by blinking; red for whole volts, green for tenths, blue for hundredths, e.g. 3*red, 6*green, 2*blue means 3.62V. NOTE that the driver clearly does not have an absolute accuracy of 0.01V! It may actually be several % off! So that last digit is only good for a direct comparison etc. T switches off.

All of the above modes have their own memory, they'll start with the settings used last time.

There's an undocumented mode. The owner might try to find out him/herself what it does.

And then there are 2 quite special modes...

TTTTTTTT -- measure cell capacity
This driver can measure the cell's capacity (in Ah) and stored energy (in Wh) with a load of 700mA down to 2.9V. Insert a full cell, activate this mode. It will then run for a few hours till the cell is drained and go into sleep mode. Press the button and it will tell the capacity and energy in blinks like the battery indicator above, i.e. a short white pre-blink to indicate capacity readout, 2*red, 5*green, 1*blue -> 2.51 Ah (= 2510 mAh), then a green pre-blink to indicate energy, then 8*red, 4*green, 7*blue -> 8.47 Wh. Can be repated by another tap. Exit this mode by changing the battery. This is the only mode that can't be exited by T. The above notes about accuracy also apply here.

TTTTTT -- measure internal resistance (including contact resistances)
This mode allows to measure the internal resistance of the cell, but including the contact resistances. It will light up for ~10s, pause, and then show the resistance by some blinks in mOhm, e.g. 1*red, 7*green, 2*blue -> 172 mOhm. The measurement is repeated over and over, T to switch off.
The battery must have sufficient voltage for the measurement, the measurement will be aborted (some red blinks, then switches off) if the voltage is too low. This may also happen with full cells if internal and/or contact resistances are too high. You might want to improve the contacts; the success of such measures can be seen in the measurement results. The above notes about accuracy also apply here.

I'll test it a bit more and might later send some kits (PCB and all components) for self-assembly.
Edit: Works fine.

Edit: Changed nearly the whole post; before that it described a preliminary firmware with much less features (only color cycle and white modes).
Edit: Added lockout and changing brightness in color cycle mode.
Edit: Color cycle now has a smooth brightness ramp.

Available as 17mm board or custom board for Roche F6 or custom board for the Yupard 16340.
New: Also as custom board for the Skilhunt H02/H02R (H02R recommended).

Available as complete driver or kit for self assembly or bare MCU.

Very interesting news! Are you making a batch for sale?

sweet! Congrats on your first foray into designing your own PCB. Looks like it was a success!

totilde: Not as complete drivers (I have no reflow equipment, and soldering a batch of these... I doubt I want to do that.), but maybe as kit to solder yourself. I got a couple of boards, not enough components though. Will order some next year :)

mattthemuppet: Thanks! Yes, a success :) . My second board is in the fab already, it's a 46mm driver board for King/Kung/T90 etc. I hope it'll turn out well, too.

Nice work DrJones. I dont understand how you do your work but like it for what it is. Your driver in my OL light is full of magic surprises. Happy xmas and have a safe new year. :slight_smile:

Very nice.

I missed this thread, very nice work. I just made myself a small AA zoomie with the xml colour and the 17mm intl-outdoor driver. I am happy with that UI, but being able to mix colours is much nicer obviously. I would be interested in a board+components when you make a batch of these.

The led I bought from led-tech.de by the way, they have the xml colour on a nice thick 20mm board ( that I sanded down to 16mm).

To share some thoughts....

I have played with rgbw lights for quite some time now and have thought about how a -for me- ideal UI would be. It would be operated with two switches; a reverse clicky (say: at the tail) and an electronic (side) switch. I do not have the knowledge how to implement it in an actual driver, and I guess it will not be possible with this particular driver without altering the hardware, it is a wish..

The clicky would cycle through WRGB (or whatever leds you connect this driver to, perhaps a quad board with leds in the four colours behind a TIR, that may solve overlap problems in the beam). When the next die is on, the last is off, like the intl-outdoor rgbw-driver without the blinkies. This way, if just the clicky is used, you can use the four dies/leds in a simple effective way separately.

But when one of the dies is activated by the clicky, you can use the electronic switch to ramp it down and up to set the brightness. As soon as you use the electronic switch for ramping, switching to the next die with the clicky leaves the last die at the set level, so it does not turn off anymore. This way you can adjust all four dies to a desired output.

I don't think I would want memory, I like this UI to be simple.

I'm not planning a dual switch firmware.

But there will be a mode where you can increase or decrease the value for each die.

The white mode got much more useful meanwhile, upated OP. I even often EDC this light in the evening indoors, just for the white mode.

Added quite some modes (edited the OP). I'm quite happy with it now. :)

I wont repeat myself but orsm.

amazing driver, those test modes are a must for all lights!

(grin..) that has become one weird and very complete driver, I think it is huge fun to build a flashlight around it. I'm in for a kit when it is ready :-)

Measured a quite old Trustfire Flame: 1.5Ah, a newer one: 2.2Ah, new Panasonic NCR18650B: 2.9Ah. Sounds plausible.

It is a 'colourful dream discharger' ;-)

What a great project.

great thinking outside the box!
A question about the pwm: if you move the light quickly in any of the colour-mixed modes, do you see a line of R/G/B dashes, or a solid colour line?
I would still love to see an alternate firmware for clicky switches, even with just the basic modes.

Thanks :)

2kHz gives a solid color line.

I honestly have no additional mode ideas for this. Sure someone will come around saying “can you change this timing to this timing?”, but you went above and beyond on this one.

how much code space did you use/how much was left?

Edit: nevermind, I have a mode question: how easy would it be to implement brightness ramping in the color cycle mode?

Brightness ramp in color cycle: not that easy, mainly due to the limited PWM resolution at low levels, i.e. at low levels there will be much less available colors. I may try anyway though.