Mod - GarryBunk's SecurityIng HD-016 (It's Finally Done!) - Pic Heavy

From a firmware point of view, voltage monitoring is easy. The hard part is dividing it to a usable range and then calibrating the actual values needed on the internal 8-bit or 10-bit scale. Er, and the other hard part is fitting more than one battery into a flashlight. It’s all about the physical build and circuitry.

Thermal step-down shouldn’t be too difficult (again, after build concerns and calibration), but we start to run into limitations on the attiny13 in terms of ROM space and switching the ADC channel. Especially on e-switch lights, since handling that takes a lot of room. As is, only 174 bytes are left.

JonnyC has been trying to put together a solid firmware with both voltage and temperature monitoring, and last I heard he is seriously considering requiring an attiny25 instead so there will be enough ROM to hold the code. Everything is do-able, just very hard to fit into 1024 bytes.

It’s also a bit difficult for me to ensure anything works without having the relevant hardware. You may have to do a lot of tweaking and calibration.

I'll do the best I can if you are game. I certainly don't want your time to be wasted and you seem to appreciate the same for me. We just need Garry's agreement to proceed.

Garry,

I'd like to say that pulling off thermal protection (not faux turbo timeout) and voltage monitoring with series cells is not a small feat. Adding another MCU to the mix creates more potential problems and potential failure points. I recommend making the indicator lights optional (hopefully, they can be worked in some hobbled form) and ditching the stock MCU.

To me, FW is the critical factor as there is very limited space in the Attiny13a. So I will do my best to work with whatever you and ToyKeeper want to do.

I'm fine with ditching the stock MCU. I'm also okay if you can't get the thermal protection to work and just keep the turbo timeout. I'm also okay if the voltage monitoring is hobbled down to just one of those LEDs flashing or something like that. I'm at your and TK's mercy as to what you all can pull off.

-Garry

Sounds good. Thanks Garry.

TK,

Sure you know, but just in case. The Thermistor circuit drops voltage to the MCU as it warms up. So I'm getting assuming it decreases resistance with heat as it is between ground and the "R1" of the voltage divider. It makes sense that is should work about like voltage monitoring from a FW point of view. Not sure if you can use the existing voltage monitoring and use an "Or" type clause. I think step down reading will likely be in the 60's.

No sure if turbo timeout takes up much space. If it does, real thermal protection seems like a better safety measure. Ideally, I'm guessing Garry would like to have both in place.

Finally, if you are able to include code for a voltage indicator output pin, the indicator LED's are hardwired to 5.19volts positive. The MCU appears to provide ground via a 470 ohm resistor. I could rewire them if you need them set up the other way around.

For some reason, I can't get the indicator emitters to light up when I take them to ground directly. They test fine with a DMM. I don't know what to make of that.

Cool. I can just invert the value then.

What I was thinking is to do something roughly like setting the maximum PWM level to 255 minus the difference between some hardcoded value and the actual thermistor value. This way, it would ramp down smoothly and gradually above a certain temperature, and step back up just as gradually when it cools off. The scale might need to be multiplied or curved or something, but it seems like the concept should work.

The goal is something similar to ZL’s “PID” thermal controls, which behave like this (but less advanced):

Low voltage, though, should just use the standard approach found in STAR. When low, step down. If it’s already at the bottom level, warn and shut off.

Not really. The attiny can only measure one at a time, and it’s asynchronous, so it needs a bunch of extra logic just for switching back and forth between the two ADC channels. Plus, low voltage logic never steps back up.

I agree, both would be redundant. Thermal protection will use more ROM space than turbo timeout though. We’ll have to see what will fit.

It’d be nice if we could just replace the standard attiny13 with attiny25 chips in all the common drivers. Twice the ROM space, and since half the space gets used for overhead it means like 1500 bytes to play with instead of 500.

I have no idea. I’ve only done voltage indicators once, and the circuitry side of things was already fully taken care of. I just had to do the measurement and logic in the firmware.

This is just a guess, but I would assume that the attiny’s output pins run at the same voltage as its power source, so whatever the buck is feeding the attiny. It can run at up to 5.5V though, I think, which should be enough. And to control how much power is fed to those indicator LEDs you’d have to insert appropriate resistors along that path; the attiny can only turn it on or off. I don’t recall off-hand what the default attiny output pin current is, but you’ll almost certainly need to reduce it for indicator light use.

Guys, don't want to break out your brainstorming flow to much, but I have an idea for my usage only leaving stock MCU in place as is. First to resume what we have in stock form. As I understand it (I might be wrong) we have three circuits parts: 1 controling/user interface and 2 power controling for each led.

Now, my idea is to put both leds in parallel on both power controling circuits parts. Leaving everything else as is I'm assuming we can get modes like 50%, 50% 100%, strobe. This of course is not very usable, but if I change sense resistance in the circuits to get: first 1/3 and in second 2/3 of desired power. Then I think we can get modes 33%,66%,100%, strobe.

This would be just fine for my usage leaving all other features (voltage indicators, thermal protection) in place. Not the best as would rather have strobe hidden and bit different mode spacing, but it's usable.

Can someone look if this mode is possible? Resistor mod is trivial to me, but putting leds in parallel is in question electricaly. Phisicaly I can just connect two black wires and we are done .

What do you think?

TK,

All that sounds good to me. I have no problem if you wish to go with a Attiny25. I believe I could use the same equipment I already have. I would just need to specify Attiny25 in Atmel Studio when first setting up your FW. I would need to order some 25's.

I will play indicator leds to see what gets them to work. It sounds like they must have some internal protection that blocks current when voltage is too high.

ledoman,

Interesting idea. I don't know enough about electronics to answer your question. It sounds like it would work. I have paralleled drivers before to increase current. I didn't have any of the drivers off though. So I don't know if there would be any kind of back flow issue. On this driver, I think you would have to connect both the positive leads and both the negative leads to each other to make it work.

Thanks, will wait what others have to say. Since hopefuly there is no PWM, just on/off, I expect no intereference between power circuits. Hopefuly!

I should mention that I don’t actually have any attiny25s or the tools needed to swap one out on an existing driver. I’m just basing my guesses on the usual difficulty getting everything to fit, plus JonnyC’s comments that he is having trouble with exactly the same features. I know I’ve had to pull some dirty tricks to make things fit into 1024 bytes in the past…

I can probably use a lot of what JonnyC already wrote, but I haven’t looked at the details yet.

^ I can only imagine how creative one has to get squeeze code into such a small space. Just let me know if you do decide to go with the 25. I would need to place an order for some. I'd do my best to test code since you wouldn't be able to do the same with actual hardware.

I wonder if I should just get a hot air gun.

Or I found a BLF member selling nanjg drivers with the MCU replaced, but they’re $15 each plus $5.50 shipping. For the price of three, I could probably get a hot air gun and a few attiny25s and be able to upgrade arbitrary drivers.

Hot air guns are great to have for all kinds of things. I find that even the cheapest ones work fine for reflowing.

Not sure if you would be interested in the conversation that I trying to start here.

Have you optimized the code enough? If you have based your code on Star there is a lot you can do. I’ve cut memory usage almost in half but still have the same functionality. Star is written for easy use and changing of modes and such, but can be optimized a whole lot to save space without changing functionality.

It depends. I’ve definitely squeezed a lot of extra features into the available space before, on other firmwares… There is a lot in STAR that I don’t need or care about, which helps. But in this case I don’t actually have hardware so I haven’t written much code.

I was surprised at how much memory could be saved from a few changes. Saved me from having to dig into ATtiny25 programming… for now at least.

I managed to fit 15 modes into 1024 bytes on an off-time based light, including a battery check mode and a bunch of different styles of blinkies and a pulse frequency modulated moon mode which smoothly self-adjusts its speed to compensate for decreasing voltage over time. And 2-level turbo stepdown and low-voltage protection. And a short/med/long button press UI.

So I might be able to fit everything into 1024 bytes for the light in this thread… I’m just not totally sure, and it’s hard to know until I have hardware to test on.

If there was more RAM, I could compress the code and fit even more… but attiny chips have nowhere near enough RAM to run a decompression engine and then store a larger program in memory.

Seems like you’ve done a lot of optimizing :slight_smile: I’ve got two individually controlled PWM channels with separate output pins, 8 individual modes per channel (each channel with it’s own mode memory), turbo timeout, low and critical voltage step down, short and long press UI (off time)… and still have room to spare… Not finished with it yet though, don’t need a total of 16 modes so I’ve got more space to work with if needed.

You don’t need any hardware to see if it fits, AVR Studio tells you how large the end result is after compiling.

Oh, I have the size calculation built into my build script. The question is whether the code actually works. I can easily make it small enough if it doesn’t have to work. :slight_smile:

In theory, practice and theory are the same. But in practice… well, not so much. Code is all theory until it’s running in its intended environment.

Yeah, I couldn’t get anything done without the hardware. It’s just that wrote you where not sure if it would fit, guess I misunderstood that a bit. Of coarse you can’t be sure of the size until it’s all been tried and tested, I know that all too well :slight_smile:

Regarding Attiny 13a vs 25, I'm not sure what all in involved with converting the FW over, but part of my thought process if I was a programmer would include the following:

  • The Attiny13 has been a challenge memory wise for quite some time. It probably has hobbled more than one programer.
  • The 25 is superior to the 13 and uses the same foot print.
  • Programing time will be needed to squeeze into the 13. This same time could be used to convert to 25. This time could be thought of as an investment into taking drivers to a new level going forward.