jiristepanovsky.cz

Return to Index


Flashlight - 2021

Getting a decent quality high-power flashlight is not easy. Sellers are adding as many features as possible and are exaggerating or straight-up lying about their product's performance. So the mainstream is represented by unpractical flashlights with 3, 5 or even 7 modes, which are a total nightmare to navigate through. To top it off, the "rated" lumen output has (almost) nothing to do with the real brightness. At worst, the seller is lying completely; at best, the lumen output reflects the maximum ratings in an LED's datasheet, regardless if the flashlight is actually able to provide such current and sufficient cooling.

Hence, I started to build my own flashlight (that you can see in the video), with the following design requirements:
pocket size body with a small 14500 Li-ion inside,
as much lumen output as possible,
linear drive with Attiny10 as a controller,
constant current drive,
low battery voltage cutoff,
high LED's die temperature cutoff.

The schematics that mostly complies with everything above looks like this:

Flashlight schematics

The flashlight is powered by a 14500 Li-ion battery, which can provide up to (about) 1.5 amps, and the light is produced by a Cree XM-L LED. The LED is driven using 8205 N-MOSFETs connected in parallel and operated in their linear region. 8205 is commonly used in BMS circuits; it has low on-resistance and low Vgs voltage, which is required to reduce the drain-source voltage drop in this circuit to the minimum. The 8205 is controlled by a PWM signal smoothed out using a low pass filter (R4, C2). With a PWM frequency of 8 kHz, the attenuation is about -76 dB which is close to DC. The filtering of the PWM introduces a slight lag in the system, but nothing major.

The current is measured on the RESET pin of the Attiny10 microcontroller as a voltage drop over the R1 shunt resistor, with R2 as a protection. Since the RESET pin is still used for resetting the controller, the voltage must not drop below 90% of VCC (according to the datasheet). That limits the maximum current somewhat, for example, to 1.2 amps if VCC=3V. The maximum current can be, however, always increased by lowering the value of R1.

The temperature of the LED's die is measured using a 100k thermistor placed next to it with some thermal paste in between. The temperature is calculated from the voltage between R3 and TH1 when PB1=GND.

Measuring the VCC voltage was the biggest problem. It would be nice to have some internal voltage reference in the microcontroller or at least an external voltage regulator. But Attiny10 has no reference, and voltage regulators have significant quiescent current, which would lead to considerable battery consumption. Therefore the VCC voltage is calculated from the ADC value measured on diode D3, when PB2=GND and PB1 has enabled pull-up. From the following graph, it is clear that the voltage on D3 is nicely linear to VCC voltage at a constant temperate.

Flashlight diode vcc

But as you can see again on the second graph, the voltage on D3 is highly temperature-dependent (typical -2mV/degree). That is a BIG problem in a flashlight that can experience significant temperature changes...

Flashlight diode temp

Sadly, we can not correct the measurement using the thermistor TH1, since the LED's die temperature does not necessarily reflect the D3 diode temperature. All in all, it sounds pretty bad, but even though the firmware does not account for the temperature dependency, for VCC range of 3V to 4.2V and temperatures of 25 to 60 degrees Celsius, we can still calculate the VCC voltage within +-0.2V. Do not get me wrong, that is pretty bad; but in this project it is sufficient for the low Li-ion battery voltage cutoff.

Finally, let's talk about Schottky diodes D1 and D2, which should provide polarity protection. The only problem is that C2 is directly grounded, so if the polarity is reversed, the only protection against reverse-polarization of C2 is R4. It does prevent any catastrophic failure but still introduces a slight reverse current flowing through C2. Connecting the negative terminal of C2 to the anode of D1 would prevent that... I have no idea why I have not done it.
D1 increases the minimum gate voltage on the 8205 to about 0.2V above GND. Fortunately, it is not enough to introduce any measurable current through the power LED.

Flashlight pcb

The double-sided PCB has about 14mm in diameter. One side serves as a contact point for the positive terminal of the 14500 Li-ion, whereas components are placed on the other side. Missing on the PCB is the LED, thermistor, and a push button. The thermistor is mounted to the power LED with some thermal paste and placed in front of the flashlight. The push button is placed in the removable bottom cap of the flashlight and has to be connected via a wire... Although the negative terminal of the Li-ion is also connected via a wire, it could be as well connected via the metal body of the flashlight.

Flashlight XM-L

I have used two cheap flashlights and replaced the drivers inside them. One got a brand new Cree XM-L power LED, the other one was left with the original 3W LED.

Flashlight 3W

The firmware is written almost entirely in assembler, considering the tiny 1kB FLASH memory inside of Attiny10. When turned off, the microcontroller is in power-down mode consuming less than 0.2uA. When turned on, a closed-loop PID regulator controls the duty cycle of the PWM, influencing the gate voltage on 8205 MOSFETs. The current is set to 1 amp for the XM-L LED and 750 mA for the 3W LED. The XM-L can easily withstand higher currents, but the SOT23-6 package of 8205 can not dissipate much more power than it already is. When the low battery voltage threshold or the maximum LED's die temperature threshold is reached, the brightness automatically and gradually decreases such that these limits are not exceeded. It is much more user-friendly than just shutting the light off, but of course, when the battery voltage gets so low that even the lowest brightness is not sustainable, the light turns off entirely.

The firmware also allows displaying the battery charge level and selecting an arbitrary brightness by holding the button. But, notably, these functions do not interfere with the simple on/off action when just pressing the button.

Flashlights

I used two cheap flashlights to mount the circuits in. The smaller one is 19mm in diameter and 84mm in length. It has XM-L LED inside driven by 1 amp, which should produce more than 300 lumens (according to the datasheet). It uses a TIR lens with an efficiency of about 80%, so the real output should be somewhere around 250 lumens.
For its size, the flashlight is realy bright and is comparable to the much larger ones "rated" at 1000 lumens. Of course, some larger and more expensive flashlights with 18650 inside are indeed brighter.

Flashlights

The power output of this flashlight is near its possible maximum. An additional increase would have to be complemented with a larger MOSFET with a better cooling... and therefore probably even a larger body. Furthermore, currents above about 1.5 amps would have to be supplemented with a bigger battery, like 18650, for example.
One might, however, increase the efficiency. For example, LUXEON TX LED seems to offer slightly better performance than Cree XM-L at the same current. Another option might be to use a buck driver instead of a linear drive.
From the circuit perspective, it suffers from an inaccurate VCC voltage measurement. It would be nice to add a voltage reference somehow and not use the temperature dependant diode D3. Also, the Attiny10 has only 8-bit ADC, which is quite limiting mainly for the current measurement (LSB is about 60mA). A bit more precise ADC and current measurement would be nice.

To sum up, when building a flashlight with high power output, one must consider the voltage drop over a MOSFET and any other components in the electrical path (shunt resistor, wires, springs, switches...). Especially in a single cell flashlight, where the voltage of the battery at high currents is not much higher than the voltage drop over the power LED. Further, it is important to consider the thermal dissipation of the LED and MOSFET and either ensure sufficient cooling or monitor their temperature. My circuit does the second thing because it can get really hot really quickly.

That's all, firmware and schematics can be downloaded here.