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

863 posts / 0 new
Last post
sixty545
Offline
Last seen: 1 year 7 months ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

DrJones wrote:

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  Undecided

[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

Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

DrJones wrote:

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

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.

DrJones
DrJones's picture
Offline
Last seen: 5 years 4 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

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...

boffid
Offline
Last seen: 6 years 7 months ago
Joined: 01/15/2011 - 11:54
Posts: 12
Location: Finland
So, what we have now on KD SKU S009742 is.. My 5-pack delivered last week was with PICs. Ordered them early this year. Too bad, I'd much prefer atmels too.
sixty545
Offline
Last seen: 1 year 7 months ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

The picture of the 5-pack SKU: S009835 at KD is in fact showing the 105A with PIC !

The picture of SKU S009742 shows 105 with ATtiny13.

I can tell because I have both and the numbers are printed at different spots.

[Edit:] And welcome, boffid !

boffid
Offline
Last seen: 6 years 7 months ago
Joined: 01/15/2011 - 11:54
Posts: 12
Location: Finland
A very good point. By looking closely at the pictures they are indeed different! One seems to have an empty place for a resistor (besides the mcu) while the other looks like having a cap and no place for resistor. Time to order some singles perhaps..
Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Good news, everyone. Although I still haven't managed to teach the toaster to feel love, I made some good headway on the BLF-VLD-PIC front. I've flashed a NJG-18 with the driver code and the result was better than expected. The PWM frequency is high enough not to result in any visible flicker (somewhere between 500Hz and 1kHzh) and mode programming actually works. The lowest low isn't anywhere near of what can be achieved with the Atmel's hardware PWM, but maybe I can find a way to work around that. 

On a side note, did you ever notice that short blink some flashlights make when the mode memory kicks in? I used to think this was a deliberate feature, but it actually is a result of the missing hardware PWM. Interrupts have to be disabled during EEPROM writes, so the interrupt driven PWM gets suspended.

sixty545
Offline
Last seen: 1 year 7 months ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

Good news indeed.

Yes I saw the memory blink using the AK-47C. But the NANJG 105A also have memory snap-in after 2 sec. but don't blink!

Don
Don's picture
Offline
Last seen: 11 months 20 hours ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

Can anyone suggest why the Mr.Lite J4 driver will only strobe on 14500 (This is the same driver as the BLF AA-Y4E but starts on high. It works fine with NiMH, but not with 14500 where all it'll do is strobe. I'm probably going to replace the driver anyway since I accidentally dedomed the XR-E in it and swapped in a reflector and an XM-L but if a quick spot of solder somewhere can sort out the existing driver, it would be useful to know. I can't make it strobe with an NiMH.

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

I don't see any voltage monitoring circuitry on the board, so it's unlikely that the driver software detects an overvoltage situation. From the software's point of view, everything is fine as long as the MCU gets enough power to run. Maybe the boost circuit is broken and shuts down when it detects a too high input voltage, then starts up again, shuts down... and so on.

But this is just idle speculation, I'd need to prod around the PCB with some measuring equipment before I could say anything definitive.

Don
Don's picture
Offline
Last seen: 11 months 20 hours ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

Tido wrote:

I don't see any voltage monitoring circuitry on the board, so it's unlikely that the driver software detects an overvoltage situation. From the software's point of view, everything is fine as long as the MCU gets enough power to run. Maybe the boost circuit is broken and shuts down when it detects a too high input voltage, then starts up again, shuts down... and so on.

But this is just idle speculation, I'd need to prod around the PCB with some measuring equipment before I could say anything definitive.

 

That sounds like a lot of work.

If you want it for interest, I can send it to you once I've done a driver swap in the light.

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Thanks for the offer, but it would probably just end up in a drawer and get thrown away in the end, when they ship me of to a retirement home.  Forty years from now...

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

I received my driver from Shining Beam (which he ran out of stock of as it's no longer on his site).  It's a NANJG 101-AK with 4x7135's and an Atmel ATtiny13A.

I have been having a hard time keeping up with all of the information here as I'm really starting out from scratch on any of this stuff.  So before I even dive into the programming I need to understand how the circuit is setup.  There is one capacitor (brown SMD at C1) and two resistors (R1 10k, R2 3k), along with a diode.  Referencing this diagram from a similar driver, found in the first post of this thread http://www.candlepowerforums.com/vb/showthread.php?t=192206&page=1, it seems as though the capacitor isn't used to condition any signals but to possibly maintain power to the MCU if the battery disconnects for a slight second (it's not very big, so I don't know how long it could power it.

PB1 (pin 6) is used with PWM to switch on the 7135's to drive the LED.

PB2 (pin 7) is connected to R1 (which connects to Vcc) and R2 (which connects to ground).  Is this used for low-voltage monitoring?  If so, how exactly does this work?  I can't quite understand how the resistors are hooked up and what effect they would have.

PB4 came soldered to GND I assume to pull the pin to low triggering the MCU to keep us in a 3-mode group.  After removing the solder, the light had more modes, although I couldn't quite figure out what the sequence was (although I assume there are 3 to 4 groups of modes or something with the ability to switch in between).

 

So I guess my last questions are, what capabilities does this board have without modifying it?  Can that capacitor actually be used to determine short clicks vs. long clicks?  Can PB2 be used to determine voltage levels, I assume through ADC?  And if so, how do I even know to look for on PB2?

Tido, by the way, I downloaded your code and I must say I am really impressed.  I'm just learning C and bitwise stuff, so I can mostly understand it, but it is really well organized and commented.  I think this would be a huge hit over on CPF.

- Jon

Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

JonnyC wrote:

I have been having a hard time keeping up with all of the information here as I'm really starting out from scratch on any of this stuff.  So before I even dive into the programming I need to understand how the circuit is setup.  There is one capacitor (brown SMD at C1) and two resistors (R1 10k, R2 3k), along with a diode.  Referencing this diagram from a similar driver, found in the first post of this thread http://www.candlepowerforums.com/vb/showthread.php?t=192206&page=1, it seems as though the capacitor isn't used to condition any signals but to possibly maintain power to the MCU if the battery disconnects for a slight second (it's not very big, so I don't know how long it could power it.

The diode provides polarity protection for the MCU, the capacitor is there to filter out noise on the power supply line. Its job is to stabilise the supply voltage in case of very short (< 1ms) voltage sags. It won't be able to keep the MCU powered for more than a few milliseconds, especially if it also gets drained by the voltage divider, which is what the resistors are doing.

Quote:

PB1 (pin 6) is used with PWM to switch on the 7135's to drive the LED.

PB2 (pin 7) is connected to R1 (which connects to Vcc) and R2 (which connects to ground).  Is this used for low-voltage monitoring?  If so, how exactly does this work?  I can't quite understand how the resistors are hooked up and what effect they would have.

Yes, the two resistors form a voltage divider. It is used to bring down the supply voltage into the 0V - 1.1V range, so it can be measured by the MCU's analog-to-digital converter. If you are interested in how this works, please take a look at the README, where I tried to explain things in more detail.

Quote:

PB4 came soldered to GND I assume to pull the pin to low triggering the MCU to keep us in a 3-mode group.  After removing the solder, the light had more modes, although I couldn't quite figure out what the sequence was (although I assume there are 3 to 4 groups of modes or something with the ability to switch in between).

I would guess that the drivers from shiningbeam use either a custom firmware or the firmware found in the AK-47s. The famous stars are just connected to I/O pins and the MCU basically checks which pins are pulled to ground on start-up. The mode group is then selected on this data. You could try soldering other I/O pins to ground and see if the mode group set-up is changing.

Quote:

So I guess my last questions are, what capabilities does this board have without modifying it?  Can that capacitor actually be used to determine short clicks vs. long clicks?  Can PB2 be used to determine voltage levels, I assume through ADC?  And if so, how do I even know to look for on PB2?

The capacitor is much too small for that and besides, it would need very good fine tuning of the components used to get mode switching via brown out detection working. I gave it a try some time ago and got nowhere. If you want the short/long power off distinction, the only reliable way is to use the resistor-diode-capacitor circuit we have discussed earlier in this thread. Take a look at this post on how to do it in an incredibly beautiful way.

Quote:

Tido, by the way, I downloaded your code and I must say I am really impressed.  I'm just learning C and bitwise stuff, so I can mostly understand it, but it is really well organized and commented.  I think this would be a huge hit over on CPF.

Thanks for your praise. Personally, I think it has way too much #ifdef'ed code blocks, but it is the only way to cram this much configurable functionality into the tiny program space. The comments are as much for my own sake as they are for others. This was my first AVR based project and it really helps to "mumble along" to yourself in this form, while trying to figure out how to do things on a new system.

As for the CPF, the guys over there are free to use the code, as is everybody else. It's open source, after all. But I'm really put off by the general sentiment and rampant pack mentality over there, not to mention the petty power-crazy moderators.

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA
Tido, you're awesome. Thanks for the detailed response! You answered all of my questions. I now understand that that the resistors are used to divide the voltage (down to 1.15v on a 5v source), I just have to try and understand how voltage dividing works -- but I'll figure it out. I agree with your CPF comment, at least with the moderator issues. Once my cable and programmer show up, I'm going to try out your code. I may try playing around with having the number of short presses you do put you in that mode number, but I'll have to look at your code in more detail. Thanks again!
JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Well, I received everything that I needed.  I assembled the USBtinyISP programmer, connected the clip from Ebay to the correct pins inside the USBtinyISP and connected it up to the ATtiny13A.  The clip connected easier than I thought and avrdude was able to connect property to the MCU.  Decided I would be gutsy and flash a compiled hex after changing a few parameters in Tido's code, and success - it flashed!  I didn't think it would happen this easy.

I connected an XP-G mounted on a heatsink to the driver board, connected up a battery and gave it a shot.  It turned on! (sorry, but I didn't even expect this to happen).  I tried to cycle through modes, but it seemed to stay on one mode.  The mode seemed like some type of SOS, but I couldn't notice any pattern. So I decided to program it again with the PROGRAMMABLE define disabled.  Flashed it again successfully, but when I connected up the battery, the LED went on for a split second then cut out.  Checked the connections, tried a different XP-G, and no dice.  I reflashed it with the Simple.hex file, and no power.  I think I may have somehow killed the MCU or something on the board.

I really rushed this, kind of taking a shotgun approach, because I knew the driver and LED were cheap and figured "what the heck".  Shining Beam doesn't have this driver on his site anymore, but I should be receiving some other boards like them from DX in 1 to 2 years (ha).  Once I get those I'll take things slower.  I should really get a bread board with a switch to turn the light on and off as my jerry rigged way of doing it isn't the greatest for testing it out, let alone seeing if the mode setup will work out, and I can't install the setup into my Mag host until it's flashed with the right program and set to be installed for good.

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Well, I will certainly do some more reading.  I have a feeling I have to set some fuses and do some more complicated stuff.  Right now, flashing it with the hex file from either Simple or Programmable result in the LED not turning on.  However, it does turn on when flashed with Fixed Modes, although it's only running at about 100mA, so I assume it's starting in a low mode and is unable to switch to another mode.

Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

My first guess would be the fuses. Please try using '-Ulfuse:w:0x79:m -Uhfuse:w:0xed:m' (Brown-Out Detection at 1.8V, 4.8MHz internal clock, Self-Programming and SPI enabled). If this doesn't work, you could try recompiling for ATtiny13A. Maybe the ATtiny13A is not that much of a drop-in replacement for the ATtiny13(V).

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Thanks for help again Tido.

I read the fuses and they where lfuse 0x72, hfuse 0xfd.  I set the fuses to what you provided, which changed the clock and a few other things.  However, there's no difference in how the LED acts.  I compiled your code in AVR Studio set for ATtiny13A, flashed the hex, and no difference.

I might just wait for the drivers from DX to show up and try those.

EDIT: Durrr...I didn't flash the eeprom Silly  Seems to be working now, so time to play around with some different options.

pipopopo
Offline
Last seen: 6 months 3 weeks ago
Joined: 12/23/2010 - 15:07
Posts: 189
Location: EU

seems like more people are programming flahlights

http://www.youtube.com/watch?v=TZ5rtmIpjNw

DrJones
DrJones's picture
Offline
Last seen: 5 years 4 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

I heard about a (hopefully better) C compiler for PICs, MicroC. The demo has a limit of 2KB - enough for the 12F629. Migh be worth a try.

Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Looks like it's Windows only, that's a no-go for me. Besides, if I'm going to use a demo version, I might as well use the one from Microchip. But maybe someone will give this compiler a try, once I get around to cleaning up and releasing the PIC-port.

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

This is so much fun!  I got my first prototype together.  I reduced your code Tido just to make a real simple 3 mode light with no strobes and no programming.  To access the modes, just tap the momentary switch (this is a Maglite btw) the same number of times as the mode you want to access.  Tap once before fully clicking the switch in and you'll go to mode one.  Tap three times before turning it on and you go to mode three.  The nice thing is that the light delays turning on for 250ms.  So if you just woke up in the middle of the night and don't want to have to cycle through modes, ruining your night vision, just tap once before turning on and you go to low (mode one in my case).  If you almost always use the light on max, just set to max and it will always turn on at max.  The nice thing is that you don't have the 2 second delay before it programs the mode like the driver comes stock.  Once the light is on you know the memory is stored, so you can turn it on for a split second and then off without having it go to the next mode upon the next startup.

I just want to thank you guys again, this is a really fun little hobby.

EDIT:  I thought this would really only work will with forward-clicky switches, but it could work well for reverse-clickys as well, you would have to tap 2 times once the light is on to access mode 1, 4 times for mode 3 (although you could think of 1 tap as going to the saved mode, 2 taps for the 2nd slot, etc.)

Piers
Offline
Last seen: 2 years 4 months ago
Joined: 01/18/2011 - 20:31
Posts: 896
Location: Bolton, UK

I've just received the two  "AMC7135*8+MCU 1100mAh 5-Mode Circuit Board SKU: S009742" from KD they are both 105C's with the Atmel chip.

 

The order was placed on the 21st so only took a week to arrive, which is rather good.

sixty545
Offline
Last seen: 1 year 7 months ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

Pook wrote:

I've just received the two  "AMC7135*8+MCU 1100mAh 5-Mode Circuit Board SKU: S009742" from KD they are both 105C's with the Atmel chip.

 

The order was placed on the 21st so only took a week to arrive, which is rather good.

That was really fast!

I hope for you that they are 2800 mA Wink

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Hey guys,

Now that I have things working great, I'm thinking about adding a secondary switch on my Maglite.  The main switch will still act as the main power switch, but a momentary switch would also be installed in order to facilitate mode switching.   I'm thinking this switch could be setup with a pull-up resistor to one of the PCINT pins.

Looking at the reference sheet, it seems as though I could have the ISR trigger when the pin switches low to high or high to low.  Is that correct?  If so, would I be able to recognize how long the secondary button was pushed?  This would make it really easy to enter programming mode and be able to select a new mode.

Thanks,

- Jon

LobsterX
Offline
Last seen: 5 years 2 months ago
Joined: 12/27/2010 - 06:07
Posts: 15
Location: Singapore

ordered: 25 Jan 2011

Recieved today.

 

1x 106 ATtiny13A

2x 105A PIC

 

how come I got mixed ones?

Your ATTITUDE Determines Your ALTITUDE

sixty545
Offline
Last seen: 1 year 7 months ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

LobsterX wrote:

ordered: 25 Jan 2011

Recieved today.

 

1x 106 ATtiny13A

2x 105A PIC

 

how come I got mixed ones?

Good grief.

So it's not over yet (if ever) with the PIC's. It looks like they have a lottery mill they draw them from.

I have 3 pc on order, packing right now. I pray they are ATtiny13.

LobsterX
Offline
Last seen: 5 years 2 months ago
Joined: 12/27/2010 - 06:07
Posts: 15
Location: Singapore

but considering I don't do "reprograming", they should be fine for me since the functions are similiar...

 

I wonder if we can post them a note to request for "specific" models instead of waiting for lottery for 105A, 106 and 105C[I have not seen this,but I heard the stars have no functions]

Your ATTITUDE Determines Your ALTITUDE

JonnyC
JonnyC's picture
Offline
Last seen: 4 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

FYI, I ordered 3 x SKU 6190 from DX.  Took almost a month to arrive from the shipping date, but they are all Atmel ATtiny13A's Smile

Pages