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

My plan for building that driver is to actually keep the µC running for a while after the user has switched the light off. I'm going to use a bigger capacitor parallel to the µC, so when the battery power is off, it runs from that. Some battery sense pin is required to check if the flashlight is on or off, and sleep with watchdog is engaged as soon as power goes down (via interrupt). This allows timing the 'off' taps for mode changes etc. Since programm logic will be simpler, it might even use up less memory and leave more space for fun ("Hey look, that light says my name in Morse code!" :) )

When I first thought about the the BLF-VLD, I wanted to keep the MCU running too, but I soon realised that this just wouldn't work with the standard PCBs available. For one, almost all ATtiny based PCBs have voltage dividers for battery monitoring, that will suck a buffer cap empty in a matter of milliseconds. Second, to actually detect the power-off, one would have to add a wire directly from the battery's positive end to an I/O pin, circumventing the protective diode. As a major design goal was to have a driver program that could be flashed into a stock PCB, that was the end of that idea ;)

AFAIK, most PIC based PCBs don't have the voltage divider problem, as the 12F629 doesn't have an ADC and therefore can't monitor the battery's voltage. But you'd still need to add the wire for detecting power loss and would probably have to upgrade the buffer cap.

Have noticed your posts on DX forums , they stand out and have been helpful just knowing that your advice is a step above the norm..

I also have to admit to having a thing for Mrs. jones ..

We gotta thing goin' on ...

BLF-VLD version 0.4 is available for download here. Special thanks to sixty545 for giving valuable feedback and spotting a few bugs. This release is not as thoroughly tested as I would like, but I do have a lot on my plate right now. Bug reports and suggestions are still welcome, but it might take some time before I get around to fixing anything.

Here is the section from the ChangeLog:

2011-01-10 Tido Klaassen <tido@4gh.eu>

* BLF-VLD: release v0.4

* driver.c: fixed initialisation of ADC

* driver.c: added support for mode switching based on an I/O pin's
state

* driver.c: fixed driver getting possibly stuck in extended mode if
compiled without extended mode support and EEPROM gets corrupted.

* driver.c: added compile time option for gradually lowering light
level in low battery situation

For those of you who are worried about the availability of drivers with ATtiny13 I am happy to say that I just got 4 pc. of the old AK-47 with ATtiny13 delivered from KD in just 9 days.

Tested one: It was AVR programable as expected.

And I ordered a single AMC7135*8+MCU from KD on 01/05 and got a Nanjg 105 (with ATtiny13A) 01/14 :)

Edit: Doh, wrong item number, sorry, edited.

Can you tell the sku no. please.

I got 105A (with PIC) in an order of SKU: S009742 dec.9 - dec.27

I got a 105A SKU: S009742 1/3/2011

following this thread with interest but way over my head

Excellent thread! In fact, I registered on this forum just so I could post here ;) I want to thank all of you for the information so far.

I am planning on buying the equpment needed in order to program ATtiny13 chips to use in a driver for a D cell Maglite runing (for now) an XP-G. Here is what I plan to order or have ordered:

Drivers:
DX 7135 - http://www.dealextreme.com/details.dx/sku.6190 (probably a crapshoot to see if I'll get a good one with the correct MCU)
SB 7135 - http://www.shiningbeam.com/servlet/the-133/3-dsh-Mode-Regulated-Circuit-Board/Detail (not sure about the solder bridge I see between pins, but I'll try it)

Programmer:
USBtinyISP - https://www.adafruit.com/index.php?main_page=product_info&products_id=46

Cable:
SOIC 8 pin - http://cgi.ebay.com/ebaymotors/ws/eBayISAPI.dll?ViewItem&item=400171159037 (as suggested by a member here - thanks!)

The purpose of doing this is mainly to have some fun, but it seems the majority of the 7135 constant current multi-mode drivers out there have a UI that I really dislike. Because they only have an ON and an OFF state, controlled by switching the power from the battery, they have that funky "3 second memory" function (because there is no way to know how long a light has been off). Now, I would like to have the benefits of brown-out detection with a capacitor (I believe I'm saying that right) so that the controller knows when a user clicks the light off and then back on in a split second. However, I can't seem to find a good driver that has that ability, at least without other drawbacks. Currently, the Solarforce low-voltage drop-in I have in front of me has a great UI. You can turn it on for a split second, and as long as you wait a second or two before turning it on again, it will not switch to the next mode. Also, if the light has been on for a few minutes, you can switch to the next mode just by tapping the reverse-clicky once, instead of twice like the drivers I listed above. However, the PWM is really bad on it.

So, my goal is to hopefully be able to program whatever UI I or a friend might like to have, at least within the limits of the hardware setup. I will need to be able to do this with pre-mounted controllers, such as on the drivers I purchased. In the future however, I might try to build a driver board myself, but I doubt I'll get there. I've never programmed in C before, and I was initially turned on to the PICAXE chip as you can program in BASIC. However, being that the Atmel tiny chips can run at lower voltage and seem to be more widely available on pre-built drivers, this seems the way to go.

Anyways, I just wanted to say thanks and warn you that there will probably be a lot of questions coming your way. I've hardly soldered much in my life, let alone try to work with a microprocessor :)

- Jon

Hi JonnyC, and welcome to this thread. Hope you'll still like it after striking some time with the challenges in this project.

The 8 pin clip can really give you some grey hair. It needs some fine fiddling to have full contact with the MCU and at the same time hang on to it. Also you will do some microscopic soldering, especially as you (like me) prefer the memory_after_OFF (pin-switching) which needs 3 (SMD) components to be mounted. Use a pair of +3 spectacles.

But it is a great reward in itself when you have made your first own driver. I like letting my light run down to watch the stepwise dimming functioning (there is appr. 3 hours of light left after the battery reach 3V on max).

Thanks sixty. Maybe you already posted it, but I'll be interested to see how you accomplished this. I really don't know much when it comes to electronic components, but I'm trying to learn. I'll just stick with the basics first (not physically altering the drivers that arrive), and then maybe move on to adding capacitors and such.

Welcome JonnyC. Good to have you here, I hope you enjoy your stay.

Aloha and welcome to BLF JonnyC!

I received a bunch of 101-AKs last Tuesday, all were equipped with ATtinys. Ordered on December 26.12., received on 10.1. KD really seem to have streamlined their delivery process.

If anybody's interested in news from the PIC port, I have given up on the open source tool-chain. SDCC just isn't anywhere near GCC when it comes to code quality or features. I switched to Microchip's Hi-Tech compiler, which also sucks hard enough to pull golf balls through a garden hose, but at least it produces working machine code.

So far I managed to implement timer-interrupt based PWM and something analog to the watchdog-timer ISR I used in the AVR version. It looks like I can use the same basic architecture as in the original BLF-VLD. Today I wanted to test the PWM, so I copied some mode functions over from the AVR version and they just worked without any changes. I'm almost tempted to try keeping a common code base between AVR and PIC...

That sounds very good (given my growing collection of PIC based drivers).

But Hi-Tech compilers did not used to come cheap! (I have used Hi-Tech C compiler in the past so I know that Aussee compagny, there were also some bugs....., but the firm was always responsive and fresh to do corrections).

How much would the new expences be to cover the PIC development (lightest set-up)?

Happy to see that you keep up your enthusiasm despite job-hunting and perhaps little interrest from the forum - not so many with MCU programming experience, I think.

Hi-Tech's "Light" version is free, but the produced code size is atrocious. I couldn't get the driver to fit into the program area, even with just a single mode function compiled in. Using the "Demo" version, I still got 15% free space, and that is with all available mode functions added. So it seems like I won't be allowed to distribute compiled hex-files. Maybe we can find somebody with a Pro license to build these for us, so they can be distributed legally.

Some good news. Today I felt a bit daring and just copied the missing parts of code over from the AVR source. After adding some functions for compatibility (mostly EEPROM stuff) and changing register names, I managed to compile the driver and it just worked. So far, all the mode functions and switching between standard and extended mode groups are working. Only mode programming is broken, but that shouldn't be too hard to figure out. I'm really surprised at how easy it was to port this thing.

Now I have to find a way to flash the program into a real driver PCB. So far, I only tested it on my breadboard model. None of my PIC-based driver PCBs will allow me to use the debugging clip, as the MCU is always obstructed by other components. I think I'll have to glue something together from two connecting plugs with 1.27mm pitch.

Thanks for that report!

That confirms my worries; I guess I'll not go that way and stick to AVR instead. Fortunately AVR drivers are still available.

sixty545: I edited my post; It now has a working link.

So, what we have now for KD SKU S009742 is:

delivery date, version

nov.22 105 ATtiny13A sixty545

dec.16 105 Attiny13

dec.27 105A PIC sixty545

dec.28 105A PIC for the 5-pack

jan.03 105A PIC pipopopo

jan.14 105 ATtiny13 DrJones

jan.27 105C ATtiny13A Nautic

mar.1 105C ATtiny13A sixty545

mar.4 105C ATtiny13A Buwuve

maybe not a lottery any more...

[edited]: added input from DrJones. Could be that the 105A only was delivered in a time window dec.27 - jan.03

[edited jan.27]: added Nautic, looks like PIC is ended, but new type 105C (for the moment), dare to order, now let's see...

[edited mar.1]: added sixty545, got them eventually, was 105C fortunately.

[edited mar.4]: added Buwuve 105C

That is true for 7135 based drivers, but there is only one AVR controlled boost driver I know of, the NANJG-112A. Unfortunately, this one is nowhere to be found anymore.

sixty545: Add these:

delivery date

dec.16 105 Attiny13

dec.28 105A PIC for the 5-pack (doh...)

@Tido: I'm more into 18650 lights anyway.

I wonder how difficult it is to build a reasonably good 3A buck driver (for XM-L on 2*18650) with a µC though...