alexvh's firmware. Update: Hidden strobe, Ramping and optional mode memory added.

Update: March 9, 2015 Hidden strobe mode
I’ve added a hidden strobe mode to my firmware. After 2 very short on times the light goes into a strobe mode. To access it, half press the switch as fast as you can 3 or more times. I tried to make it hard to accidentally enter strobe, but easy enough to get into it when you want to, so it requires a very short on time between presses. You pretty much have to turn it off again before you see the light. A long press is needed to exit strobe mode.

Update: January 17, 2015 Ramping, Optional mode memory
Hey guys, I’ve added ramping to my firmware. I tried to make it a nice smooth ramp, it’s kind of like the sleep LED on a mac or something. It uses the ram retention trick, so it won’t wear out your eeprom. You can change the code to use the default ramp() function which rises and falls /\\\\ or ramp2() which is rising only /////. Just do a short press when it is ramping and that brightness level will be selected. I’ve also added mode memory (disabled by default) just uncomment #define MODE_MEMORY to enable it.

Original Post
Hey guys, I’ve been lurking here for a little while and thought I might contribute something back. I’ve been experimenting with writing firmware for NANJG drivers.

I’ve come up with a method for using off-time mode switching on stock nanjg drivers. This requires no hardware modifications, there is no need to solder any extra capacitors to the stars for example. It works by storing data in memory that does not get initialized on startup. The bypass capacitor that is already on the nanjg driver is able to supply just enough power to keep the data stored in memory for about 500ms. This happens to be a very convenient amount of time for off-time mode switching. For this to work, brown-out detection must be enabled in the fuse bits when you flash the chip.

I’ve only actually tested this with the NANJG 101-AK-A1, but it should work with the others as well.

This isn’t really meant to be a complete firmware, it’s mostly intended to demonstrate the method and allow others to add off-time mode switching to their own firmware. I plan on releasing more stuff in the future when it’s finished but I thought I would share this with you guys now. Please try it out and let me know what you think (and whether it actually works with your driver).

You can read a more in-depth description and download it here:

Great job, thank you! I’m willing to try this!

Interesting! Thanks for sharing, I’ll take a closer look at the code soon.

Very interesting work!

I just flashed this to the new style(no stars) 105d.

Unable to change modes - stuck on full output.

Willing to try any suggested changes.

You could try doubling up C1.

Pinched the cap from another 105c & stacked it, but no change.

I’m loving anything off-time at the moment so if this works reliably on a stock Nanjg, that’s fantastic news. Well done! :slight_smile:

Make sure brown out detection is enabled by setting the correct fuse bits when you flash it. The startup time fuse bits may be important as well. I flash it with these fuse bits: low=0x79 high=0xed

Yes, I used those fuse bits when flashing.

Oh wow…so this method of doing the code could actually replace the OTC on ALL the builds correct?

Very awesome build and very very slim on the coding…

Interesting method for making the levels…

are the 0x numbers written in HEX?

Welcome to the coding fray good sir :wink:
most importantly, welcome to the forum!

Awesome first few posts :slight_smile:

Hmm, I have only tested this method with the nanjg 101-AK-A1. It is possible that there are hardware differences that break this method. What resistors does the 105d use for the voltage divider? Do you have any way of measuring the capacitor?

Maybe try a low fuse of 0x75, I’ve found that also works. Maybe also try raising the brown out detect voltage to 2.7V by setting the high fuse to 0xeb. Maybe some combination of these will work.

Also, has anyone else tested this with their hardware and had success or failure? I’m interested to see which drivers this works for.

Edit: Also did you compile it from source yourself or did you use the hex file I compiled?

I’m not sure what you mean by OTC? I think this could be used on all the builds to get off-time memory. It’s a bit of a hack and I’ve only tested it on a few drivers, so I’m interested to see if others are able to get it working reliably as well.

Yes the 0x in front makes it hex. It’s the same as 255, 64, 16, and 4.

WarHawk-AVG means “off time capacitor”.

Sorry, I can’t measure the Caps. The resistor values are the same between the 101, 105c, & 105d.

I compiled the code from source using AVR Studio 5.1

I’ll try the different fuse values & report back.

Ok - I thought I’d try your pre-compiled hex first, & it worked on the 105d.

At that point I still had the additional Cap on the board, which I removed, & tested successfully again after the removal.


What I didn’t realize though, untill re-reading your Readme & OP, is that it is off-time memory switching , rather than off-time memory.

If this method can be implemented to save the current mode as well, I’m sure there will be a lot of happy people!

Great work, oh & welcome to BLF! :beer:

Maybe you also try the hex file I’ve uploaded on github as well? There could be a difference in the way it is being compiled.

I tried replacing the 10uF capacitor on the 101 driver I was using with a 5uF (approximate values) from a 105c and it works fine with either of them. So I don’t think it is the hardware.

I’m compiling it on linux using the commands below:

avr-gcc -g -Wall -Os -mmcu=attiny13 -c driver.c
avr-gcc -g -Wall -mmcu=attiny13 -c driver.c -o driver.elf driver.o
avr-objcopy -j .text -j .data -O ihex driver.elf driver.hex

and flashing it using:

avrdude -p t13 -c usbtiny -u -Uflash:w:driver.hex:a -Ulfuse:w:0x79:m -Uhfuse:w:0xed:m

cross-post…. :slight_smile:

Sounds good. Alexvh’s method should adapt fine to the “normal” style of offtime memory rather than “offtime no memory”. Both the cap and this new method could be considered flags: the same method of keeping track of modes used by STAR_off_time is fine.

Oops, I posted before seeing your reply. So yes, it seems they are being compiled differently. We should try to figure out what’s different so that people compiling with AVR studio have the right options set.

The flashlight terms can be a little confusing, but I think I know what you are asking. Yes mode memory can be added to this using the eeprom just like in the other drivers. I’ll upload a version with that soon. So that the light turns on in the mode it was previously left on in (unless it is a short press, in which case it comes on in the next mode). This was mostly meant to show how it works and what can be done using this method. I wanted to show that you don’t have to use the eeprom at all unless you want mode memory.

I’m certainly no expert with AVR Studio, but I can try suggestions for different settings to compile & test. I know there has been a few minor differences in versions of AVR Studio that have caused hick-ups in the past.

I figured that should be the case. This is a real nice chunk of meat for the programmers here :beer: