Flashlight Firmware Repository

2222 posts / 0 new
Last post
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

Thanks. I added that to the blf-a6-final branch, since it appears to be based on that code. The main/trunk branch has done some refactoring to move common code into shared headers, so this mod might not build quite right there. In any case, it’s online here now:

http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/blf-a6-final/...

testedandbaked
testedandbaked's picture
Offline
Last seen: 1 week 5 days ago
Joined: 09/04/2015 - 07:40
Posts: 59
Location: Australia

Thanks TK!

KramKram
Offline
Last seen: 2 years 7 months ago
Joined: 10/15/2015 - 03:13
Posts: 46

I have a question, how do you disable the output on pin 6 of attiny13a in blf a6 firmware. The reason i want to disable the pin 6 is i am only using the pin 5 for output on one 7135 and no connection on pin 6 (no FET or 7135). But the problem is i am getting an occasional blinking when going from high mode to moon mode or even after turning on the light where it goes to moon initially. Maybe the reason i am getting the blink is because the pin 6 is not disabled? So how can i disable it in the firmware?

pyro1son
pyro1son's picture
Offline
Last seen: 2 months 1 week ago
Joined: 03/21/2013 - 08:18
Posts: 432
Location: UK
    DDRB |= (1 << PWM_PIN);     // enable main channel
    DDRB |= (1 << ALT_PWM_PIN); // enable second channel

delete the first line

Pastebin                                      &nbs

KramKram
Offline
Last seen: 2 years 7 months ago
Joined: 10/15/2015 - 03:13
Posts: 46

pyro1son wrote:
DDRB |= (1 << PWM_PIN); // enable main channel
DDRB |= (1 << ALT_PWM_PIN); // enable second channel

delete the first line

Thanks, i’ll try that.

Edit: I already deleted that line. There is still blinking between the transition from high to moon mode and also whenever i turn on the light. Maybe i have a bad attiny13a or 7135?

pyro1son
pyro1son's picture
Offline
Last seen: 2 months 1 week ago
Joined: 03/21/2013 - 08:18
Posts: 432
Location: UK

I have a question what code would I need to make a 0805 LED blink on pin 3 while the light was off say once every 5 seconds for example?

I can make it turn on with:

DDRB = (1 << PWM_PIN) | (1 << RED_PIN);
PORTB |= (1 << RED_PIN);



P.S. e-switch driver

Pastebin                                      &nbs

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

KramKram wrote:
There is still blinking between the transition from high to moon mode and also whenever i turn on the light. Maybe i have a bad attiny13a or 7135?

The pre-flash is more of a hardware issue. It shows up on some drivers but not others. I’m not sure why, but no code changes I could think of had any effect on it.
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

pyro1son wrote:
I have a question what code would I need to make a 0805 LED blink on pin 3 while the light was off say once every 5 seconds for example?

P.S. e-switch driver


First you’ll need to change what it means to be “off”. Normally the driver goes to sleep and will only be awakened by an interrupt such as pressing the e-switch.

Instead, you’ll need to give it some sort of shallower sleep, which will increase standby power and reduce battery life while “off”.

One option is to leave the CPU in a busy loop. It’s easy, but far from ideal. Another option is to enable the WDT interrupt during sleep and add code to the WDT handler to count time and blink the LED periodically. I don’t recall the details of sleep mode right now though… I’m a bit too sleepy myself to remember something I only once glanced at in a hundred-page reference manual. There is a table though, explaining different options for sleep mode and which options pay attention to which interrupts.

pyro1son
pyro1son's picture
Offline
Last seen: 2 months 1 week ago
Joined: 03/21/2013 - 08:18
Posts: 432
Location: UK

ToyKeeper wrote:

First you’ll need to change what it means to be “off”. Normally the driver goes to sleep and will only be awakened by an interrupt such as pressing the e-switch.

Instead, you’ll need to give it some sort of shallower sleep, which will increase standby power and reduce battery life while “off”.

One option is to leave the CPU in a busy loop. It’s easy, but far from ideal. Another option is to enable the WDT interrupt during sleep and add code to the WDT handler to count time and blink the LED periodically. I don’t recall the details of sleep mode right now though… I’m a bit too sleepy myself to remember something I only once glanced at in a hundred-page reference manual. There is a table though, explaining different options for sleep mode and which options pay attention to which interrupts.

Sounds interesting. How complicated is this manual? Might be worth a read.
As long as it’s not significant drain I think I will be ok with it.

Pastebin                                      &nbs

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

It’s just the standard attiny13a reference manual / data sheet from Atmel. I think they call it doc8126.pdf or something like that. It has everything you could ever possibly want to know about the tiny13.

pyro1son
pyro1son's picture
Offline
Last seen: 2 months 1 week ago
Joined: 03/21/2013 - 08:18
Posts: 432
Location: UK

Probably over my head but I’ll try give it a read

Pastebin                                      &nbs

mattlward
mattlward's picture
Offline
Last seen: 4 days 17 hours ago
Joined: 06/19/2015 - 09:20
Posts: 2827
Location: Illinois, USA

I am attempting to compile a version of this firmware with the 2 strobe modes removed. It appears though that I am missing a layout file and AVRStudio 5.1 aborts on the first line of the code… Where can I find that layout file? I did not see it on TK’s page last night in her section.

Thanks Matt

EDC rotation:
FW1A, LH351D 4000k (second favorite)
FW3A, LH351D 3500k
FW3A, SST20 FD2 4000k
FW3A, Nichia 4000k sw40 r9080 (favorite light!)
FW3A, Cree XP-L Hi 5A3
Emisar D4V2, SST20 4000k
S2+, XM-L2 T6 4C

Halo...
Halo...'s picture
Offline
Last seen: 3 years 7 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Could you paste the error or the whole output that AVRstudio gives you?

mattlward
mattlward's picture
Offline
Last seen: 4 days 17 hours ago
Joined: 06/19/2015 - 09:20
Posts: 2827
Location: Illinois, USA

I will re-run the compile this evening and post it.

EDC rotation:
FW1A, LH351D 4000k (second favorite)
FW3A, LH351D 3500k
FW3A, SST20 FD2 4000k
FW3A, Nichia 4000k sw40 r9080 (favorite light!)
FW3A, Cree XP-L Hi 5A3
Emisar D4V2, SST20 4000k
S2+, XM-L2 T6 4C

Tom E
Tom E's picture
Offline
Last seen: 7 hours 40 min ago
Joined: 08/19/2012 - 08:23
Posts: 12648
Location: LI NY

Atmel Studio 5.1 is pretty dated. I'm running 7.0 now, upgraded from 6.2, slightly better optimization even. Actually I never used 5.1 - started with 6.0 way back. Hhmm - not sure, maybe a header file is miss'n?

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

There is no AVRStudio layout file because I’ve never used AVRStudio. It’s kind of an unnecessary layer and most projects omit those files. I build it with a single short “build.sh” command, then flash it with “flash.sh”. It looks like this:

(~/src/torches/trunk/ToyKeeper/blf-a6/)-]> ../../bin/build.sh blf-a6
avr-gcc -Wall -g -Os -mmcu=attiny13 -c -std=gnu99 -DATTINY=13 -o blf-a6.o -c blf-a6.c
avr-gcc -Wall -g -Os -mmcu=attiny13 -o blf-a6.elf blf-a6.o
avr-objcopy --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex blf-a6.elf blf-a6.hex
Program:    1000 bytes (97.7% Full)
Data:         13 bytes (20.3% Full)
(~/src/torches/trunk/ToyKeeper/blf-a6/)-]> ../../bin/flash.sh blf-a6.hex
mattlward
mattlward's picture
Offline
Last seen: 4 days 17 hours ago
Joined: 06/19/2015 - 09:20
Posts: 2827
Location: Illinois, USA

I am not very good at running a compiler. My initial problems were caused during project creation, the program in both versions wanted the *.c file to be called main.c. I had to remove that file from the project after importing the desired *.c file.

Here are the changes that I made, I desired to remove the both of the blinky modes so I could get to the battcheck easier.

// Hidden modes are before the lowest (moon) mode, and should be specified
// in reverse order. So, to go backward from moon to turbo to strobe to
// battcheck, use BATTCHECK,STROBE,TURBO .
#define NUM_HIDDEN 2
#define HIDDENMODES BATTCHECK,TURBO
#define HIDDENMODES_PWM PHASE,PHASE
#define HIDDENMODES_ALT 0,0 // Zeroes, same length as NUM_HIDDEN

#define TURBO 255 // Convenience code for turbo mode
#define BATTCHECK 254 // Convenience code for battery check mode
// Uncomment to enable tactical strobe mode
//#define STROBE 253 // Convenience code for strobe mode
// Uncomment to unable a 2-level stutter beacon instead of a tactical strobe
//#define BIKING_STROBE 252 // Convenience code for biking strobe mode
// comment out to use minimal version instead (smaller)
//#define FULL_BIKING_STROBE

Hey! Also gained some space on the CPU.

Studio 7 output log!!!

——— Build started: Project: BLF-A6_no_blink, Configuration: Debug AVR ———
Build started.
Project “BLF-A6_no_blink.cproj” (default targets):
Target “PreBuildEvent” skipped, due to false condition; (‘$(PreBuildEvent)’!=’‘) was evaluated as (‘’!=’‘).
Target “CoreBuild” in file “C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets” from project “E:\AVRdude\BLF-A6_no_blink\BLF-A6_no_blink\BLF-A6_no_blink.cproj” (target “Build” depends on it): Task “RunCompilerTask” Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all Building file: .././blf-a6.c Invoking: AVR/GNU C Compiler : 4.9.2 “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe” -x c -funsigned-char -funsigned-bitfields -DDEBUG -I“C:\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 “C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny13a” -c -std=gnu99 -MD -MP -MF “blf-a6.d” -MT“blf-a6.d” -MT“blf-a6.o” -o “blf-a6.o” “.././blf-a6.c” Finished building: .././blf-a6.c Building target: BLF-A6_no_blink.elf Invoking: AVR/GNU Linker : 4.9.2 “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe” -o BLF-A6_no_blink.elf blf-a6.o -Wl,-Map=“BLF-A6_no_blink.map” -Wl,—start-group -Wl,-lm -Wl,—end-group -Wl,—gc-sections -mmcu=attiny13a -B “C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny13a” Finished building target: BLF-A6_no_blink.elf “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe” -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures “BLF-A6_no_blink.elf” “BLF-A6_no_blink.hex” “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe” -j .eeprom —set-section-flags=.eeprom=alloc,load —change-section-lma .eeprom=0 —no-change-warnings -O ihex “BLF-A6_no_blink.elf” “BLF-A6_no_blink.eep” || exit 0 “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe” -h -S “BLF-A6_no_blink.elf” > “BLF-A6_no_blink.lss” “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe” -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures “BLF-A6_no_blink.elf” “BLF-A6_no_blink.srec” “C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe” “BLF-A6_no_blink.elf” text data bss dec hex filename 920 0 13 933 3a5 BLF-A6_no_blink.elf Done executing task “RunCompilerTask”. Using “RunOutputFileVerifyTask” task from assembly “C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrGCC.dll”. Task “RunOutputFileVerifyTask” Program Memory Usage : 920 bytes 89.8 % Full Data Memory Usage : 13 bytes 20.3 % Full Done executing task “RunOutputFileVerifyTask”.
Done building target “CoreBuild” in project “BLF-A6_no_blink.cproj”.
Target “PostBuildEvent” skipped, due to false condition; (‘$(PostBuildEvent)’ != ‘’) was evaluated as (‘’ != ‘’).
Target “Build” in file “C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Avr.common.targets” from project “E:\AVRdude\BLF-A6_no_blink\BLF-A6_no_blink\BLF-A6_no_blink.cproj” (entry point):
Done building target “Build” in project “BLF-A6_no_blink.cproj”.
Done building project “BLF-A6_no_blink.cproj”.

Build succeeded.
====== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ======

EDC rotation:
FW1A, LH351D 4000k (second favorite)
FW3A, LH351D 3500k
FW3A, SST20 FD2 4000k
FW3A, Nichia 4000k sw40 r9080 (favorite light!)
FW3A, Cree XP-L Hi 5A3
Emisar D4V2, SST20 4000k
S2+, XM-L2 T6 4C

Tom E
Tom E's picture
Offline
Last seen: 7 hours 40 min ago
Joined: 08/19/2012 - 08:23
Posts: 12648
Location: LI NY

K, cool!! Smile

pilotdog68
pilotdog68's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

Here is the code I’ll be referring to, Stock STAR momentary on the left, my code on the right.

It will be used in a dual switch light. As far as I can tell, whenever power is applied to the driver, it should turn on the LED in the “3” mode (max). It does do this when the power is removed while the light is on, but if the power is removed when the light is in the “0” mode (off), it comes back on in the same “0” mode after power is reapplied, instead of defaulting to “3” mode like it should. I’m sure its a quick fix, but I don’t know what it is.

Help?

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Tom E
Tom E's picture
Offline
Last seen: 7 hours 40 min ago
Joined: 08/19/2012 - 08:23
Posts: 12648
Location: LI NY

Not sure if I'd depend on the mode variable initialization like that. Try setting mode_idx to 3 just before the main while loop - then there's no doubt it is set and should be acted on since last_mode_idx is set to 0 - guaranteed it's processed in the main loop.

pilotdog68
pilotdog68's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

Tom E wrote:

Not sure if I’d depend on the mode variable initialization like that. Try setting mode_idx to 3 just before the main while loop – then there’s no doubt it is set and should be acted on since last_mode_idx is set to 0 – guaranteed it’s processed in the main loop.


that makes sense to me in a logical way, but not in a firmware way. I tried just throwing “mode_idx = 3” before the longest loop and it just gave me a bunch of compile errors. What do i need to do?

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

pilotdog68
pilotdog68's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

I think i got it working the way I want by commenting out a lot of the stuff relating to “sleep”. Will that cause me other issues, like with LVP perhaps?

New Diffcheck. (mine on the right)

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Tom E
Tom E's picture
Offline
Last seen: 7 hours 40 min ago
Joined: 08/19/2012 - 08:23
Posts: 12648
Location: LI NY

That sounds weird - sleep mode shouldn't have anything to do with a clean power up... Sounds like the mode_idx set to 3 is not working.

Putting the following statement in a line by itself before the while(1) line should definitely compile ??? I've only been programming in C since 1982 or so Smile Frown.

mode_idx = 3;

 

pilotdog68
pilotdog68's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

You of course were right, I just didn’t know how to read what you were saying H)

I’ve got it in the right place now and it works great, thanks.
……………………….

Next issue:
the way I have the modes ordered, I can cycle through lo-hi-lo-hi without hitting the hidden “medium” that turbo steps down to. However, I think this means that if LVP steps in, things will be messed up.

If I’m in High mode when LVP starts, it will step down to low, then step “down” to medium, then to sleep. Or if I’m in the hidden medium, it will step down directly to sleep.

What can I do to fix this?

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

pilotdog68 wrote:
the way I have the modes ordered, I can cycle through lo-hi-lo-hi without hitting the hidden “medium” that turbo steps down to…

If I’m in High mode when LVP starts, it will step down to low, then step “down” to medium, then to sleep. Or if I’m in the hidden medium, it will step down directly to sleep.


At a glance, it looks like it has off, medium, low, high. So, LVP stepping down goes high, low, medium, off. Yes?

You could either modify the logic for LVP… or throw out the idea of using mode_idx at all for step-down and modify PWM levels more directly. Not sure which would be easier. I prefer the second approach, but it’s harder to fit into STAR-based projects.

Tom E
Tom E's picture
Offline
Last seen: 7 hours 40 min ago
Joined: 08/19/2012 - 08:23
Posts: 12648
Location: LI NY

Yes, looks like you are right. I noticed your mod to the next_mode() function, and the seemingly odd mode ordering. You probably have to have a special prev_mode that's used for LVP only, skipping mode 1, or to make it more flexible, skip a previos mode that has a higher PWM value, but that's a bit more involved. Depends how much code space you have, and how flexible you want it to work.

You are still in the tiny world of the 13A with this driver Smile.

pilotdog68
pilotdog68's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

Is there a different way I can order the modes to keep medium hidden but also lvp linear? Like, if I swap the order of low and Medium, can I get it to skip over medium in normal mode order? Like, “when switch is pressed: if mode is low, go to high. If mode is not low, go to low”?

I’m not too worried about jumping to the 25/85 because I like a very simple user experience. Though I did buy a 25 for my 7G3CS because I want the temp monitoring.

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Tom E
Tom E's picture
Offline
Last seen: 7 hours 40 min ago
Joined: 08/19/2012 - 08:23
Posts: 12648
Location: LI NY

Well, lots of options. Like TK said, you could simply hard code LVP. I'd tend to keep the mode table in proper order so LVP works fine, but skip the next to last mode (med mode) in next_mode(). When LVP kicks in, it doesn't limit use of the higher modes, so normal nav still works and it won't be broken.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 38 min 46 sec ago
Joined: 01/12/2013 - 14:40
Posts: 10231
Location: (469219) 2016 HO3

If you have enough room left, you can do anything you want. The only real limitation is ROM space.

Most of the logic you described seems pretty straightforward too. Just add some extra clauses to detect the mode and step down in different ways, and it should be fine. Or you could perhaps do it in less space by using a mode change table… like each entry would define what “stepping down” means from that mode. Here’s a rough idea of what I mean:


uint8_t modes = {0, 0, 0, 255};
uint8_t altmodes = {0, 255, 30, 255};
uint8_t stepdowns = {0, 2, 0, 1};

void stepdown() { mode_idx = stepdowns[mode_idx];
}

I suspect Tom’s suggestion would be simpler though. Smile

pilotdog68
pilotdog68's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

Tom E wrote:

Well, lots of options. Like TK said, you could simply hard code LVP. I’d tend to keep the mode table in proper order so LVP works fine, but skip the next to last mode (med mode) in next_mode(). When LVP kicks in, it doesn’t limit use of the higher modes, so normal nav still works and it won’t be broken.


That works. How do I make it skip the next-to-last mode?

My Favorite Modded Lights: X6R, S8 , X2R , M6, SP03

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Pages