Darkstar

Few years ago I was facing simple question. Should I invest a huge amount of money to one of the top headlamps like Scurion or am I able to build my own with similar parameters? Well, buying stuff is easy and boring, building my own is a great way to learn and save some money (in theory).

After brief comparsion of various headlamps, I've came with following requirements:

• Separated battey box for two or more Li-ion 18650
• Two LEDs, flood and spot (preferably latest Cree technology, at the time of building the lamp Cree XP-L2), with separated control
• Aluminium body (heatsink, durable)
• Water and mud proof design

Hardware

The headlamp is just a current source for a LED module, right? Maybe with some additional crap like modes control, but the current control is the most vital part. High power LEDs can draw around 3 Amps at 3 volts. Li-Ion battery has nominal voltage 4.2 Volts, higher than LED nominal voltage. This simplifies the design. So, how can we control the current trough LED?

• Linear supply - Resistor/Diode/LDO in series with LED, ineffective (4.2 - 3)V * 3A = 3.6 Watts lost as heat, hard to control power output (multiple switchable resistors)
• Direct PWM - limit current by resistor, control brightness by PWM - ineffective same way as above
• Switched current source - best possible efficiency, current through LED is precisely controlled, switched supplies have efficiency above 90 %.

So, switched current source is the best, right? But how do I get one? And how to stuff it inside tiny headlamp? Fortunately, I found interesting application note from Microchip. PIC MCUs contain reasonably fast comparators inside. These can be used in simple, but working buck regulator. The principle is simple:

• High side switch opens, current flows through coil in series with the LED and current measurement resistor
• Current through the coil cannot change immediately, it's rising, voltage accross measuring resistor is rising therefore too
• Once voltage on resistor reaches configured value, high side switch is closed, coil becomes current source and current flows now through diode connected to ground.
• Once voltage on resistor falls below configured value, high side switch opens and cycle starts again.

These magical configured values when high side switch changes its state are derived from one reference voltage (generated by MCU, more below) and hystersis of the comparator. Equations to control exact values can be found in the Microchips application note mentioned before.

Now I need to generate the reference voltage. Cheap PIC MCUs don't have DAC, so what now? Just run PWM of reasonably high frequency through simple low pass RC filter, it removes the higher frequency parts of the signal and what remains is a DC value (with some small ripple, no filter is perfect, especially single stage RC is quire horrible filter to use, but it requires only two components!). Cut off frequency of the RC filter is $$F = \frac{1}{2\pi RC}$$. We need to get as low as possible - it means large capacitor and large resistor. Cap can be in range of $$\mu F$$, resistor in hundreds of $$k \Omega$$. This way, the cut-off frequency is in dozens of Hz. Cut-off means the filter attutenation is 0,5. Simple RC filter provides 20dB/decade. Dozens of kHz means 3 decades, 60 dB, the main frequency will be made 1000 times weaker. That should be ok.

Rest of HW is just a bunch of buttons, passive components, nothing special. The board was designed in KiCad and manufactured by Seeedstudio. LEDs are mounted directly on the PCB, below the LED heatsink pad there's a bunch of vias to move heat to back of the PCB (and eventually to the aluminium body).

Software

The software for PIC MCU was written in assembly. Why not? It's quite simple and these MCUs are so cheap... The principle is simple, user is pressing buttons to increase or decreate LED power (or turn on/off second led), when upper button is held, MCU turns off the leds and goes to sleep, to wake it up again, user has to hold the button for a second or so. For programming there are 4 pads to connect the programmer, you can either solder wires directly to these pads, or you can be clever and use pogo-pins.

Mechanical

The body was machined on a lathe from Aluminium 6082. As my workshop tooling isn't as good as I would like to, my manufacturiong options were severly limited. Smallest cable gland I was able to find was something like M8, which is huge for such a small lamp (body weights only 80 grams). Therefore I simply glued the cable into a hole with almost exacly the same diameter as the cable itself.

The battery box is 3D printed, sealed by O-ring. However while testing in the kitchen sink, few drops of water got inside and the box become heavier, it seems the water was able to penetrate the box between printed layers. It's almost impossible to get rid of it afterwards. Therefore I printed the box from ABS and applied some acetone to smooth the surface and increase waterproofness.

Li-Ion batteries were taken from an old laptop battery and simply soldered together. As these cells were unprotected, I soldered small BMC protection circuit from ebay on top of the cells. To make the resulting battery bit more rigid, I used a heat-shrinable tube and two pieces of plastics that serve as top and bottom covers. Add aa piece of wire and a connector and it's ready to be used.

Testing

As a student of electrical engineering, I was able to negotiate access to ligh lab at my university. The real light output from this beast after few minutes since turning on was 200 lm at 4800 K. More about light measurements can be found on my github.