How To Build a Flashlight With Perfect Modes (picture heavy)

Yes, the capacitor could be rapidly charged across the diode and slowly drained via the resistor. Although I don't see how the capacitor would lose its charge in an exactly defined time if the ATtiny was switched off.

It is a small capacitor, perhaps 100 nF, and there will always be a (very) small leak current into the powered-off ATtiny port. About accuracy, look at the different timings on my lights a few post's backwards, there are two 'identical' C3-SS, one with 5 sec and one with 10 sec untill storing the mode. They properly have equal circuits.

I can see no other use for this circuit than providing this storing-timing. I really think we spotted 'how they do it'.

According to the datasheet, there is a maximum leak current of 1µA into a tri-stated I/O pin at 5.5V, which equals a minimal resistance of 5.5MΩ. I measured ~12MΩ on one of my chips. A high level is >= 0.6 * Vcc, so if we take these two values as lower and upper bounds, and assume the capacitor is 100nF, this circuit would register taps from 0.3s to 0.6s in length. That sounds plausible.

I expect this could work with just the capacitor alone. This would be the poor mans version, but more easy to implement in hardware. The AK-47 already have solder pads ready for this, connected to pin 2 (look at the left end of ATtiny). Pin 2 is also connected to the first star underneath, where it is also easy to mount a capacitor. On the NANJG 106 (from KD, 8x7135), the first star is likewise connected to pin 2 and second star to pin 3, so here it is also easy to add the condenser. I expect the same possibility on 101-AK, but my last DX order on theese gave me AK-47C instead with PIC uC.

In SW, could'nt we just omit the WD counting to 8 and instead read pin 2 at start-up?

It would ne nice to have two versions (#define ?), one (the present version) with power-up-memory and one with power-down-memory for those that have an already equipped driver (as the BLF-light) or don't mind adding a capacitor.

I tried a similar circuit (470kΩ and a diode in parallel to a 1µF capacitor) on my breadboard model this morning. It works reliably for detecting short clicks. Removing the diode breaks the circuit, as the I/O pins seems to lose the high impedance state during start-up. With just the resistor it either takes much too long to charge the cap or it is drained before the program has a chance to test it, depending on the resistor used.

Adding this kind of mode switching to the program shouldn't be too hard, although it already contains far too man #ifdef-ed code blocks for my taste.

*Sigh* just when I thought I could go job hunting without any more distractions from this project, you come along and hand me an interesting problem...

I think that interesting problems is just why we have this forum , good hunting! - eventually...

Mode memory after power-down.

I now have the power-off memory working in my BLF AA-Y4E with the original components (a diode in parallel with 100 kOhm going from pin 2 (port B.3) to a capacitor looking like a 100nF). All taps shorter than 1 sec shifts to next mode, longer taps turn on in the same mode. It seems to work fine and an oscilloscope show that the condensers voltage fall to half value in about a second. The coding took only a few lines and the omission of watch dog counting as this got obsolete. I have used Tido's program version 2 for the testing.

Next, I will try to implement similar function on AK-47, 101-AK, NANJG 106 with the fewest possible extra components and report back here.

Yes, it can be done in a few lines of code. The hard part is not getting it to work, but not to break other configurations in the process. The real head scratcher is how to implement the mode programming. With the cap-switching, there is only one type of tap. We could fall back to mem-switching just for the acknowledging sequence, but memory is so tight that there would be only enough space for a single mode function.

I see what you mean, my preference is for the time being just a simple, 3-4- or 5-level light. Spacing the levels with less than a factor of 4 is in my opinion overkill because of the logarithmic behaviour of the eye.

I focuses much on the memory after power-off because I find the opposite annoying: you often tap through levels to find the level that suits you, at least I do. If you are a little indecisive the next tap often does'nt work because the memory kicked in and the time window has to be re-started first.

This seldom happens with memory after power-off because you don't have to judge anything during the off period.

About my experiments, they confirm what you have found earlier, that a condenser alone get drained by the port during power-off, that calls for at least 3 components -too bad.

Okay, I've thought about the acknowledging sequence a bit and I think I've found a way to do it without falling back to mem-switching. We could keep the short-short-long-short sequence and abort programming once the light stays on for more than two seconds. This would effectively prevent any accidental re-programming and should be quite easy to implement. Although there will be yet another case of #ifdef...

This is probably the last feature I'll be adding to the driver, as it has already reached a state where it's really hard to read the code and see what's going on.

A WF502B-R5 was modded with version 3 of Tido's BLF-VLD program. I choosed to make a simple 4 mode light with low battery detector. The modes was layed out as 1.5%-6%-25%-100%, the result in (my own)lumens was 3.5-16-66-240.

The program now has battery low detection. When the battery voltage drops under about 3V the light will revert to lowest level and will blink every 5 sec's. This is a matter of taste, perhaps it should only blink as a warning, but then it could not be left alone without damaging a battery without protection. Perhaps the best would be that the light stepped down a step at a time (how about that, Tido?). This is easily done manually by just restarting in a lower mode, the detector will not cut during the first few sec's.<(Edited): The Low Bat function is now changed so that the output repeatedly will be cut to half every time the battery voltage fall to 3V. That way the output will be optimized to the remaining charge until the LED only glows. This works very nice.>



At the top a fourth 7135 is added to obtain 1.4 Amp. At the bottom, the wire connecting the chip to the memory circuit on the other side is visible. At the right a new, round diode - I used the original, smaller doide in the circuit underneath as the round one was too long. <(Edited): I have changed the diode back again! the original diode is a Shottky type to keep the chip running at low voltage.>



The 3 added components to make the memory_after_off (as in TR-801, EF23, Skyray S-A1, F20, C3 SS, Z1, WF501B-MC-E, ...). A diode is soldered 'piggy-back' on top of a resistor of 10MOhm (invisible in the picture), both soldered to a capacitor of 100nF to the outer ring. The isolator underneath is a piece of tape for painting. These components are not nesessary if you prefer a memory_after_on type (as in Tank-566, TrFi.R5-A3, WF502B-R5, ...). The PIN_SWITCH variable in the program should be changed accordingly.



The pill in place. In the tube two full rounds of Pepsi-Max alu-can is fitted for better cooling.

EDIT:
After a few broken capacitors, I changed the mounting method to a more rigid one. Here shown on a NANJG 105C which already (like the AK47) has a star that is connected to the MCU pin 2 so a wire is not needed. This makes the mounting of components and also a later reprogramming of the MCU easier.
I put a piece of Kapton tape besides the rightmost star to isolate the other stars and solder the capacitor to the rightmost star. Then from the free end of the capacitor I solder the resistor and the diode (cathode) to the outer ring (see picture). This circuit has exactly the same function as the former but is more mechanical stable.

That is fantastic! Absolutely amazing and incredibly tiny detailed work. I guess the PWM has been set fast enough where it isn't noticeable or are there problems setting it so high for so little output?

The PWM frequency is 1.1 kHz. The light is rock-steady on lowest. The actual PWM output design values are 0x04 - 0x0F - 0x3A - 0xFF. There are no problems in lowering the low value down to 0x01 but the output is not quite linear at the lowest values. To make 1 lumen I would guess the output should be 0x02.

About the mem_after_off, it is sensible to bad connections and could shift level by knocking on the light. Perhaps 10uF across the chip could help. But it sure is my preferred kind of memory.

Again I have to issue a warning. This time it is the NANJG 105 driver from KD . They have changed it to 105A and it has a PIC processor (luckily I have two of the old 105 with ATtiny for my upcoming XM-L's). Here are pics of the two sides:

At least it has stars so it is possible to make a 3-mode (I hope). I expect it has memory after ON plus 2 sec.

Now to the big question: are drivers with ATtiny about to die out?

That would be a real bummer, the Atmels are the easiest to re-program. OTOH, I've got a PIC-Kit2 programmer on the way, so this is a strong incentive to port the BLF-VLD to the PIC platform ;)

Hi, I followed this thread with great interest, and I already programmed some kind of flashlight driver (a somewhat special thing for geocaching though, not a general flashlight; wanted to do that next).

I too got the new 105A from KD (unfortunately a 5-pack), while I earlier got two 105 ones. And fortunately I have still some AK101 and AK47 around.

I just got into programming AVRs (WinAVR/AVR Studio), I don't know if I really want to adapt to PICs, too.

I wonder about code efficiency... The 12F629 has space for 1024 instructions (of 14bit each...), which is more than the ATtiny13 (1024 Bytes for 512 two-byte-instructions), but tiny13 has a bigger (more powerful?) instruction set (120) than the PIC (35). The available free compiler (Hi-tech PICC lite) probably will optimize less than the avr-gcc - So I'm looking forward to your porting reports.

Furthermore the 12F629 doesn't have ADC nor PWM (as far as I know). -- I prefer AVR I guess :)

Did you order a 'real' PICkit2 (~33 EUR, ebay) or a cheaper clone (~17 EUR, ebay)?

Hi and welcome to the BLF DrJones!

Hope you will enjoy your stay : )

Hey DrJones, Glad to have you here!

I knew about your site many many months ago! Thanks for your help!

Welcome to BLF DrJones. I wonder, is this the same DrJones of DX forum fame? :)


Hi and welcome DrJones.

Good to have another active programmer here.