Flashlight Firmware Repository

I tried that, actually. I think itā€™s a matter of compile options, but for me it made no difference at all in the size or content of the build. But if it helps at least sometimes I donā€™t mind making it default. :slight_smile:

Here is what I see when building it (same with/without inline):

~/src/torches/trunk/ToyKeeper/Ferrero_Rocher/> ../../bin/build.sh Ferrero_Rocher
avr-gcc -Wall -g -Os -mmcu=attiny13 -o Ferrero_Rocher.o -c Ferrero_Rocher.c
avr-gcc -Wall -g -Os -mmcu=attiny13 -o Ferrero_Rocher.elf Ferrero_Rocher.o
avr-objcopy --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex Ferrero_Rocher.elf Ferrero_Rocher.hex
Program:     970 bytes (94.7% Full)
Data:         26 bytes (40.6% Full)

If my guess is correct, the ā€œ-Osā€ option will automatically un-inline everything which has been used more than once.

Weird - just tried it again, and the difference is 48 bytes saved - 984 with inline, 948 without. I'm using Atmel Studio 6.2, and the -Os option is specified.

This is what 6.2 studio invokes for compiling:

Invoking: AVR/GNU C Compiler : 4.8.1

"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe" -x c -funsigned-char -funsigned-bitfields -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=attiny13a -c -std=gnu99 -MD -MP -MF "Ferrero_Rocher.d" -MT"Ferrero_Rocher.d" -MT"Ferrero_Rocher.o" -o "Ferrero_Rocher.o" ".././Ferrero_Rocher.c"

Thanks!

The important option there was ā€œ-c -std=gnu99ā€. I added this to my build script and am now getting the same results you are. This also has reduced the size of every firmware Iā€™ve tried so far, so Iā€™m leaving it in as a permanent thing. :slight_smile:

This also saved enough room to let the full config mode fit into the blf-a6 firmware without having to remove anything. :smiley:

I tried Star 1 mode on wight`s A17DD driver and it works, the problem is that it give only 3.5amps max

How can one solve that problem?

The only firmware change I can think of which might be relevant is to change FAST_PWM_START to 255, to force it to use phase-correct PWM. But this would likely only change the numbers by a tiny tiny amount (like half a percent).

The rest is probably due to hardware. You might want to try bypassing springs, checking your measurement setup, using thicker wires anywhere possible, using a hotrod cell, etc. Might also be worth checking to make sure the light hadnā€™t already stepped down from maximum when the measurement was taken.

The emitter type and vintage makes a big difference tooā€¦ if itā€™s a recent XM-L2 it might not be able to go as high as an older XM-L2, for example.

Iā€™m not sure what the best practices are for high-amp measurement, but it seems like most people prefer to use a clamp meter and thick short wires and it probably doesnā€™t work as well to use a traditional DMM on an open tailcap. I recall a lot of discussion about this on the BLF X6 thread, and how hard it is to accurately measure amps. It might be easier to measure lumens instead.

Already did that ToyKeeper- 3.5amps tops, wierd, tried on 3 different emitters , and 2 drivers- on Samsung 25r battery

Since its the best even hunting firmware and there are lotsa hunters, i use this one most :slight_smile:

P.S Same drivers with your A6 firmware top up arround 4.8-5amps with U2 1A XML2

I use this method on the 84 and 85 as it has 512 bytes. I already have an array of 16 bytes full of different settings not that are changed unless user enters the user programming mode, so before this array gets filled up with the stored settings I use it for looping through as described to find the mode bytes.

On the 13A Iā€™d go withToyKeeperā€™s suggestion. There is no need for the array really, just use a single byte. You wonā€™t notice any difference in start-up speed, takes less space to program and uses less RAM.

Thatā€™s really strange. Iā€™m not as familiar with STAR; I only changed what was necessary to make it work as a 1-mode driver.

Looking again, I see one other thing which could make things a little weird. STAR sets alt PWM (in set_output()) to the same value as the primary channel (regardless of whether itā€™s compiled to use dual PWM), so itā€™s turning on both channels on a 2-channel driver. In my blf-a6 tests I found that turbo is actually brighter with only the FET channel ā€” turning on both the FET and 7135 causes lower output. So if youā€™re using a 2-channel driver it might be that the 7135 is actually getting in the way.

More generally, Iā€™m not certain itā€™s a good idea to run at full direct-drive amps on a 1-mode light, unless you make the turbo timeout really short. If itā€™s mounted on a weapon, thereā€™s no skin contact so nobody would notice if it gets really hot.

Wow, interesting... Not sure if the Studio IDE set that somehow by default. It's in the Compile "Miscellaneous" settings. When I create new solutions/projects, I simply copy a previous to begin with.

Oops - the "48" saved should be "36"... Smile

I was thinking about doing it byte by byte but thought it would be too slow so I went with a 8 byte array instead. I got plenty of space in ram anyway but I may switch later when my flasher arrives. But i donā€™t want a noticable boot time in my driver. :stuck_out_tongue:

Edit: Using an array was a bit tricky with a weird pointer to the eeprom adress. Must get my flasher to confirm I got it right.

Is it better to put pwm to phase when in 255 level? What do you get by default? Or maybe there is no default?

The attiny13a is running at 4.8 MHz. It only takes a few clock cycles to check each eeprom byte, and there are 64 bytes. Letā€™s say it takes a dozen cycles each; thatā€™s 768 cycles, which should take about 0.16 ms total. The data sheets suggest an array might save about four clock cycles per byte, but itā€™ll still be roughly 0.1 ms.

Can you feel a boot-up difference of 0.05 milliseconds?

In general, yes, phase-correct PWM is a good idea on the highest level. It doesnā€™t usually make any noticeable difference, but itā€™s nice to make the code default to phase-correct to account for the few cases where it matters. I donā€™t think the hardware has a default; you have to explicitly tell it to generate pulse waves because those pins can also serve other functions.

Well, the timer is set to arround 1.5minutes- then it ramps down to 50%, the FL body gets only warmer this way ā€¦.plus when its mounted on a weapon it lights for usualy 10 seconds tops- i use simple momentary on self made remote switches, made from thick Cu pads: found that those are most reliable, especialy with all that forest fog and moisture

The 7135 thingā€¦ā€¦you might be right, i have to try the 024 version out then

Once again, 10x for that 1mode version, i waited for this long time

Most likely not. :slight_smile: But, you can have all the mhz in the world, if itā€™s slow reading from eeprom itā€™ll still be slow. Look, Iā€™m not saying itā€™s too slow reading byte by byte. I thought it was faster reading 8 byte blocks but if it works reading byte by byte that is a simpler solution.

Got it, I take it you mean something like this then: void set_output(uint8_t pwm_lvl) { if (pwm_lvl > FAST_PWM_START && pwm_lvl != - Pastebin.com

Is it possible to paste code directly in the forum?

Ish. I normally use phase-correct on moon and turbo, and use fast for everything between. The pulses are longer with phase, which makes moon more stable (drops less with voltage).

But if it doesnā€™t bother you, you could use phase everywhere. I donā€™t like the whining sound or visible flashing, but not everyone is sensitive to those.

Getting rid of buzzing pwm modes are my main motivation for writing my own firmware. But was thinking about something else. How do the different sleep modes work? SLEEP_MODE_IDLE just seems to be doing more or less nothing. Iā€™m more curious about SLEEP_MODE_PWR_DOWN though. Does it turn off the output? If you run a special mode like ie strobe it could be a bit tricky to turn it off manually otherwise. You only got a few bytes to play with so would be nice if output is turned off automatically when going to SLEEP_MODE_PWR_DOWN.

TBH, I havenā€™t really optimized much for sleep mode. I have some relevant patches waiting for me to merge and test, but I havenā€™t done it yetā€¦

In sleep mode the PWM counter stops, but I havenā€™t specifically tested to see what that does when I donā€™t set it to zero first. I expect the emitter would stay on if itā€™s not turned off before entering sleep (which is a trick I use for the standby light on my Roche F6, but first I set it to a special non-PWM low mode).

Interrupts can wake up the MCU from sleep mode, if they are enabled and a relevant event happens. Touching the e-switch is one example, or the watchdog timer can do it too. So for low-power shutdown itā€™s usually a good idea to disable interrupts too. On e-switch standby though, at least the switch interrupt needs to stay on.

Hey thanks for the tip. By adding c99 to the makefile and using inline for a few functions that only run once I managed to save 40 bytes. :slight_smile: It looks like c89 is the default you get. Using c11 didnā€™t change anything for me though.

Sorry, Iā€™m still a total noob at this. Is this close to what would need to be done? The purpose is for my XinTD X3, i want to have one mode group for 18650, and one for use with 3x alkaline AAā€™s. So I donā€™t need LVP for the AAā€™s.

What is the lower PWM limit where you switch between phase-correct and fast?

Interesting. I never looked at the E-switch versions of Star. I coded my own E-switch routine by changing the watchdog timer to the fastest and have the switch test in my main while(1) loop. It may have made the logic pretty easy but I guess itā€™s not a power efficient way of running things as my entire main routine with voltage monitoring and all gets executed a whole lot more. Has anyone done any tests? Or maybe this stuff can be found in the datasheets, havenā€™t looked at MCU power consumption at all.