Flashlight Firmware Repository

Oops, I just realized this thread wasn’t sticky. It is now.

Thanks! Good idea :)!

D’oh. It looks like that includes everything except the first step, the one where it converts a .c file into a .o file. And that’s the one I’m most hoping to see. :slight_smile:

In any case, it appears that the new version saves about 6 bytes. I’d like to know what build options it uses to make the result smaller. Maybe it’s just a newer version of gcc, but maybe not.

The main options right now are STAR or NLITE, and neither is quite what you described. I don’t think anyone has done the mode group switch via blink-on-low, because very few people seem to like that. Neither one has blinky modes, either. STAR’s code is open though, if you’d like to use it as a starting point.

Change the ‘ticks’ variable to a uint16_t and set its limit to 65535, and then you can have a turbo timeout up to about 9 hours.

This may be what you are interested in?;

Invoking: AVR/GNU C Compiler : 4.9.2
"D:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"D:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.0.68\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=attiny13a -B "D:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny13a" -c -std=gnu99 -MD -MP -MF "main.d" -MT"main.d" -MT"main.o" -o "main.o" ".././main.c"
Finished building: .././main.c

Maybe I missed it this morning, as I was running late for work when I posted.



Thanks TK.

I clipped this beginning at line 272.

ISR(WDT_vect) {
    static uint8_t ticks = 0;
    if (ticks < 255) ticks++;
    // If you want more than 255 for longer turbo timeouts
    //static uint16_t ticks = 0;
    //if (ticks < 60000) ticks++;

Is this the correct place to change it from?

So it will look like this?

ISR(WDT_vect) {
static uint16_t ticks = 0;
if (ticks < 65535) ticks++;
// If you want more than 255 for longer turbo timeouts
//static uint16_t ticks = 0;
//if (ticks < 60000) ticks++;

Think it should be:

ISR(WDT_vect) {
//static uint8_t ticks = 0;
//if (ticks < 255) ticks++;
// If you want more than 255 for longer turbo timeouts
static uint16_t ticks = 0;
if (ticks < 65535) ticks++;

Oh duh, your probly right. I did not even notice that bit at the bottom where it already had the static uint16_t ticks = 0; bit.

I had tried before asking in the thread by just enabling the 6000 ticks part and commenting out the unit_8 bit.

I will try that and report back.

Thanks! That had all the info I was looking for.

It looks like the options make no difference in size, but the version of the compiler does. I’ve currently got 4.7.2 on one box and 4.8.1 on another; it seems debian doesn’t have 4.9.2 yet. :slight_smile:

Fortunately, the difference is small… 1002 bytes, 1000 bytes, or 996 bytes (for 4.7.2, 4.8.1, and 4.9.2).



Ok that did do the trick. T timer is good now.

One more question. Does anyone happen to know what causes that whining noise on MED mode. What I mean is with some setups I get it and some I dont. I use the same FET drivers for almost all my lights, just different firmware and emitters, hosts etc.

Right now I have this driver setup with 2 26650s and an XHP70. On low (2) I get no PWM whine, on med (39) I get a bad one. and of course none on high.

Is there a fix for this?

I surrounded my one driver that was doing this (Edit: JUST the FET, left room to attach the SOIC clip) with some RTV, seemed to help. I guess duct seal would work as well (search for POTTING here on BLF) and be more temporary if you wanted to remove it later…

I think the driver whining is still an unresolved question.

Has any tried potting a whining driver? Preferably with something removable like fujik heatsink compound, neutral cure silicone, or one of those removable potting mixes that people have posted.

30 sec too slow. :smiley:

You only potted the fet, not the caps and resistors, correct? Did the driver have a spring? Consider trying those small brass pillars that they sell?

Yes, just the FET, as far under it as I could. A big dab on top as well. It wasn’t that loud of a whine originally, but I couldn’t hear it afterwards… I would bet that changing something acoustically would cancel your whine, as it is a sympathetic vibration, not a direct tone being generated. Changing the airspace with a chunk of old pencil eraser or a packing peanut may even help…

Yes, I have potted drivers many times to resolve this. Using various items ranging from the silicone heat sink material that comes with some Chinese drivers all the way up to full encasement in JB weld.

EDIT: One other thing I have noticed that helps is not using a spring on the bottom of the driver. Especially one like the spring that comes out of the switch post of a maglte. These act like small record needles or amplifiers.

I was just hoping there was a fix that could be done by editing the firmware. For example tweaking the PWM level of medium mode a few percent or something.

I just noticed something else. What would happen if I changed this line.

#define FAST_PWM_START 8 // Above what output level should we switch from phase correct to fast-PWM?


What would be the effect if I changed that 8 to like a 50?

The reason I ask is it seems to have reduced the whine of the medium mode slightly ( maybe I imagined it), but I am wandering if there will be any side effect? Like a flicker on med or something?

Phase correct is slower PWM. But different people have different tolerances for flicker. If this is for a personal light and your aren’t bothered by it then no harm.

In general, phase-correct PWM tends to be easier to hear than fast PWM… but it really depends on the harmonics of your exact build.

I’d like to see if the whining issue goes away with attiny25 drivers and a higher clock speed.

The loudest I’ve heard is actually a different issue… on my Cypreus (triple XP-L HI, FET+7135), it clicks every time it goes between off and turbo. So, the strobe modes make both light and (a bit of) sound.

Ya, part of what has me so stuck right now is the light body I am using. I finally gave up and JB welded the driver and insulated it with some foam in addition. There is still a little whine when its outside the host, but much less. However the body of this light is a very thin stamped metal that acts like a radio antenna when its installed.
http://www.flashlightmuseum.com/Rayovac-Flashlight-D367F-7-Cell-Sportsman-Hunting-Light-with-Leather-Strap-7D-1970

Very cool and retro looking, but man has it been a pain.