Flashlight Firmware Repository

2223 posts / 0 new
Last post
DEL
DEL's picture
Offline
Last seen: 2 years 1 month ago
Joined: 06/28/2015 - 08:35
Posts: 559
Location: Canada

ToyKeeper wrote:

FWIW, ohaya, I recommend measuring different values rather than trying to calculate what it will do. Try a PWM level, flash it to a driver, and try it with a full and an empty cell. If it’s too low, add one. If it’s too high, subtract one. Then try again.

At ~8 kHz, I have the BLF-A6 moon mode running at 2/255 on a single 7135 chip and it produces about 0.5 lumens. It decreases with voltage, but it’s not too bad… IIRC it drops from about 0.5 lm to 0.3 lm during the lifetime of a cell. On my attiny25 test host, I’m using 3/255 for moon on a single 7135, at 15.8 kHz, and it ranges from 0.55 lm to 0.34 lm (at 4.1V or 3.1V).

Sometimes even lower values work. My BLF-SRK with 32×7135 chips gets a moon mode at 16 kHz (fast PWM) with 0/255. Most FET-based drivers will also light up at 0/255 in fast PWM mode, but this level is highly voltage-sensitive.

FET-only drivers suck at moon mode; my last attempt with one of those went from ~3 lm (at 4.2V) down to 0.001 lm (at 3.6V) — even after I tried to correct for voltage by decreasing the off-time. So, at 4.2V it ran at 0/255 (16 kHz)… and then at 4.0V it did 0/128 (32 kHz), then at 3.6V it was down to 0/2 (~2 MHz PWM). It helped, but not enough. And I couldn’t bump it up to 1/255 because then it would go all the way up to ~10 lumens. At least it was neat watching the driver auto-adjust its output; it gave kind of a “soft turn-on” kind of effect.

Sometimes a higher value is needed. On a 8×7135 nanjg with an old XM-L T6, I couldn’t get the emitter to light up until 8/255 in fast PWM mode (~16 kHz). Swapping in an XM-L2 cut the lowest usable value by quite a bit.

Dropping the PWM speed does help with stability though… which is why I use phase-correct (~8 kHz) instead of fast (~16 kHz) for moon mode on most lights. But I haven’t found it necessary to drop the speed below that.

Mostly it depends on your driver, emitter, and cell voltage.

That is some interesting and large variation. All 7135s are obviously not created equal.
If the emitter makes a difference it is simply because the 7135s are not turning on fully?
Note that it may be normal for the tiny to have less trouble turning on one 7135 than multiple 7135s. I only looked at turn-on time with 8 7135s. The MCU output has limited drive current and it has to feed the combined 7135s gate capacitances at the start of each pulse. This is like shorting the MCU pin momentarily to ground until all these (very small) parasitic ‘capacitors’ charge up. Would have been great if we actually had a datasheet to know what we are dealing with.
If it is useful I can take oscilloscope screenshots some time to show the turn-on delay of the 7135s. Maybe compare 3*, 4*, 6* and 8* 7135 drivers.

This is my deluxe wooden light for testing :). At the moment it features an ISP quick connector soldered to a 105C to save the clip and frustration. The switch is a regular reverse-clicky from an old light.
The local 1000 uF capacitor is required to run PWM properly when hooked up with 1m leads to a power supply.

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 56 min ago
Joined: 01/12/2013 - 14:40
Posts: 10245
Location: (469219) 2016 HO3

Scope shots would be cool. Comfychair published some a while back, but he and his site went down since then. Here’s one of his results though:

In any case, yes, the emitter matters. With otherwise identical hardware, an XM-L2 will light up at a lower PWM level than an old XM-L. It also depends on the type of 7135 chips; the 350mA ones behave a little different than the 380mA ones. And it depends on the number of 7135 chips… it seems like 1x and 32x light up at pretty low levels, but 4x and 8x might require something a little higher (maybe). I haven’t tested the number of chips very much though.

I’ve seen a few drivers light up at fast PWM=0, a bunch at phase PWM=2 or 3, and a couple as high as fast PWM=9.

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

Anybody know if it would cause long-term harm to the Attiny13 for it to receive 5.5v directly to one of it’s I/O pins? I’ve tried it, so I know it doesn’t fry immediately.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

Not sure but could we just add a zener in line?

Pastebin                                      &nbs

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

If necessary I definitely could (easily).

Pyro, you probably already know I’m talking about the X6R driver.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

That’s why I said “we” Wink I remember that you put a resistor pad for pin 3 does a resistor not work to bring it to safe limits?

Oh BTW liking the firmware you’ve tweaked for it will probably use it with mine.

Pastebin                                      &nbs

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

Ooo that would save us a pin!

EDIT: Sorry, I understand now that wouldn’t work. Would still need to use pin3

Pastebin                                      &nbs

DEL
DEL's picture
Offline
Last seen: 2 years 1 month ago
Joined: 06/28/2015 - 08:35
Posts: 559
Location: Canada
pilotdog68 wrote:
Anybody know if it would cause long-term harm to the Attiny13 for it to receive 5.5v directly to one of it’s I/O pins? I’ve tried it, so I know it doesn’t fry immediately.

The rating of the IO pins is tied to what you feed on pin 8 (Vcc).
Except for pin 1 (the reset pin), the ‘absolute maximum’ rating on any pin is Vcc + 0.5 V.
And the maximum rating for Vcc is 6 V.

(Datasheet 18.1)

But running close to a device’s absolute maximum rating is usually a bad idea.

The datasheet says this:

Quote:
Stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent dam- age to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.
pyro1son
pyro1son's picture
Offline
Last seen: 2 months 2 weeks ago
Joined: 03/21/2013 - 08:18
Posts: 432
Location: UK

Could it be made so that a standard momentary firmware that only outputs one PWM channel, with a certain sequence of button presses could change the output pin and nothing else all modes stay the same but out of a different pin instead?

Pastebin                                      &nbs

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 56 min ago
Joined: 01/12/2013 - 14:40
Posts: 10245
Location: (469219) 2016 HO3

Yes, it’s definitely possible to make something which toggles the output channel. I’m not totally sure why, unless maybe you had two different emitters, but it can be done.

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

Cool, basically I like having a secondary Red emitter in my lights, sometimes useful mostly just novelty but adds something extra to it. Would be cool to have a full range of levels and pick with emitter to output from.

Pastebin                                      &nbs

DEL
DEL's picture
Offline
Last seen: 2 years 1 month ago
Joined: 06/28/2015 - 08:35
Posts: 559
Location: Canada
ToyKeeper wrote:
Scope shots would be cool.

This is the stock 105C on the ‘wooden light’ above. It has eight 7135s and drives a mystery bin XML2.

I set up the PWM to 9.4 kHz phase-correct. (Actual frequency is 7.2 kHz, due to the un-calibrated clock we get at 4.8 MHz).
Since we are running at 7.2 kHz, each of the 255 sub-periods of the PWM signal is around 0.55 us (1/7200/255).
This is with a PWM duty cycle of 32/255:

We are zoomed in on only one ‘on’ pulse of the PWM train.
The yellow trace is the control pin on the MCU.
The cyan trace is the ‘output’ pin of the 7135s going to the LED.
Both are referenced to ground (normally cell negative terminal, although I was using a bench power supply).

The horizontal scale is 2 us per division.
The vertical scale is as indicated on the screen capture, but is not very important. Basically the 7135s are fully on when the blue trace bottoms out and fully off when at the other end. (I did trace the current as well, but the signal is much more noisy, using a 4” piece of AWG 22 as shunt does not help.)

So we see on the yellow trend that the MCU output turns on at the 2nd division from the left, struggles for 2 us, then settles as a straight line at 4 V.

The 7135s output oscillates for another 4 us (there is a control loop in each chip, and this wave is probably created by the feedback loop trying to catch up with 350 mA set-point). So our theoretical 32/255 × 2.8 A becomes more like 22/255 × 2.8 A.

This what we get at 2/255 PWM:

and 4/255:

8/255:

No surprises, we are just cutting the trend we see on the first screen capture.

Finally around 10/255 we start to get to the stable output level, just before the end of the pulse:

So basically we have a 6 us unstable transition period before the 7135s get to do what they are supposed to.

Typical circuit design strategy would limit this unstable operation to less than 10% of total operation to get acceptable stability, linearity, efficiency, repeatability, etc. That means not using pulses shorter than 60 us.
That is around 43% PWM at 7.2 kHz. And 86% PWM when using fast PWM at 13.5 kHz!
So we see we are not really playing inside the ballpark.
It also unfortunately translates to an ideal PWM frequency of 1/(60 us x 255) = 65 Hz.
Not going to happen.
So we have to live with the inconsistent PWM results or find a better way of doing it.

My compromise for the moment is to lower the PWM to 2.2 kHz.
Also lowering the self-imposed 10x criteria above to 2x limits me to using pulses longer than 12 us.
At 2.2 kHz, each 1/255 sub-period is 1.8 us. So PWM duty cycles greater than 7/255 is ‘stable’.

2.2 kHz PWM, 8/255 duty-cycle, more than half the ‘on pulse’ gives stable current:

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

I am working on my X6R, trying to get it to recognize when the charger is connected. I have connected a wire directly from the USB 5v+ to Pin 7 on the Attiny (normally used for LVP). Then I ran TK’s battcheck.hex. As expected, it reads out the full 255 adc value.

So now all we need is a bit of code that tells the light to turn off when it senses max voltage on Pin 3, right?
Something like:

If
adc_ticks = 255;
mode_idx = 0
else
mode_idx = last_mode_idx

Except in the proper language and for Pin3 instead of pin7.

Or even if it detects ANY voltage on Pin3, it doesn’t have to be specific.

I’m trying to get this working in the STAR momentary version I posted above.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

Would this work?

I’ve put it into the firmware here
Don’t know it it will actually work and can’t try to compile it as I’m currently at work.

Pastebin                                      &nbs

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

pyro1son wrote:
Would this work?

I’ve put it into the firmware here
Don’t know it it will actually work and can’t try to compile it as I’m currently at work.

I don’t really follow what you did, but I’ll compile it and try it on my test rig…. just a minute….

edit: it compiled and flashed fine, but no dice. The driver didn’t react at all to input on Pin3 (or pin7)

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

Dam. I’ll keep looking at it hopefully ToyKeeper might be able to see any issues with what I’ve done. I’ll start from scratch tomorrow and see what I can fine. Just bare in mine that I have no coding background and have never learnt any coding, I just hack and stitch stuff together.

Pastebin                                      &nbs

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 56 min ago
Joined: 01/12/2013 - 14:40
Posts: 10245
Location: (469219) 2016 HO3

At a glance, it doesn’t appear that code is checking pin 3 at all. The ADC hardware can only measure one thing at a time. With VCC on one pin and the charge sensor on another, it’s necessary to reconfigure the ADC between readings and then set it up for a fresh measurement. This will mean flip-flopping the ADC between two pins, toggling the pin every time it goes through the main loop.

Also, it looks like you told the code to step down incrementally before shutting off, like what the LVP does, instead of just shutting off. And it’s sharing the same “lowbatt_cnt” counter as LVP, so I’d expect it to act more than a little bit weird. Like, if it detected the charger being connected, it’d bump up the counter. But then LVP detection would see that the battery is fine, and reset the counter to zero. And it would keep repeating that while the light stays on forever.

I’ll be doing something similar soon, but instead of LVP + charger, it’ll be measuring LVP + temperature. So maybe I’ll have an example of how it can work soon. Also, I think JonnyC already did something like this in his thermal step-down branch, but I’m not sure how close it is to finished.

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

I thought it would take much less code. As you said, it doesn’t need to ramp down or delay and check a few times before acting, just set pwm=0 or mode_idx=0 as soon as any positive input is sensed on Pin3.

I thought it would just be as simple as changing mode order on Star3 was/is.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 56 min ago
Joined: 01/12/2013 - 14:40
Posts: 10245
Location: (469219) 2016 HO3

Yeah, I’m not sure if the ADC is even required for this. It might be able to detect the charger based only on whether the pin is “up” or “down”.

Can’t say for sure without trying it though.

… which you could probably do by using a stock build (with the pin 3 “star” enabled) and checking if it uses a different mode order depending on whether the light is plugged in.

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

ToyKeeper wrote:
Yeah, I’m not sure if the ADC is even required for this. It might be able to detect the charger based only on whether the pin is “up” or “down”.

Can’t say for sure without trying it though.

… which you could probably do by using a stock build (with the pin 3 “star” enabled) and checking if it uses a different mode order depending on whether the light is plugged in.


Ok, so I flashed it with the FW version that I posted earlier, which still has the Star3 mode order code intact. Without the lead from the charger soldered, it functions correctly. With the connection to the charger but the charger NOT powered, it toggles Star3 and switches the mode order. When power is applied to the charger, mode order switches back to the original order.

Also, the driver will run without external power supply. With only power connected to Pin3 (not pin 8 ) the driver functions normally.

Edit: Just discovered that the Attiny gets extremely hot with the 5v running directly into pin3, so we definitely need a limiter inline.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

As useless as my bit of code was at least were making progress I will see if it can get a test rig built this weekend and have a play

Pastebin                                      &nbs

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

Not sure if this works but I’ll try give it a go over the weekend.

Pastebin                                      &nbs

ToyKeeper
ToyKeeper's picture
Offline
Last seen: 9 hours 56 min ago
Joined: 01/12/2013 - 14:40
Posts: 10245
Location: (469219) 2016 HO3

Drat, it sounds like the easy method doesn’t work. Sad

RMM
RMM's picture
Offline
Last seen: 1 month 1 week ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

I've measured some FET drivers PWM on my scope at around 17 KHz, but I've never seen one go up close to 19 KHz.

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

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

pyro1son wrote:
Not sure if this works but I’ll try give it a go over the weekend.

When I flash that, the driver behaves very strangely. I can’t even work out a pattern.

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 3 weeks ago
Joined: 05/30/2013 - 23:31
Posts: 6420
Location: Held against my will in IOWA, USA

ToyKeeper wrote:
… which you could probably do by using a stock build (with the pin 3 “star” enabled) and checking if it uses a different mode order depending on whether the light is plugged in.

pilotdog68 wrote:
Ok, so I flashed it with the FW version that I posted earlier, which still has the Star3 mode order code intact. Without the lead from the charger soldered, it functions correctly. With the connection to the charger but the charger NOT powered, it toggles Star3 and switches the mode order. When power is applied to the charger, mode order switches back to the original order.

ToyKeeper wrote:
Drat, it sounds like the easy method doesn’t work. Sad

The driver is responding to the charger being powered, we just need to make it respond in the way that we want.
I tried this, but no dice

Plus, we need to have it check pin 3 continuously, not just when power is first applied.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

OK I’ve flashed my latest attempt and I just get the modes in reverse order. My additional Beacon works tho which is a start Smile

Pastebin                                      &nbs

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

I tried this just to see if it was doing something

Quote:
if ((PINB & (1 << STAR3_PIN)) == 0 ) {

mode_idx = 2;

} else {

mode_idx = 3;

}


If I power the driver with the charger attached but not powered, it comes on in mode 2.
If I power the driver with charger also powered, it comes on in mode 3.

I’d say that’s progress!

The problem is that it doesn’t change if you connect/disconnect the charger while the driver is already on, and I can no longer change modes (it stays in whatever mode it came on in)

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

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

-Just tried:
PCMSK = (1 << SWITCH_PIN) | (1 << STAR3_PIN);
But no luck-

It’s just occurred to me that I’m being really stupid. I don’t actually have pin 3 connected. I hadn’t but a resistor inline

Pastebin                                      &nbs

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

OK I’m done for tonight I’ll have another crack at this tomorrow.

I’ve even tried adjusting MTN-Mom as it has temp sensor so any input would shut off but no luck so far.

Pastebin                                      &nbs

Pages