Flashlight Firmware Repository

That question should be posed to Dr.Jones. None of us can answer that and you should NOT assume what his position is either way. If the Doc is opposed and you do not ask that just shows disrespect AND if he is not opposed you just shorted yourself and others.

I also own a graphic design and sign business. Copyright is what we have to protect us BUT there are many things that as long as we are asked we do not care. We tend to get upset when someone takes something we worked hard to produce without asking and makes a million or is worth a million and in turn makes it worthless.

Here is another phrase (I have lots of them).....It is the fool that does not ask. And just FYI if it wasn't for asking TK we would not have the fantastic A6 code or even Wight's +1 7135 driver (which I do not have further info about yet)

The closest examples I’m aware of are:

  • Ferrero_Rocher/Ramping_UI_Table.c uses a ramping interface, where you hold the button until it gets to the level you want and then let go. The transitions are mostly smooth, but it has only 64 (or 40) discrete levels instead of 255.
  • STAR has an option to smoothly ramp when the turbo step-down hits, but this only happens at a fixed length of time and the ramp is designed to be slow so nobody will be able to see it while it’s happening.
  • cypreus.c uses a quick ramp-up approach on moon mode, where it tries to soft-regulate the output based on battery voltage and pulse frequency.

None of these are quite what you were describing, but maybe they could give you a starting point to work from.

IIRC, the Nitecore SENS series always ramps to the level you asked it for, but it’s proprietary and uses an accelerometer instead of a button. It won’t ramp down to off, either, since it shuts off by breaking power.

A fool is the one talking BEFORE thinking. :stuck_out_tongue: I’ve been using open source for more than a decade and out of all code I’ve ever found on the net 99.99% has been open source or Public Domain. What DrJones has written in the beginning of luxdrv-0.30b is something like Creative Commons. CC is very very rarely used for code and is not even considered to hold up in court in most civilised countries as you usually should sign a license agreement (yeah I know almost noone reads them :laughing: or NDA for closed source to apply. But as I said I’ll remove lines that DrJones consider as closed source.

Don't take what I said the wrong way. :) If you would like to use it why not ask?

As bugsy suggested, you’ll have to ask DrJones since no one else can speak for him and the license does not grant permission by default.

About explicitly open code, not all people who contributed code care about licenses so I’ve tried to fill in the blanks as best as I can. Here are some of the details:

  • All original flavors of STAR: JonnyC basically granted permission to do anything anyone wants with it (see STAR/README.md). This has resulted in most of the open code being based on STAR.
  • STAR derivatives: These are less clear since the parent license allows for open derivatives but does not require them to be open. I’ve done a lot of guessing based on the apparent intent of the authors, but would prefer if the licenses were more explicit.
  • My firmwares are explicitly GPLv3 licensed, except for some which I haven’t put the license on yet (but that is the plan so feel free to treat them as if they’re already explicitly open). GPL is basically “do whatever you want, as long as you re-share the code and the rights with anyone who wants them”.
  • alexvh/* : GPLv2 license
  • Tamagotchi/* uses the GPL, but I’m not totally sure its authors understand what that means and I think it only works on modded nanjg drivers.

Some others are public domain, I think, but it could take a while to verify that.

My preference is to use GPL or GPL-style licenses, since it clearly answers the licensing question for both the original project and all its derivatives, and the answer is “yes, it’s open”.

So Star is Public Domain, I guess. Thing is, when I started learning I took luxdrv-030b because it’s so small, Star is quite big, and well commented by DrJones. It really is a good avr hello world. And should imho be put in the public domain. :slight_smile: But I’ll take a look on Star too now as the code already is public domain.

Awesome, now it’s CC-BY-NC-SA. That’s a big improvement in terms of both permissions and clarity. Good things can come from asking. :slight_smile:

Just wondering whether you worked the kinks out of this. Hope you had a nice weekend!

I don't know if its been tried before (let me know), but here is a way to get extremely low 'OFF state' current (parasitic current, quiescent current, sleep current, etc.). I'm talking about the current used by the driver after it has shut itself down due to Low Voltage Monitor (LVM) kicking in. (Obviously to get zero current just click the switch OFF!) Lowering this current will help protect the cell or cells when the light has been left ON and forgotten.

The amount of current used by a typical 105C driver is very small compared to the capacity of a typical cell, but remember the LVM forced a shut down because the cell is nearly dead, so there isn't a lot of capacity left to run for long before the cell voltage drops to bad levels. With some mods we can drop this current under 0.002mA (2uA). But, we need to do some rewiring and recoding... are you up for it?

To do this we need to tweak the program code, steal the use of Star3 and move the lower ADC resistor, the one going to ground (usually 4.7k in a 105C driver). One end of the resistor goes back to pin7 and the other end now goes to pin3 or Star3. The code now needs to be changed to turn Star3 into an output, and set it Low. This reconnects the resistors just as normal but also allows the ATtiny to turn this pin Off by setting it to an input when the LVM kicks in. This opens the current path through the resistors saving over 100uA. If you were using Star3 to select memory, or the like, then you'll now have something else to do in code.

I've listed some typical currents used by different circuits. These depend on battery voltage and are roughly as follows:

  • ADC resistors = 3V / (22k + 4.7k) = 112uA
    This mod reduces the ADC resistor current draw to zero.
  • OffTimeCap resistor = 3V / 470k = 6uA This current is already zero if a resistor is not used with the OTC
    Change code to set this pin low before going to sleep, no need to keep the cap charged when "OFF".
  • ATtiny13A = 2uA Assuming Power Down Sleep mode with ADC off
    Can't get much below 2uA...
  • Zener Mods = 6V(batt) - 5V(zener) / 200ohm = 5000uA Changes with different resistor
    IMHO multi-cell lights should be done with low current LDO regulators (like TPS71550) rather than zeners. But I understand completely that these mods work perfectly well, they're just not as low current as a regulator. TPS71550 draws 3uA. My latest 2 cell driver now sleeps at less then 5uA.

Edit: This mod is not recommended for multi-cell setups as the voltage on the ADC pin will rise above the MCU supply voltage. This may/will draw current, and defeat the purpose of this mod. My 2 cell mod seems to work probably because the LVP point is very close to the MCU supply voltage.

I'm a hardware guy, so I don't feel comfortable telling you how to tweak the code in your particular driver to do these changes. (I had trouble trying to program a pin to be an input...) enough said. These are the changes I made to ToyKeeper's TK_OTC.c, it's nothing special even an old hardware guy can figure it out! Thanks TK! :)

#define STAR3_PIN PB4 // Low end of ADC voltage divider resistors
#define STAR3_DIDR ADC2D // Digital input disable bit corresponding with PB4

Added this to ADC_on()
DIDR0 |= (1 << STAR3_DIDR); // disable digital input on STAR3 pin to reduce power consumption
DDRB |= (1 << STAR3_PIN); // Set to Output
PORTB &= ~(1 << STAR3_PIN); // Pull low end of Voltage divider to ground
DDRB &= ~(1 << STAR3_PIN); // Set to Input (without pull-up) oops

Added this to ADC_off()
DDRB &= ~(1 << STAR3_PIN); // Set to Input (without pull-up)

Added this just before Set_Sleep_Mode
ADC_off(); //ADC off
PORTB &= ~(1 << CAP_PIN); // Drive Cap_pin Low

Cool :slight_smile: more dummy prof protection is always welcome, when you want to give lithium lights to less hyper aware individual.

Does this work on all attiny13a drivers & not only on “typical 105C driver”
like the fet+7135 driver for example because that one don’t have any “stars” or am i missing something vital here?

I think this can be adapted to any 13A driver because typically pin3 (Star3) is unused. Unfortunately, that pin is not in a convenient location to make this mod easy (but where is the fun in easy?). Even E-switch drivers can benefit from this mod. In fact they would have the most to gain because they are always drawing some current. But I don't have any to test this out on... Likewise, any driver using any micro-controller should be able to adapt this technique to reduce current.

Somewhat off topic…
Does 112uA = +/-1A per year?
So a typical 3000mAh 18650 would drain a third of its capacity in a year with a 112uA parasitic drain?

You are joking right?! As I said before CC shouldn’t be used for software and even CC itself has it in its faq:

https://wiki.creativecommons.org/Frequently_Asked_Questions#Can_I_apply_a_Creative_Commons_license_to_software.3F

Anyway, to sum it up. Tido use GPLv2 for BLF-VLD and JonnyC use Public Domain for Star. And then you use GPLv3 for blf-a6. Those are the ones that you can safely use then.

With CC-BY-NC-SA, you should be safe to use the code for your own use, and to publish modifications you make of it, as long as it’s under the same license and you give credit to DrJones. Selling a light with a version of that software is likely not allowed, and as a guess no selling of it is DrJones intent. I don’t know of a software license that allows that sort of use, CC-BY-NC-SA does.

From some random page I pulled up with a quick Google search:

AFAIK the GPL also allows commercial distribution, and doesn’t specifically require attribution. TK can tell us, as she works with this stuff all the time. But, I doubt those things would be hard to add if they were important to you. I think the GPL does require re-distributors provide a link to the unmodified original code, though. That would probably count as attribution. Like I said, ask TK.

Well yes, your math is correct (if you ignore self discharge), but why would the light will be in LVP mode if the cell has a full charge?

This mod helps protect the cell once it is depleted. At that point there is very little reserve capacity to feed that 112uA drain. Dropping that current to 2uA gives you 50X more time to realize that you left the switch ON. Is this a solution to all the world's problems? No, but it is a small step in the right direction.

The GPL requires re-distributors to provide the source code for whatever they are distributing. If they modified it, they need to include their modified version. If it’s unmodified, they should include the original version. Aside from just guaranteeing that everyone can use and mod it, it is also intended to make sure that people share the improvements they make.

This can be inconvenient for vendors though. It would mean, for example, that if RMM sold drivers with the BLF-A6 firmware, he would need to include a link to (or copy of) the BLF-A6 source code or at least provide it to anyone who asked for it. With the public-domain(ish) STAR firmware, he doesn’t need to do this.

Some people prefer BSD-style licenses, which make virtually no demands on anyone. One can modify BSD-licensed code and sell products using it with no need to share their code or improvements. In fact, this is where much of Microsoft’s code came from; it’s based on old BSD code. There is an ancient and ongoing debate about whether “share” or “share and share alike” is more “free”.

Regardless, I’m happy about contributions people share under any open license. You’re helping people you may never even know about. :slight_smile:

A few noob questions, what does this line do?

#define F_CPU 4800000 // CPU: 4.8MHz PWM: 9.4kHz ####### use low fuse: 0x75 #######

And these two?

#define pwminit() do{ TCCR0A=0b00100001; TCCR0B=0b00000001; }while(0 ) //chan A, phasePWM, clk/1 ->2.35kHz@1.2MHz
// #define pwminit() do{ TCCR0A=0b00100011; TCCR0B=0b00000001; }while(0 ) //fastPWM

The two last ones look like two different ways of running pwm. And the first one seems to be somehow related.

Edit: And this one?

#define PWM OCR0B

It sets the CPU clock speed and pulse generator options. It’s a little easier to read the parts of STAR which do the same thing, or the attiny13a reference manual has full details on which bits do what.

The most common options are whether to use “fast” PWM (18.75 kHz sawtooth wave) or “phase-correct” PWM (9 kHz triangle wave), and single channel or dual-channel PWM. In single-channel mode one can also select whether to use variable PFM (pulse frequency modulation) or stick with the default speed.

Ok, good to know. I didn’t know that pin3 was equivalent to star3.

Anyway as i see it, i hope this improvement will be picked up as a standard feature in the LVP in future revisions of the attiny13a drivers.

Seems like the obvious next step, for extending the protection of the LVP in single battery applications & multi battery LDO drivers.