Attiny25/45/85 FW Development Thread

Mike - this might be the correct thread. As far as I know, Bistro has no dedicated thread, so it's either this thread or the firmware thread: https://budgetlightforum.com/t/-/32545.

The bottom line would be asking the author - ToyKeeper, and her firmware thread would be the better of the two since she created the other one.

I just looked the code over and it seems you are right - 1/2 second delay in the main loop, then the "overheat_count", incremented by 1, has to be greater than 15 to do an adjustment, and when it does an adjustment, "overheat_count" is reset to zero.

So it doesn't adjust for 8 secs, then only will adjust every 8 secs or so thereafter.

Also be aware it adjusts one "level" per drop-down adjustment, and there are 64 levels defined for the full range of brightness/output.

All I can offer for my explanation is that Bistro was written for single LED DD lights in mind, for the BLF SS/Cu X6 or Cu X5 class running at 4-5A. Also I can say others have seen this problem and tweaked the algorithm. You can bump up the decrement factor or bump up the frequency of checks, and/or add intelligence to do it smarter. Dr Jones got his own PID algorithm implemented for temp monitoring, but has not released it to the public. I heard Atmel has a sample PID in source code as well, but will probably not fit in to a 25's 2K.

Yes - you are right about the 80 seconds. Here's the top 11 levels for FET PWM values:

129,137,146,155,164,174,184,194,205,216,255

I agree, a triple in a thin tube light is a crazy design when it's fully max'ed out. I would never put one in the hands of someone who is in-experienced with these sort of things. Bistro is just the firmware, and not designed for this intended use, accept for the fact it's given out open and freely in source code, so the designer of a flashlight can mod it as they like.

You also might want to consider a turbo timeout - set the timeout to 30 secs, and it drops one full mode, which could be down to 35-40%, depending on you mode definitions, but of course temp monitoring has advantages for more circumstances.

In my lights Iā€™m using my own driver software anyway but this driver is used in mass production lights meanwhile, and perhaps it might be safer to implement a configurable turbotimer than a temperature regulation which wonā€™t work with many lights.

Oops, was still editing, repeatedly.... Again I put responsibility squarely on the manufacturers. TK has not made a penny on the use of Bistro by the Chinese manufacturers. The BLF group buys are one thing - buyers know or should know, but when the manufacturers turn that into a commercial light, it's all on them.

I agree regarding the responsibility of the manufacturers but often I doubt they know what they are doing ā€¦

Made some progress over the weekend on implementing/adding a ramping mode to Narsil. Testing it in a SupFire M6. The ramping is pretty much fully implemented, but it breaks all the other UI stuff for now, til I work it all out, like the lock-out, entering configuration modes, displaying battery voltage, toggling the locator LED, etc.

I used posts on BLF by ToyKeeper and blueb8llz as a guide for implementing how it works. I'll be providing more details.

One note is I'm currently using 64 levels spread over 3 seconds to fully ramp the range. I tried 2 seconds at first, but could not stop at moon mode. With 3 secs, it's fairly easy now, but just not sure if 3 secs is too slow. Maybe 2.5 or so is bout ideal -- not sure. Certainly it's all touchy/feely issues, probably a lot of personal preferences thrown in.

Nice work with the black magic Tom. You be careful now. :slight_smile:

More progress this eve on ramping support in Narsil:

  • got lock-out working with same sequence as in non-ramping mode: 2 quick clicks followed by hold
  • got battery voltage check working same way also: 1 quick click followed by hold
  • got both modes of configuration UI working, again same or similar way as non-ramping, but for the main configuration setting, simply hold the button for 5.5 seconds, which is a full 3.5 seconds longer than a ramping sequence
  • changed ramp down - it stops now on moon mode instead of stopping by turning the light OFF

Still to do:

  • would like to get the locator LED toggling ON/OFF supported in ramping. Right now I lost that capability
  • need to add selection of ramping vs. mode sets to the configuration UI settings
  • might be on small bug to fix: after exiting lock-out, looks like 1st click is ignored, then all works fine
  • might see if I can clean up the LED output when in these special sequences (lock-out, batt voltage, config UI, etc.)
  • would like to get the ramping a little smoother look'n - right now a flicker is noticeable because it's changing PWM levels at 20 times/sec, whcih is somewhat noticeable. Would be better to adjust it closer to 100 times/sec which is possible.
  • might want to add in ramping a direct method to Hi/Turbo - possibly a dbl-click or triple-click

Overall liking the smooth ramping. Operation:

From OFF:

  • click to last level it was on
  • hold ramps up from moon to hi/turbo in 3 seconds, smoothly (currently 64 levels)

From ON:

  • click turns it OFF (this level is restored on the click from OFF)
  • hold ramps up, accept if it is on hi. If on hi, hold ramps down all the way to moon in 3 seconds, and stops there

It's simple and predictable, least that's my think'n... All the other special stuff is accessible by special sequences.

Thanks to blueb8llz and ToyKeeper for guidance, inspiration and support:

Ramping UI, Defined by blueb8llz (Ray)

Posted here: https://budgetlightforum.com/t/-/72707/10

In this thread on the Meteor M43: https://budgetlightforum.com/t/-/72707

It would need to be single click to turn the light on and off.
Hold switch while light is on, and ramps levels.
Hold switch while light is off, turns on moonlight mode.
Single click turns on light in last used mode including turbo.

Give me this ui, I promise to purchase at least two more units.

Iā€™d really like to test your firmware with my current XHP50 SRK (I blew the driver past weekend so Iā€™ll rebuild it with an attiny25)
I have an indicator LED around the switch so I can test this too.
Is it available for download somewhere?

Wauw Tom!!
Looks great and logical thus intuitive!

Very nice Tom E!
I might want to go with the ā€œoldā€ Narsil for my DQG due to the thermal issues. Maybe a cut down High would be better for my u.i., but this is definately nice for lights with normal cooling abilities.

Iā€™ve ran into a problem flashing the X6 driver:

ā€œC:\AVRusb>avrdude -p t25 -c usbasp -n

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1effff
avrdude: Expected signature for ATtiny25 is 1E 91 08
Double check chip, or use -F to override this check.

avrdude done. Thank you.ā€

Also with the -F function it doesnā€™t write firmware properly. I get the same signature error.

I donā€™t know how to use a .bat file yet, but I guess if a direct command doesnā€™t work, that wonā€™t work either.

Am I missing something or could it be a faulty Attiny25? Iā€™ve got another driver lying aroud, but before I brick both, I thought lets ask the BLF oracle in advance :smiley:

Narsil requires an 85 - won't run on a 25 because of program space requirements.

Yes, but not with the ramping features - still under development/test. Latest version posted is dated 2016-04-07, accessible here for the source code, AVRDude BAT files and manual:

https://drive.google.com/folderview - shared 25-45-85 projects

Dutcheee - Are you sure you have a properly wired USB dongle? I've posted this several times - there's bad info floating around on the dongle wiring, and it didn't really effect me til I started programming 25's, 45's, and 85's.

That messaging you are getting is probably related to a bad connection of the clip/dongle - I've gotten the same message many times. Sometime the clip position is off or the pins just aren't making good contact, but if you have the GND pin wired incorrectly, you can get similar inconsistent error messages.

Check detailed info and pics in my recent post #127 of this thread: https://budgetlightforum.com/t/-/30672

Ahaa, yes now I rememberā€¦ Thatā€™s why Iā€™ve got the coloured FT cable you recommended in my parts boxā€¦ :+1:

Already thought I had missed something, thanks! Will rewire and try again.

That helped a lot, I just flashed your psw-te25 firmware to the X6 driver. I donā€™t have the 85s in yet, so Iā€™ll try with the T25 first.

I had to bend the pins from my cheap ebay clip a little, but it works flawless!

Cool!

I'm always keeping a spare USB AVR complete w/cable and clip around now. The clips specially can start having problems with use. The first black cheaper one I used had pin problems - pins just loosened up and would back out on attempting to clip to the MCU. Became a real PIA fiddling with them all the time. Then a blue Pomona failed on me - one of the pins sprung out of the plastic tabs holding it in, and just couldn't get it to stay. This problem was probably my own fault though, abusing it to fit on MCU's in tight spaces.

I basically got the ramping mode operational in Narsil, accept for the To Do list below. There were a lot of little bugs along the way, but looks like it's operating pretty clean now, so far that is... Ramping can be chosen via the configuration settings, so you can still choose one of 12 mode sets, or ramping.

Code size is now 5496 bytes, 67.1% filled, so still lots of free space.

So the basic ops is fairly simple:

From OFF:

  • click to last level it was on
  • hold ramps up from moon to max level in 3 seconds, smoothly (currently 64 levels)
  • double-click to max level

From ON:

  • click turns it OFF (this level is restored on the click from OFF)
  • hold ramps up, accept if it is on the max level. If on max, hold ramps down all the way to moon in 3 seconds, and stops there

All the Narsil special/advanced features are now working in ramping mode:

  • lock-out works: From OFF, 2 quick clicks followed by hold (same as non-ramping)
  • battery voltage check: From OFF, 1 quick click followed by hold (same as non-ramping)
  • both modes of the configuration UI working - to access the main configuration setting, hold the button for 5.5 seconds, 2.5 secs longer than a ramping sequence
  • in ramping, locator LED is toggled by a triple click from OFF

Couple things still To Do:

  • turbo timeout (currently only works in normal mode sets, not ramping)
  • Low Voltage Protection - needs to be modified to lower levels (currently only steps down modes in a mode set)

Nice. :slight_smile:

This looks sweet Tom!
I have ordered the hardware to flash the AT85
And I already know which srk will be using the prototype Q8 driver
NICE!!!
So intuitive!

Does the voltage of the PWM signal from an Attiny chip vary with the battery voltage?

Sorry, I can't answer that in any certainty, but total guess is yes, because I don't think anything in the MCU is boosting or regulating voltage, but really dunno. Do you think it makes a difference to the FET or 7135's, because it just acts as a ON/OFF switch, not used directly as power out of the FET or 7135's?