STAR Firmware by JonnyC - Source Code and Explanation

Just swap the 1 and the 0, and it’ll reverse the meaning of having that star soldered. So, “0 : 1” instead of “1 : 0”.

Or if there’s still room left, you could add a second line to logically invert it: “memory = !memory;”

With drivers that don’t have an off-time capacitor, I definitely prefer this “no memory” or “short cycle memory”, so it always takes 3 taps to access mode 3, always takes 5 taps to access mode 5, etc. Going from 3 to 5 still takes 5 taps because the saved mode resets back to zero after the light has been on for a full second.

But I like off-time methods even better. It can still have no memory, but it then becomes one tap to go from 4 to 5, and one medium tap to go backward from 5 to 4, instead of taking 5 taps and 4 taps respectively. And it will always start in the first mode after being off for a few seconds, regardless of what you did before. (short cycle memory has sort of a bug where if you tap 4 times quickly and immediately shut it off, it’ll start on mode 5 next time because it wasn’t on long enough to reset back to zero)

The other thing I like about off-time methods is that it allows for shortcuts or “negative” modes. Basically, turn it on, then instead of doing a short press to go to the second mode, do a medium press to go backward. It can do something different in that case, like turbo or battery check, or whatever. There can even be more than one “negative” mode.

Oh, um, but if you want the end user to be able to configure the modes, regular STAR firmware is the way to go (and a driver with solderable stars on the back).

Thanks ToyKeeper! Since my mag kit will be targeted to the general public I want it as simple as possible, so no memory. Three partial presses of the mag switch to get to mode 3. Always start in low mode from OFF.

I actually made a thread on CPF about the whole garage conversion. I bought all the required components and made the fixtures for a 900 watt Nichia 219A lighting setup for the garage but still haven’t finished it…. Will be over 40,000 lumens of passively cooled light from my fixtures once I bother to finish it.

I just tested out my mag kit with the fresh STAR firmware and no memory. I don’t like how it functions. Just like you said, it always starts from low when changing modes from an existing mode, so if I am in medium and I want to go to high, it takes three clicks instead of one. Ideally the mode would be changed every time with a single click, but from off it would always start on LOW.

I’ll have to give off-time firmware a try once I get some caps in…

In my opinion ontime with “no memory” is 100% intolerable. It’s the polar opposite of offtime with “no memory”. Look forward with hope. :wink:

FWIW, the off-time firmware expects the capacitor to be on the star normally used to toggle memory. So, there is no “no memory” option. You’ll probably have to add that yourself, but it’s not too hard. The issue is that end users won’t be able to toggle it.

Personally, I’d rather sacrifice the mode-order star for this instead, and retain the moon toggle and memory toggle. Always low to high, but at least people can have memory if they want it.

BTW, if you enable mode memory without the capacitor, it’ll still take two clicks to change modes. It’s really annoying. Sometimes it’ll take one click, sometimes two, depending on how long the light has been on.

I still find it preferable to ontime with memory. I don’t really mind short-cycle memory, since the most-used modes are generally at the beginning so they never take many clicks to access… and the least-used modes are at the end where they can be ignored most of the time.

Hmm. I’ve only used ontime with no memory on the bench. Maybe if I used it on an EDC things would seem different. Make no mistake: I also strongly dislike the “sometimes one, sometimes two” taps required by a standard ontime-with-memory firmware.

Agreed. Ontime without memory is preferable to ontime with memory, but still not ideal.

We can probably all agree that on-time anything is worse than off-time anything :) A lot of us "grew up" with on-time w/ memory, so for me I was entirely used to it. But anytime I gave a light to a friend and tried to explain how it worked I realized how horrible the UI is.

Hoop - Awesome, awesome, awesome shop. A new flashlight company, hell yeah! I'm excited to see what you can do.

Thanks Hoop. I'm pretty much speechless. Just gotta say love the garage.

I’ve run into a problem, I’m not sure why.

I built up one of these: DD driver w/ low parasitic drain for e-switch lights. I used 10uF for both input and output capacitors on the LDO (a 3.3v LT1761).

Then I flashed it with STAR_momentary w/ voltage-mon disabled. (how do I properly refer to the commit I used? Is there a concise way to communicate this information? ba5fb9efbd5ad11e0edd4008123301532ac0a277 ?) (for my own reference - 2014-12-20_STAR_momentary_v1.6+no-voltage-mon.hex)

The problem is that in the highest mode (Turbo) only a long press works. A short press doesn’t switch from Turbo to Off. I can step through the modes forward as expected - 0,3,14,39,125,255, but it does not loop from 255 to 0. I can step backwards 255,125,39,14,3,0 and have it loop from 0 to 255 as expected. Turbo does have an MT-G2 at >8A, but I don’t see how that would have an effect on my momentary input to the MCU, especially when we consider that it does recognize the long press. Any ideas? Thanks!

Crap, that sucks. When you are in turbo and a short press doesn't turn it off, will another short press bring you to the first mode? I remember there was an issue with the PWM output not getting set to 0 before going to sleep for some crazy reason that makes me hate AVR programming, which is why I added this stupid line of code...

_delay_ms(1); // Need this here, maybe instructions for PWM output not getting executed before shutdown?

That seemed to fix it, but maybe it isn't enough. Are you able to (I hope!) reprogram the driver with ease? Maybe you can try commenting out the "sleep_until_switch_press()" call when it shuts the light down for being at the 0 index mode and see if it works then. This is not a solution, but it will be a way to debug it.

Thanks JonnyC! Good question, I didn’t connect the dots on my own. This is such a high current setup I can barely get my thoughts together during my brief, brief tests.

Yes, two short presses takes me to the first mode. I can go back to “off” with a long press. It seems that the problem is exactly as you suspected.

Unfortunately the driver is in a difficult to reach position. (oops!) I’ll build another for testing. Once there’s a solution I can take the other out and flash it. :slight_smile:

I’m eyeballing the sleep_until_switch_press function now. I guess this is the sort of thing where the debugger that was recently discussed could be very useful; many important things happen in that function and in the WDT_off() function it calls.

I guess you suspect that a slightly longer delay could band-aid the situation?

Son of a beach!! It was an actual bug. On December 13th I added an extra mode but did not add the corresponding "FAST" to MODE_PWM. Not sure exactly how it manifested itself in this behavior because I don't know how the code would react to an array index out of bounds. Whatever the case, it broke it.

Please pull the latest copy or just add another "FAST" to the MODE_PWM list. Sorry to anyone that this affected!

I just ordered some 1uF 0805 caps for off-time memory but I also have a cap from a stripped nanjg of mine and I wonder if I can use it for this? What are the specs of the standard caps on a nanjg?

It’s been said that it’s a 10uF cap. I’m confident it’s >4uF. 10uF may work fine, but you’ll probably need to adjust your offtime value. EDIT: for some additional info, look in the first 5 pages or so of this thread for HarleyQuin’s post(s) on the subject. HarleyQuin tried much smaller values than 1uF and was able to get those to work.

Caps on my seven 105Cs (both 8x7135 and 6x7135 versions) are all in the 3.5-4.2uF range

Heh, maybe I should have been confident about a different number.

I tested somewhat recently to see when the ATtiny13A would start working properly. Now that you call me out, I think I tried 1uF, 2uF, 3uF, and then got tired and went directly to 5uF. Ahh, here we are: Phase Correct PWM So much for confidence! :wink:

AK-47A 3x7135 with the same ATtiny13A has 1.6uF capacitor :slight_smile: Guess it depends on the load for ATtiny to drive.
On the other hand, 101-AK-A1 4x7135 has 7.5uF cap…

BTW, it’s a good idea to use PHASE on the highest and lowest mode. This prevents the moon-like fast PWM=0 mode from sticking around while the switch is pressed, and helps the light to shut off entirely.

On the lowest mode, PHASE can usually get lower than FAST, so that’s a benefit. And on the highest mode, PHASE and FAST are no different so you may as well use the one which won’t trigger the moon-while-pressed bug.

Out of all the firmwares I’ve made, the Ferrero_Rocher.c one is the most similar to base STAR. It might be worth a look in case there are any improvements you’re interested in. The main things are UI (press-and-hold ramps down and shuts off) and a battery check mode (from off, short-press then immediately long-press).