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

[quote=Tido]

If I do that, the compiler (make) will not run properly, I get this message:

Building file: ../driver.c
Invoking: AVR Compiler
avr-gcc -DBUILD_FIXED -Wall -Os -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=attiny13 -DF_CPU=4800000UL -MMD -MP -MF"driver.d" -MT"driver.d" -c -o"driver.o" "../driver.c"

and only one file, driver.d (empty) is made.

I just tried to change to "TCCR0B = 0x02;" - on my machine it builds without problems.

I went into the "Fixed" directory, and used the commands:

make clean
make all 
Building file: ../driver.c
Invoking: AVR Compiler
avr-gcc -DBUILD_FIXED -Wall -Os -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=attiny13 -DF_CPU=4800000UL -MMD -MP -MF"driver.d"
 -MT"driver.d" -c -o"driver.o" "../driver.c"

Embarassed [quote=nkildal]

make clean
make all 
Building file: ../driver.c
Invoking: AVR Compiler
avr-gcc -DBUILD_FIXED -Wall -Os -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=attiny13 -DF_CPU=4800000UL -MMD -MP -MF"driver.d"
 -MT"driver.d" -c -o"driver.o" "../driver.c"

[/quote]

Very strange, when I do exactly the same, it does'nt work. Only if I change back to 0x01.

Well, more stupid than strange - I was in a hurry and put in TCCR0B = 0b00000002 !!! Embarassed

0xEB was not good, the light never came on. I tried 0xED instead and now it reacts on very fast clicks, but it is still a lottery and I keep ending in the extended mode. How do I exclude that?

I remove #define EXTENDED_MODES I guess.

You can set the following in driver.c (line 48-50):

#undef EXTENDED_MODES      // enable to make all mode lines available
#undef PROGRAMMABLE        // user can re-program the mode slots
#undef PROGHELPER          // indicate programming timing by short flashes

Then go into the "Default" directory and do your build there.

Edit: I think we cross posted :-)

Or you could also choose to change how the "Fixed" version is built, by just editing the lines 188 to 193 to your taste:

#ifdef BUILD_FIXED
#undef PROGRAMMABLE
#undef EXTENDED_MODES
#undef PROGHELPER
#define EXTENDED_MODES
#endif

That's the one I had in mind

What voltage is the battery you are using? With my fuse settings, the µC would trigger a brown-out reset at 2.7V. Adding another 0.6V for the drop across the protective diode, your battery would have to be at or below 3.3V.

To build a driver without the extended modes group, just use the "Simple" configuration.

In this case It was a power supply, set to 4.0 V.

After enabling the prescaler in software and using 0x6A and 0xED for fuses the light is now almost perfect. Even the click response got better than before. The PWM frequency is about 260 Hz and there are no flickering to see. It is a 4 level, Simple model with outputs: 200 - 50 - 12 and 3 Lumen. There are almost proportionality between output and battery current so 1 Lumen costs about 5 mA in this light which is an Ultrafire WF-502B with R5.

Now I plan a bigger modding-event (strobe-killing) when my drivers arrives from DX, eventually.....

I have visions of you racing around the countryside hunting down strobes and killing them. ;)

I am totally on board... what do we use? Shotguns, dynamite or nukes? ;-) Death to all strobes (and low PWMs)... I don't even go in clubs and disco's any more... lol

sixty545, could you write up a small summary on which configurations you used and how well they worked? I'm a bit confused by all the information fragments scattered throughout the thread so far . The report about the light not turning on with the brown-out detection set to 2.7V got me a bit worried.

Has anyone played around with the programmable version of the driver yet? I'd really love to hear some opinions about the UI.

Is this related to Lumens-hunting (poor Mr. Lumen)?

No not yet - I would love to give you some feedback on the programmable version, but my BLF AA-Y4E board suddenly died last night (not related to your driver).

I am now waiting for some DX & KD driver boards to arrive so I can continue experimenting :-)

I went through a fast series of experiments and did'nt write them down in a protocol. I used this thread as a sort of protocol. I will not be able to recall the history of combinations (them old grey cells....) but I can try changing the brown-out bits again the next time I'm gonna program and then check if the light will start-up on the 4V power supply.

I'm trying to understand the button click functioning and timing, there are still too many non-reaction-clicks, I could use some hints here.

I found that the low frequency of PWM I have now, makes the digital lightmeter and the multimeter show varying values - I will try setting the CKDIV8 bit in low fuse back to 1 to have a faster frequency again but keep the divide-by-8 in software, let's see how that turns out.

Don't worry more, Tido. I tried the high fuse 0xEB again and this time it started fine. I must have had a broken power lead the first time .

I found out that a PWM period of about 1 msec is a good compromise between problems with narrow pulses (giving less than expected light) and problems with digital measuring instruments showing non-steady readout. I used 4.8MHz oscillator, clock divider = 8 (CKDIV8 = 0 ) and Timer Divider TCCR0B=1 (as in the original SW). Thus the low fuse is 0x69 and high fuse 0xEB.

The algorithm is quite simple. On start-up the program checks if the last time the light was on, it was on for more than two seconds (let's assume this is true for now). It then stores a marker in eeprom, saying that this time it was turned off after less than two seconds. Then it starts a timer and goes on setting up the light. This marker is removed after two seconds have elapsed.

Now let's assume that the light has been switched off before the marker has been removed. When the light is switched on again, the program finds the marker in eeprom and knows that it is supposed to change the mode.

So, you can only change the mode within two seconds after turning on the light and the power has to be off long enough to cause a shut-down or reset of the µC. If you want to change the mode after more than two seconds run time, you first have to tap once to start the two second timing and then again to actually change the mode.

Thank's, I think that really explains what happens.

Looking in the program I found this, are there writings to the eeprom all the time the light is on or am I missing something:

// write back state to eeprom but omit the mode configuration.
// Minimises risk of corruption. Everything else will right itself
// eventually, but modes will stay broken until reprogrammed.
eeprom_write_block(&state, 0, sizeof(State_t) - sizeof(state.mode_arr));
eeprom_busy_wait();

That would eventually destroy cells in the eeprom.

Not really.

Lumens are for capturing - they even get released outdoors.

Strobes are for hunting down and doing bad things to. Like soldering with a 500 amp welder. That works.

Or cutting up with a chainsaw...

or.......

:)

Yes, every time the light is switched on, the eeprom is written to. Given the 100000 write cycles per cell guaranteed by Atmel, you could click the light a hundred times per day and it would still take almost three years before that number is reached.

That number used to be two or three times lower with the older releases, as the cell used for recognising mode changes was written up to three times whenever the light was turned on. Femto over at http://www.taschenlampen-forum.de/ pointed this out to me and I have since added a wear levelling algorithm to alleviate this problem.