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

863 posts / 0 new
Last post
Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Okay, I've got this new programming scheme working and it looks like a winner to me. The extended mode list is hidden in normal use, but can be accessed without too much hassle. At the same time it's nearly impossible to reprogram a mode slot accidentally. It was even very hard to do it on purpose without counting the seconds on a watch, until I added some visual timing aid when leaving the extended mode selection.

I think I'll clean up the code a bit and release it as v0.2. I hope you guys will get your programming hardware soon, so we can discuss the further development based on real experience instead of all the theoretical musings.

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

I went ahead and bought the clip and programmer today. Should arrive in a couple of weeks and then we'll see what happens. I already have an extra AK47 driver to test. Once we get this running it will be good to put together a complete tutorial on how to do it, software and hardware needed, etc.

sixty545
Offline
Last seen: 2 weeks 17 hours ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

I'm a week ahead of you, ha ha Wink

and ordered 4x101-AK too.

exciting...

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

Good! I'm going to need some help.

Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Version 0.2 of the BLF-VLD is ready for download here. There have been some substantial changes, especially for the programmable version of the driver. Light levels are not freely programmable anymore, but can be selected from a predefined set of nine logarithmically spaced levels and a few strobe modes. The programming procedure has been simplified a lot, thanks to agenthex's suggestions.

The driver can also be built in two non-programmable versions. The first gives access only to a subset of modes defined at compile time. The second version also has a fixed subset of modes in the standard mode group, but can access all modes defined in the extended group by switching modes x times in a row (configurable at compile time). This way a flashlight may have just three or four default light levels, but special modes like moonlight mode or strobes are still accessible without getting in the way on everyday use.

sixty545
Offline
Last seen: 2 weeks 17 hours ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

Thank's for the new SW, Tido.

I expect my programming equipment at my door in about one week.

I have calculated a little (or more) around the actual output from the emitters taking into account the degrading of output with temperature. There is quite a loss at full power.
I presume using a NANJG 101-AK with 1050mA for XR-E, 1400 mA for XP-G and 2800 mA for XM-L and that the LEDS reach about 125 degree C at full power. If DC was used instead of PWM one woud have to degrade also from the fall in efficacy with current.
That gives the following result if you want a doubling of light for each step:

XP-E Q5 at max 1046 mA:
Flux(LM) mA  output code 
191     1046   255
 96       446    109
 48       210     51
 24       103     25
 12        51     12,4
  6        25.2    6.1
  3        12.6    3.1
 1.5       6.3     1.5
XP-G R5 at max 1395 mA:
Flux(LM) mA   output code
341       1395    255
171        606     111
85         288      53
43         141      26
21.3        70      12.7
10.7        34.6    6.3
5.3         17.2    3.2
2.7          8.6     1.6
XM-L T6 at max 2790 mA:
Flux(LM) mA   output code
629       2790    255
315       1127    103
157        527     48
 79        256      23.4
 39        126      11.5
19.7       63       5,7
 9.8        31       2.9
 4.9        16       1.4

Ofcourse you have to round the output code.

(corrected to PWM).

agenthex
agenthex's picture
Offline
Last seen: 6 years 2 months ago
Joined: 07/14/2010 - 04:49
Posts: 3070
Location: Merica

In "pwm" the current is pulsed at max with the given % duty cycle so it's close to a completely linear relationship. The cree graphs are for a steady current, not any waveform with given average current density.

Reading this makes you smarter: http://lesswrong.com/

sixty545
Offline
Last seen: 2 weeks 17 hours ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

I agree. In PWM the output versus current curve can not be used, only the point for the drive current,  which leaves the degradation due to temperature. I will have to re-calculate for PWM. But linear it is certainly not.Laughing

I have now corrected the numbers in the former mail.

agenthex
agenthex's picture
Offline
Last seen: 6 years 2 months ago
Joined: 07/14/2010 - 04:49
Posts: 3070
Location: Merica

How are you assuming the junction temperature?

Reading this makes you smarter: http://lesswrong.com/

sixty545
Offline
Last seen: 2 weeks 17 hours ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

The assumption is that at full power the junction reach 125 degr.C. That of course depends heavily on the construction of the light. Perhaps 125 is a little too high looking at Don's measurements from turn-on until 2 min. (this looks more like 90-80% as for 100-120 deg.C)

The Cree curves output vs. current give the output at full current before degradation from temperature.

Using the Cree curves for nominal output vs. temperature I find the derate values at 1/4 - 1/2 - 3/4 - full power (AVG. current) corresponding to 50 deg, 75 deg, 100 deg and 125 deg C.
Then I use curve fitting to find the formula for nominal output vs. avg. current.
To find Lumens from this you just have to multiply with the actual bin's nominal Lumen output.

Now I just have to get my programmer board and clip and 101-AK to try it out.
Ebay and DX, come on!
Can't wait...

agenthex
agenthex's picture
Offline
Last seen: 6 years 2 months ago
Joined: 07/14/2010 - 04:49
Posts: 3070
Location: Merica

My drivers are stuck in pending at DX. Dammit.

 

But...Kinect computer drivers are out (no obfuscation over usb, it seems), so that's something very very cool to play with. $150 for probably the most advanced piece of equipment you can have in your house.

Reading this makes you smarter: http://lesswrong.com/

Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

I just received three 101-AKs and a NANJG-106 from KD (took only 13 days from ordering to get to my doorstep!) and all of them are flashable.

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

Let us know if the NANJG 106 is really 2.8A as it should be. Also I know you will be flashing them, but it would be good to know how the modes are spaced by default and whether they can be changed by soldering to the stars. That could be a really great driver for P7's, MC'E's, and XM-L LED's.

Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

I can't test if it really delivers 2.8A because I don't have any LED capable of handling such a current. It does have 8x AMC7135 in parallel, so it should be a able to regulate at 2.8A. I'll test the modes once I removed the 4 "spare" 7135.

I'm not convinced this will make a good MCE/P7/XM-L driver, as it can only be used with a single Li-Ion cell. There are also no buffer caps for the 7135, which are needed according to the datasheet.

phlowcus
Offline
Last seen: 1 year 4 months ago
Joined: 06/08/2010 - 07:28
Posts: 421

Tido wrote:
I'm not convinced this will make a good MCE/P7/XM-L driver, as it can only be used with a single Li-Ion cell.

Yes, it will run out of regulation rather fast and act as direct drive, only less effective due to the AMC's own voltage drop.

Tido wrote:
There are also no buffer caps for the 7135, which are needed according to the datasheet.

Hm, I think they may be only needed when used with a switching power supply?

Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

brted wrote:

Also I know you will be flashing them, but it would be good to know how the modes are spaced by default and whether they can be changed by soldering to the stars.

 

I just did a quick test and the stars work just like they do on the AK-47. You get exactly the same mode groups.

Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

phlowcus wrote:

Hm, I think they may be only needed when used with a switching power supply?

 

One version of the datasheet states that a 0.1µF ~ 1µF buffer cap should be added to the output pin if the LED is not mounted on the same PCB. It's probably true that this will only have an effect if the supply current is not steady, but with PWM we're having a switching frequency of up to 20kHz.

I'm just a software guy, so when the datasheet strongly recommends adding this caps, I try sticking to it. Do we have an EE around here who could comment on this?

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

Tido wrote:

I just did a quick test and the stars work just like they do on the AK-47. You get exactly the same mode groups.

That is so awesome! Thanks for checking, Tido!

sixty545
Offline
Last seen: 2 weeks 17 hours ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

Tido wrote:

phlowcus wrote:

Hm, I think they may be only needed when used with a switching power supply?

 

One version of the datasheet states that a 0.1µF ~ 1µF buffer cap should be added to the output pin if the LED is not mounted on the same PCB. It's probably true that this will only have an effect if the supply current is not steady, but with PWM we're having a switching frequency of up to 20kHz.

I'm just a software guy, so when the datasheet strongly recommends adding this caps, I try sticking to it. Do we have an EE around here who could comment on this?

The capacitor is used to limit oscillations that can occour when switching large currents through inductive paths like a long wire. The oscillations produces voltages that could be destructive for the components and/or violates EMC regulations. EMC = Electro-Magnetic Compatibility. This concerns noise disturbance of other electronic equipment. A driver without the capacitor could make a "dirty" light.

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

The clip showed up today. Hopefully I'll get the USB stick soon and be ready to try this thing out. If I do a programmable UI, I'm thinking I'll set up 4 modes and set them L-H-L-H to start with. Then if I need a medium or a different Low, I can set that. But L-H-L-H will be like having a 2-mode light with an option for 4 modes.

sixty545
Offline
Last seen: 2 weeks 17 hours ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

All my stuff has arrived. I just can't find the time to test it the first few days Cry

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

I got my programmer today, but I'm not having any luck yet. I downloaded WinAVR first, then Eclipse C/C++ and configured it using instructions here:

http://interactive-matter.org/how-to/developing-software-for-the-atmel-avr-with-avr-eclipse-avr-gcc-avrdude/

But when I tried to get the settings from the device, I got an error. So then I started using AVRdude to see if I could read the chip and I don't think I'm getting a connection. I don't know if it is the driver or the clip, but I get one message when I have a bad connection (same message I get when I don't even connect to the clip) and another when I am connected, but it still can't seem to find the chip. I'm using USBasp as the programmer which I guess is right for the thing I got from eBay.

There is a jumper on the board that I am leaving in place. Also, I hope I didn't fry the board but one time I was grabbing it and my finger was across the 3 resistors near the USB jack and they felt very hot or maybe even shocked me. Also I guess it is okay to pull the programmer out of the USB port whenever I want? And I can connect or disconnect the flashlight driver while it is plugged in? Also does it matter which way the clip is attached? I've tried both ways to make sure I'm not clipped upside-down.

 

This is the no connection error (programmer has a green LED lit, a red LED flashes briefly when I send this command):

C:\>avrdude -c usbasp -p t13

avrdude: warning: cannot set sck period. please check for usbasp firmware update
.
avrdude: error: programm enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

 

This is the other one I get when I seem to have the clip on the chip correctly (green light is off):

C:\>avrdude -c usbasp -p t13
avrdude: error: could not find USB device "USBasp" with vid=0x16c0 pid=0x5dc

agenthex
agenthex's picture
Offline
Last seen: 6 years 2 months ago
Joined: 07/14/2010 - 04:49
Posts: 3070
Location: Merica

Did you reconfigure the clip's pinout? The pattern on the output of the 10-pin avr header doesn't magically match the chip's pins.

Reading this makes you smarter: http://lesswrong.com/

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

That's probably a big part of the problem. The programmer came with a 10-pin cable and the clip came with an 8-pin cable. Plus, the 8-pin cable is not feeding into slots in position 9 and 10 on the programmer, so I need to undo the connector on the clip's cable and move wire number 8 over to position 9 in order to connect to MISO on the controller.

The programmer circuit board has the following printed, the first column on one side, and the other column on the other side of the board near the connector. The numbers are my guess as to the wire numbers in the ribbon cable.

1MOSIVCC2
3NCGND4
5RSTGND6
7SCKGND8
9MISOGND10

 

The ATTiny13 is configured as follows, using ATMEL's pin numbers. The pin numbers are as follows in this table and the picture. I don't think Pins 2 and 3 are needed for programming the chip:

1RSTVCC8
2???SCK7
3???MISO6
4GNDMOSI5

 

ATMEL TINY13A pin numbers

agenthex
agenthex's picture
Offline
Last seen: 6 years 2 months ago
Joined: 07/14/2010 - 04:49
Posts: 3070
Location: Merica

You'll always need to rearrange the pin wires (almost all of them), there's no way around it. Nobody makes an AVR 10-pin to ATTiny13 clip. Smile Undo the clip, pull everything out, stack them back in right order and crimp again. Forget the numbering for this part, just look at the entirety of the setup and make sure the right pin on the usbavr goes to the right pin on the chip.

 

The little hole/depression on the chip in lower left is likely pin 1.

 

Reading this makes you smarter: http://lesswrong.com/

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

Hmmm . . . I originally guessed Pin 1 based on how the text was printed and figuring the chip was right-side up if you could read the text. But when I connected it that way the green LED would turn off. So when I do it with Pin 1 in the lower left, at least the green LED stays lit, but I still get the no connection error in AVRdude. But connecting the six pins that I think are needed for programming still didn't work, though I also tried all the combinations of Pins 2 and/or Pin 3.

agenthex
agenthex's picture
Offline
Last seen: 6 years 2 months ago
Joined: 07/14/2010 - 04:49
Posts: 3070
Location: Merica

The green led probably indicates powered-on. Not all of the wires need to be connect for programming as it's just serial.

 

Did you recrimp the rest of the wires correctly? Checked continuity w/ meter?

Reading this makes you smarter: http://lesswrong.com/

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

I checked continuity from the USBasp-labelled point to the correct pin on the clip. But I'm not sure the wires in the teeth of the clip are making good contact. Some of the teeth seem a little short. I might have to try soldering the individual ribbon wires to the Atmel chip legs which won't be easy.

Tido
Offline
Last seen: 1 year 6 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

You should first check that all the pins make proper contact. You picture shows that, except for RESET (pin 1) and MOSI (pin 5) all relevant pins are connected somewhere on the PCB, so you won't have to probe the chip's pins with needles or something like that. Also make sure that the target receives power from the programmer and maybe check whether the PCB still works. Applying Vcc to the wrong pins might have fried the chip.

If you can find no problem there, it might be that the chip has its clock fuses set to 1MHz or less. In that case you will have to tell avrdude to use a slower bit clock. Default is set at ~1µs and it's suitable for clock speeds of 4MHz and up. Try -B 0.25 or 0.1 (if your programmer is based on the USBasp, you might need to set a jumper somewhere to enable programming of slow clocked targets).

brted
brted's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

Still nothing. I don't have the AK-47 board hooked up to anything yet, so I can't really check to see if still works, but I did put my NANJG 106 driver back together and it still works (kind of; Low and Medium seem to be the same thing now). I tried the bit rate thing and still got the same error. I also tried soldering to the legs of the Atmel chip and that was pretty hopeless. I actually got one wire on there pretty easily, but when I tried to put a wire next to it, they were bridged. Instead of a clip, it seem like it would be better to have a housing that fits over the chip with wires where each leg goes. Then you could clamp the housing down to make sure there was good contact. Theoretically the clip should work just fine, but it seems so poorly made. Some of the pins are loose so when you pull on the crimped joiner the whole pin comes out of the clip.

Pages