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)

Tido, I programmed the same program into the BLF AA-Y4E as I did to the AK-47 board, but in the AA-Y4E it only starts up in the first level and do not react to tapping. I tried to remove brown-out detection in high fuse but it did'nt help. With brown-out detection the light flashes a few times (fast) at each start-up and is then steady.

Can you think why it does'nt react on taps as the AK-47 board? (I have re-fitted the two components that were removed to make space). I suspect it has something to do with slow rising and falling of the voltage to the ATtiny due to the PAM 2803 (but nkildal's BLF AA-Y4E worked).

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

It sounds like the buffer cap keeps the µC running for too long when the light is switched off. Are you sure you re-soldered the components correctly? Looking at the last picture nkildal posted, the black parts on the left of the µC look like diodes. The lower one seems to be part of a voltage monitoring circuit, which would help draining the cap. If you soldered it back the wrong way around, the cap would be isolated from the circuit and retain its charge much longer.

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

The diode was unsoldered in one end only. It comes (with kathode) from pin 2 on tiny13 in parallel with a 100kOhm. Where they end I have not found out yet. Perhaps the tiny13 is active in draining the capacitor?. The upper diode feeds the tiny13 pin 8 from VOut on the PAM2803. The only thing I changed from the original SW was the timing (PWM appr. 1 kHz, ON appr. 15 us in lowest mode). The PWM seems to work fine all the way to the LED's negative end, only the tapping, slow or fast, does not work.

The voltage to tiny13 collapses in about 10msec so it is unlikely that the watchdog should count for 2 sec

 

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

I'm afraid that I have destroyed the solder pad under one end of the capacitor near pin 4 on tiny13. If that is the reason for malfunctioning then I apologize, Tido.

Now I have no idea of where that capacitor goes to, I can't see the trace disappearing under the tiny13. nkildal, do you by any chance have an BLF AA-Y4E open so you can help me out?

Edit: I think I have found it - it goes to the end of the diode and 100 kOhm from pin 2 on tiny13 where I found no connection before!

nkildal
Offline
Last seen: 1 year 1 week ago
Joined: 12/02/2010 - 03:13
Posts: 36
Location: Denmark

sixty545 wrote:

nkildal, do you by any chance have an BLF AA-Y4E open so you can help me out?

I'm at work right now (probably shouldn't be following the forum then Smile ) but I would be happy to investigate it, as soon as I get home.

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

nkildal wrote:

sixty545 wrote:

nkildal, do you by any chance have an BLF AA-Y4E open so you can help me out?

I'm at work right now (probably shouldn't be following the forum then Smile ) but I would be happy to investigate it, as soon as I get home.

I'm happily retired, so I can do what I want, but I know your problem Wink. As I added in my previous post I think I found it but thank's anyway, now let's see what happens:

Nothing!. Re-connecting the condenser did'nt help.

Perhaps I should try the hex-files that nkildal got to work. Can you mail me them, nkildal?. Then I could see if it's a HW or a SW problem.

nkildal
Offline
Last seen: 1 year 1 week ago
Joined: 12/02/2010 - 03:13
Posts: 36
Location: Denmark

sixty545 wrote:

Perhaps I should try the hex-files that nkildal got to work. Can you mail me them, nkildal?. Then I could see if it's a HW or a SW problem.

Yep - I will send them to you, as soon as I get home...

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

nkildal wrote:

sixty545 wrote:

Perhaps I should try the hex-files that nkildal got to work. Can you mail me them, nkildal?. Then I could see if it's a HW or a SW problem.

Yep - I will send them to you, as soon as I get home...

Thank You for the files and the very fascinating soft-beacon function that You invented. One can almost feel the light beam sweeping by...

Your files worked right away, and mine also, after playing around with some editing - I never found out what the problem was.

About the mode shift:

I got an UltraFire WF501B with MC-E today and loved the mode shift, the mode is stored about half a second after turn-off. You don't have to think about starting a 2 sec period before You can switch to next level.

I think this is ideal in a light with only level shifts. If there are other functions, seldom used (Beacon etc.), perhaps it would be better to have no memory and start up in medium, followed by high - low1 - low2 - Beacon  or whatever.

I wonder if there is time to write the eeprom during a brownout?. How do we address that?, Tido, agenthex, anyone?

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

Release v0.3 is ready for download, grab it here. Here is the changelog:

 

2010-12-09  Tido Klaassen  <tido@4gh.eu>

        * BLF-VLD: release v0.3
       
        * driver.c: mode functions can now be en/disabled without rearranging
        modeline offsets
       
        * driver.c: EEPROM image configurations containing disabled mode
        functions will result in compile time error

        * driver.c: added support for battery monitoring and handling of low
        battery voltage
       
        * driver.c: added wear levelling to mode switching to protect EEPROM

        * driver.c: added timer prescaling config option

        * driver.c: added mode functions for SOS, alpine distress signal and
        fading beacon

        * README: added info on how to set up battery monitoring

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

sixty545 wrote:

I got an UltraFire WF501B with MC-E today and loved the mode shift, the mode is stored about half a second after turn-off. You don't have to think about starting a 2 sec period before You can switch to next level.

It would take some modifications to the stock PCBs for this to work.

 

sixty545 wrote:

I think this is ideal in a light with only level shifts. If there are other functions, seldom used (Beacon etc.), perhaps it would be better to have no memory and start up in medium, followed by high - low1 - low2 - Beacon  or whatever.

You could build a "simple" driver without the extended mode group and disable mode memory with the NOMEMORY #define.

 

sixty545 wrote:

I wonder if there is time to write the eeprom during a brownout?. How do we address that?, Tido, agenthex, anyone?

This cannot be done with the brown-out detection. The BOD works by stopping the µC once Vcc drops below the configured threshold, and resetting it when the power comes back. The only difference to a normal start-up is a flag set in a status register. Besides, to use the BOD for switching modes, the buffer cap would have to be chosen with the exactly right value, which depends on things like power consumption of the µC and resistance of the battery monitoring circuit. (BTW, I did a calculation some time ago on how long a 100nF buffer cap would keep the µC running. The voltage divider alone would drain it below the µC's minimal operation voltage in about 2ms. I don't think it's possible to use BOD for mode switching on a stock 101-AK.)

The only way to get this working would be to add a really big cap (10-100µF), remove the voltage divider and add a wire from the battery to one input pin, bypassing the protective diode. This way an interrupt could be triggered when the light is switched off (battery voltage is zero, but µC can still run from the buffer cap). If the power comes back before the cap is drained, it was just a short tap. But this would take some fundamental changes to the driver software to get it working.

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

Hi Tido,

I think You just disencouraged me to dig further into this. But as I know myself I can't let it be.

I thought about using the Brown-out interrupt vector rather than polling the flag BORF. If I could find out how to catch Brown-out interrupt (I don't know much about this special processor) I would turn off the load and count 4 watch dog interrupts (1 sec) and then store the tap_none flag to the EEPROM. I thought that it could be that simple.

I went through my collection of lights with memory and found 7(6) that saves the mode after power-down and only 3(2) that does it after power-up:

Store mode after power-down:

TrustFires: EF23: 1 sec,  F20: 0.5 sec, Z1: 1 sec

UltraFires: C3 SS: 10 sec, another C3 SS: 5 sec, 501B MC-E: 2sec

Skyray S-A1: 1 sec

Store mode after power-up:

Tank007 TK-566: 2 sec, TrustFire R5-A3: 2 sec, Romisen RC-C6: <1 sec but always go to next.

Now I should disassemble the first group and spy on the configuration, but the only thought of it......

 

I am not the only one that like store after power-down (=only one tap for next mode), this is from brted's review of UltraFire 501B-MC:

Pros:

  • Bright
  • Cheap
  • Mode memory works well  <<
  • Nice Low
Tido
Offline
Last seen: 3 years 2 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

I'd be glad if you proved me wrong, as I also prefer this kind of mode switching. But the PCB needs to be designed for this and the available driver boards using an ATtiny just aren't.

Using an interrupt routine to trigger on the BOD is impossible, as there is no such interrupt. When Vcc drops below the threshold, the µC's internal reset line is pulled low and kept this way until Vcc reaches operating level again. BORF is there to inform the program that it is not starting up from a complete loss of power. This is useful, if there are peripheral components that need to be initialized or explicitly reset in such a situation.

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

That's too bad, but thanks anyway for clarifying thing to me Smile

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

Tido wrote:

The only way to get this working would be to add a really big cap (10-100µF), remove the voltage divider and add a wire from the battery to one input pin, bypassing the protective diode. This way an interrupt could be triggered when the light is switched off (battery voltage is zero, but µC can still run from the buffer cap). If the power comes back before the cap is drained, it was just a short tap. But this would take some fundamental changes to the driver software to get it working.

Could'nt we just use a diode from plus on ATtiny (pin8) to a capacitor to ground, then a few hundred kiloOhms from the capacitor to an unused input pin, fx. PB3 (pin2) . Then at power-up, if the pin reads as '1' there was a short tap and if '0' there was a longer pause.

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

Sure, that would work, if it takes longer to charge the empty capacitor to logic high level than the program needs for starting up and reading the pin. Or we could charge the capacitor through the pin while the light is on and read the state on start up. I just measured the resistance of the I/O pins when the chip is powered down and they are tri-stated, so there would be no discharging through the ATtiny.

Problem is, this would require altering the PCB and a significant rewrite of the driver software.

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

Yeah, something strikes me!. Do you remember my problems with the Manafont BLF? I had unsoldered two components. A diode was going from pin 2 in parallel with 100 kOhm, they were connected to the capacitor at the other end of the ATtiny and nowhere else.

I think that those components are just what we are talking about!!!!

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

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.

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

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

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

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.

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

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.

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

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

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

Tido wrote:

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

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

Mode memory after power-down.

Tido wrote:

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.

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.

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

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.

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

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.

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

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.

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

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.

brted
brted's picture
Offline
Last seen: 5 months 1 week ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

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?

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

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.

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

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 Cry (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?

Pages