Attiny25/45/85 FW Development Thread

1901 posts / 0 new
Last post
DavidEF
DavidEF's picture
Offline
Last seen: 2 hours 40 min ago
Joined: 06/05/2014 - 06:00
Posts: 4988
Location: Salisbury, North Carolina, USA

I like those mode sets. Looking forward to seeing this stuff included in a light somewhere that we can buy for a budget price. Wink

Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone.
-Ayn Rand

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

Interesting. And cool. And sorry, I haven’t had time to try yours out either. Smile
(I don’t even have a tiny25 hooked up to an e-switch yet, though I at least have the parts)

What I’m making is a little different… the 8 mode groups are simply 1 to 8 total modes, all evenly-spaced. Separate option for whether there should be a moon mode, so it actually does N+1 modes if moon is enabled. This means the BLF A6 defaults would be group 6 plus moon, or group 4 without moon.

Basically, pick how many modes you want, choose whether to add moon, choose low-to-high or high-to-low mode order, choose whether the “medium press” does reversing or not, choose whether to enable mode memory, choose a maximum temperature… etc. I’m hoping it can cover almost everyone’s preferences. I’m also hoping the missing parts will fit into the ~600 bytes I have left on the attiny25. If not though, I can cut a couple of space-hungry optional extras.

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

With OTC, LVP and e-switch all on one pin and dual switch firmware like this. I can see some very creative and exciting firmware being used in further group buys.

Pastebin                                      &nbs

Tom E
Tom E's picture
Offline
Last seen: 1 hour 7 min ago
Joined: 08/19/2012 - 08:23
Posts: 10331
Location: LI NY

This link is current source, current BAT files for fuses, etc.: drive.google.com - eSwitchBrownOut. Again, need to do further enhancements, but this is current state. ZIP file contains full 6.2 project - didn't update to Atmel Studio 7.0 yet. I'ts built for the 85 but should work for the 45 as well.

Update 10/08 eve:

Got in more improvements, bug fixes, and test hours (well, maybe minutes...).

  • Broke out moonlight mode as a separate config setting so it's more flexible, more mode set options, so now there are 64 combos total!
  • re-ordered the sets of modes so 1 click is a 1 mode set, 2 clicks a 2 mode set, 3 clicks a 3 mode set, etc. This is good up til 6 clicks, but 7 clicks is a different 3 mode set, and 8 clicks is a different 4 mode set
  • played with the timing of blinks and quick clicks for the lock-out setting and clearing - think it's easier now to do
  • Bug Fix: if the light is in mode 1, could not get into strobe -- fixed that now
  • expanded the stored config settings from one byte to two bytes. Wear leveling uses a 128 byte EPROM buffer, so it rotates around 64 times.
  • added a "Turbo timeout" setting to the config settings, so now there are 5 settings in config mode:
    1. mode sets of 1 to 8 sets (1 to 8 clicks)
    2. moonlight mode is toggled
    3. mode ordering is reversed
    4. mode memory is toggles
    5. turbo timeout, where: 1 click disabled it, 2=30 secs, 3=60 secs, 4=90 secs, 5=2 mins, 6=3 mins, 7=5 mins, 8=10 mins

 Tried to make config mode easy to access, and easy to set values or skip values.

  • To enter config mode from OFF or ON, hold the button for 2 seconds (acknowledged by two slow blinks)
  • you are now in mode set selection, 1-8 clicks to choose your mode set or no click to skip
  • in 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (moonlight)
  • 1 click toggles moonlight enabled or disabled
  • again 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (mode ordering)
  • 1 click toggles the current mode ordering setting (lo->hi or hi->lo)
  • again 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (mode memory)
  • 1 click toggles the mode memory ON or OFF setting
  • again 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (turbo timeout)
  • 1 click turns OFF turbo timout, 2-8 clcisk chooses the time to use for turbo timeout (as listed above)
  • again 4 seconds with no clicks, the setting times out and three slow blinks indicate you are done, and back to normal mode of OFF

 

pilotdog68
pilotdog68's picture
Offline
Last seen: 1 week 3 days ago
Joined: 05/30/2013 - 23:31
Posts: 6346
Location: Held against my will in IOWA, USA

Did you still keep a version that fits on the 25? I foolishly only bought 25’s instead of larger models, but I’m looking for a good FW for my 7G3CS.

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Tom E
Tom E's picture
Offline
Last seen: 1 hour 7 min ago
Joined: 08/19/2012 - 08:23
Posts: 10331
Location: LI NY

Ohhh - I'm up to bout 2500 bytes - blew past the 25... Still have the e-switch and brownout power switch support version which fits in a 25 though, just no config settings in the UI.

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

I’m going to have to order some 85V’s soon to try some of these firmware’s out. I’m still waiting form my 25’s to arrive.

Pastebin                                      &nbs

DavidEF
DavidEF's picture
Offline
Last seen: 2 hours 40 min ago
Joined: 06/05/2014 - 06:00
Posts: 4988
Location: Salisbury, North Carolina, USA

Tom E wrote:

This link is current source, current BAT files for fuses, etc.: drive.google.com – eSwitchBrownOut. Again, need to do further enhancements, but this is current state. ZIP file contains full 6.2 project – didn’t update to Atmel Studio 7.0 yet. I’ts built for the 85 but should work for the 45 as well.


Update 10/08 eve:


Got in more improvements, bug fixes, and test hours (well, maybe minutes…).



  • Broke out moonlight mode as a separate config setting so it’s more flexible, more mode set options, so now there are 64 combos total!

  • re-ordered the sets of modes so 1 click is a 1 mode set, 2 clicks a 2 mode set, 3 clicks a 3 mode set, etc. This is good up til 6 clicks, but 7 clicks is a different 3 mode set, and 8 clicks is a different 4 mode set

  • played with the timing of blinks and quick clicks for the lock-out setting and clearing – think it’s easier now to do

  • Bug Fix: if the light is in mode 1, could not get into strobe — fixed that now

  • expanded the stored config settings from one byte to two bytes. Wear leveling uses a 128 byte EPROM buffer, so it rotates around 64 times.

  • added a “Turbo timeout” setting to the config settings, so now there are 5 settings in config mode:




    1. mode sets of 1 to 8 sets (1 to 8 clicks)


    2. moonlight mode is toggled


    3. mode ordering is reversed


    4. mode memory is toggles


    5. turbo timeout, where: 1 click disabled it, 2=30 secs, 3=60 secs, 4=90 secs, 5=2 mins, 6=3 mins, 7=5 mins, 8=10 mins

 Tried to make config mode easy to access, and easy to set values or skip values.



  • To enter config mode from OFF or ON, hold the button for 2 seconds (acknowledged by two slow blinks)

  • you are now in mode set selection, 1-8 clicks to choose your mode set or no click to skip

  • in 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (moonlight)

  • 1 click toggles moonlight enabled or disabled

  • again 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (mode ordering)

  • 1 click toggles the current mode ordering setting (lo->hi or hi->lo)

  • again 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (mode memory)

  • 1 click toggles the mode memory ON or OFF setting

  • again 4 seconds with no clicks, the setting times out and two slow blinks indicate you are in the next setting (turbo timeout)

  • 1 click turns OFF turbo timout, 2-8 clcisk chooses the time to use for turbo timeout (as listed above)

  • again 4 seconds with no clicks, the setting times out and three slow blinks indicate you are done, and back to normal mode of OFF

 


That UI sounds great! And I like the way config works. Some will say it takes too much time. But really, how often will you config your flashlight? 8)

Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone.
-Ayn Rand

Tom E
Tom E's picture
Offline
Last seen: 1 hour 7 min ago
Joined: 08/19/2012 - 08:23
Posts: 10331
Location: LI NY

Ohhh - bout the time it takes... There's a shortcut built in. If you always wait for each setting to time out, yes, it would take at least 20 seconds (4secs x 5) to complete. But, instead of waiting if you click&hold, it skips to the next setting. So using the shortcut, it's pretty quick. I pretty much always use this shortcut now when I'm testing, and I've been doin lots of testing...

An issue with many firmware versions that support configuration, is the # of continuous fast clicks you have to do to get into configuration. With this, all you have to do is press and hold for 2 seconds, and you're in.

I was thinking of adding an "abort", so another words, if all you want to do is toggle moonlight mode, after you did moonlight toggle, you could bail out of configuration mode altogether, quickly. I think I can still do this with an extra long click&hold - it shouldn't interfere with anything and should be pretty quick, like 1 second or so, and is consistent with how this UI works (an extra long click in normal operation is strobe mode).

Also when you are in configuration settings, a click will always cause a blink, so you get feedback/acknowledgment that you did the click.

Biggest issue I can see with this is losing track of where you are -- in which one of the 5 settings. Originally was thinking of varying the blinks between settings, ex: entering setting #1: 1 blink, entering setting #2: 2 blinks, etc. I decided to just use 2 blinks for each setting entry because I thought the blink count itself would be hard for the user to count/track themselves, and also though one blink to start this doesn't feel right. I could of course use a different timed blink sequence to indicate you are entering configuration mode though, then do the 1 blink for the first setting - that would help.

There's lots of ways of doing all this of course...

Tom E
Tom E's picture
Offline
Last seen: 1 hour 7 min ago
Joined: 08/19/2012 - 08:23
Posts: 10331
Location: LI NY

Here's the latest doc/notes link: https://drive.google.com/file/d/0B1IxYZuk4DjcTUc5Z3ZkV3lsQnM/view?usp=sharing

This will eventually become the manual...

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

I spent a little time reading the manual tonight, and got temperature measurement working. I’m not 100% sure I’m doing it right, but at least it works. I get a value of 74 for room temperature and 82 after holding a hair dryer up to the driver for a while. Seems like a narrower spread than I expected, but it’s enough for my purposes.

Then I added thermal step-down (and step-up) to bistro.c. When the driver is heated, it’ll step down until the temperature is below the threshold. When the driver is colder, it will step back up until it either gets back to the original level or it gets too hot again. It currently has 64 steps in this thermal ramp.

I haven’t tested it in an actual light, but it works well with a hair dryer controlling the heat.

Let’s see… I also added a pseudo-random strobe, but it’s mostly just a proof of concept and the randomizer doesn’t seem very good because the ROM contents are less chaotic than I had hoped. And there are some other recent additions, like letting the user choose two or three levels of offtime (enable medium press?), and volts+tenths in battcheck mode.

The latest build is 1564 bytes, though some of that is extra junk which will probably be taken out later. I set 2048 as my limit so it will work on attiny25.

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

I didn’t feel like stopping yet, so I got the thermal calibration mode working too. Basically, go to config mode, wait for the relevant option to scroll by, turn the light off. It’ll turn on in turbo next time, measuring temperature and saving the value until you turn it off. After a power cycle, it’ll then use the new value as its threshold.

Again, only hair-dryer testing. But if I calibrate it to room temperature, it thinks it’s always over-heating so every mode steps down until it hits moon. If I heat it up during calibration, everything works fine afterward (but steps down when the hair dryer is on it, and back up when the dryer is removed).

DavidEF
DavidEF's picture
Offline
Last seen: 2 hours 40 min ago
Joined: 06/05/2014 - 06:00
Posts: 4988
Location: Salisbury, North Carolina, USA

With the work being done by both Tom E and ToyKeeper, we’ll be seeing some amazing new drivers in the (hopefully near) future!

Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone.
-Ayn Rand

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

It can be hard to follow incremental threads, so here’s a summary of what the ‘bistro’ code does now. Basically, what’s on the menu so far? These things are already working:

  • Choice of 1 to 8 regular modes, plus an optional moon.
  • Choice of low-to-high or high-to-low order.
  • Mode memory, or not.
  • Reversing via medium-press, or not. (requires OTC)
  • Thermal step-down with an easy self-calibration mode to let each person set their heat threshold. Only works in regular modes though; blinkies are not temperature-regulated.
  • 64 brightness levels available, though they’re only normally seen during thermal step-down.
  • Soft start on regular modes.
  • Hidden modes when medium-press is enabled:
    • Two-speed police-style strobe.
    • Volts+tenths style battery indicator.
    • Bike flasher.
  • Most of the code is abstracted to eventually work on either a single-channel or dual-channel (FET+7135) driver.

It’s not done yet, and I know of at least a few things which need to be fixed (like LVP), but it’s getting there. I’m basically putting in as much as I can fit in 2048 bytes. Hopefully it can cover most people’s needs for a clicky-switch light.

pilotdog68
pilotdog68's picture
Offline
Last seen: 1 week 3 days ago
Joined: 05/30/2013 - 23:31
Posts: 6346
Location: Held against my will in IOWA, USA

Sounds pretty fabulous

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

Major Projects:  Illuminated Tailcap, TripleDown/TripleStack Driver

Spike
Offline
Last seen: 1 year 11 months ago
Joined: 04/21/2014 - 15:36
Posts: 2

ToyKeeper wrote:
  • Choice of 1 to 8 regular modes, plus an optional moon.
  • Choice of low-to-high or high-to-low order.
  • Mode memory, or not.
  • Reversing via medium-press, or not. (requires OTC)
  • Thermal step-down with an easy self-calibration mode to let each person set their heat threshold. Only works in regular modes though; blinkies are not temperature-regulated.

These are toggled through the config mode? Same 15 fast click to enter config as blf-a6?
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 3 hours 50 min ago
Joined: 01/12/2013 - 14:40
Posts: 6057
Location: (469219) 2016 HO3

Yes, same method for entering config mode. Fast-tap anywhere between 15 and 30 times (until it stops lighting up) then leave it on.

The config mode makes the timing and counting a little easier now though. Instead of “blink, blink, pause…” for each option it now blinks a number then kind of “buzzes” for a bit to show where the click window is. Click during the “buzz”.

Before:

  1. blink, blink, pause
  2. blink, blink, pause
  3. exit

After:

  1. blink buzz, pause
  2. bl-blink buzz, pause
  3. bl-bl-blink buzz, pause
  4. bl-bl-bl-blink buzz, pause
  5. bl-bl-bl-bl-blink buzz, pause
  6. exit

Some of these options invoke a special secondary mode. Like, to select a mode group, it will go into a beacon-like mode where it’ll slowly blink 8 times then pause, then repeat. Turn the light off after N blinks if you want mode group number N. Or, for the thermal calibration, it’ll turn on in turbo and wait for you to turn the light off to set the maximum allowed temperature.

Eventually I’ll try to make a diagram again, but I haven’t yet.

Halo...
Halo...'s picture
Offline
Last seen: 1 year 1 month ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Bistro revision 185 won’t build for me.

Quote:
bistro.c: In function ‘count_modes’:

bistro.c:326:20: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default]

uint8_t *src = modegroups + (modegroup<<3);

^

I did try out r175 but only briefly. I’ve been sick and had to work up energy just to download, build, flash. :Sp Also I didn’t / don’t see tk-random.h in the repository so I removed random_strobe.
ToyKeeper
ToyKeeper's picture
Offline
Last seen: 3 hours 50 min ago
Joined: 01/12/2013 - 14:40
Posts: 6057
Location: (469219) 2016 HO3

Halo… wrote:

Bistro revision 185 won’t build for me.

Quote:
bistro.c: In function ‘count_modes’:

bistro.c:326:20: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default]

uint8_t *src = modegroups + (modegroup<<3);

^

I did try out r175 but only briefly. I’ve been sick and had to work up energy just to download, build, flash. :Sp Also I didn’t / don’t see tk-random.h in the repository so I removed random_strobe.

Oops, I completely forgot to add the random header. Fixed.

About the warning, it’s not a fatal error, is it? For me, it doesn’t prevent gcc from compiling. In any case, adding the missing ‘const’ fixed it, and I re-pushed the changes.

Halo...
Halo...'s picture
Offline
Last seen: 1 year 1 month ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

You’re right, it doesn’t appear fatal. Oops

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

I finally put one of these drivers into an actual light and did some temperature testing.

At first I nearly destroyed an LED trying to set a heat limit, since apparently the MCPCB was floating instead of having good contact with the pill. Oops. At least the emitter still works, though moon is much lower than it used to be and there are some tint irregularities.

After fixing that, I’m finding that the pill-to-MCU thermal lag makes things difficult. When setting a threshold, the MCU may not be as warm (yet) as it should be. Then when stepping down later, it can sometimes step down much farther than necessary and then take a long time to come back up. And after it comes back up, it may not go as high as it should because the threshold is too low.

… though on a second test (I left it on turbo longer during calibration), it behaves much closer to how it probably should.

It may be because I’ve got it in a big copper pill, and maybe it would work better on a smaller light. But so far, although it works, it doesn’t work as well as I had hoped. And I may need to add a special state transition to bump it back up to the original level instead of short-tap taking it to the next level.

Mike C
Mike C's picture
Offline
Last seen: 3 weeks 4 days ago
Joined: 01/22/2014 - 08:03
Posts: 1649
Location: Sweden

I ditched my experiments with a temperature controlled mode. If the temperature rises above the threshold I just call the same critical routine as critical voltage and put the light in critical mode (either off or very low output depending on setting). The user has to manually switch modes or restart the light to get out of critical mode, which of coarse will only work if the temperature is lower.

I found that the different heat lag characteristics in different lights made it too much of a hassle to make a generic routine for all lights that wasn’t annoying.

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

After tweaking it until my battery got too low to heat the light up, I think I might have finally eliminated the thermal “bounce” effect (repeatedly over-shooting the target then rebounding).

… maybe.

I’ll find out tomorrow when the cell is recharged.

The thermal controls might actually need to be adjusted according to the physical host the driver is in, to account for varying amounts of thermal lag. It’ll be interesting to move the driver to a smaller host after I’ve got it working right, to see if it still works.

There’s also now an option to turn off thermal regulation. Just tap the button during the first second of its calibration mode, and it’ll calibrate itself to 255 (hot enough to cook pizza, I think).

Halo...
Halo...'s picture
Offline
Last seen: 1 year 1 month ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

For those that are interested in using it, could you add a build time option for an external thermistor to ground (as the temp increases voltage would drop on the attiny pin) instead of using the internal sensor? Attaching a thermistor to the pill with thermal compound should provide less heat lag.

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

Halo… wrote:
For those that are interested in using it, could you add a build time option for an external thermistor to ground (as the temp increases voltage would drop on the attiny pin) instead of using the internal sensor? Attaching a thermistor to the pill with thermal compound should provide less heat lag.

Sure, but I don’t have anything like that to test with so I can’t guarantee it’ll work. Smile

Do you know what changes the code would need? I suspect that the only thing which would need to be changed is the ADC_on_temperature() function in tk-voltage.h, to tell it to use a pin instead of the built-in channel. Or possibly just the definition of TEMP_CHANNEL in tk-attiny.h, where the rest of the driver layout is defined.

(I know, the naming schemes there suck… needs to be renamed better)

Oh, drat. I just realized this needs a slightly deeper change. The built-in sensor rises with temperature, but you say the thermistor value drops with temperature? I bet that could be worked around with a one-line change somewhere… like adding “temp = 255 – temp;” just before the end of get_temperature(). It’d be easier than swapping all the <s and >s, at least.

texaspyro
Offline
Last seen: 1 year 3 weeks ago
Joined: 04/29/2011 - 12:43
Posts: 4593
Halo… wrote:
should provide less heat lag.

The thermal lag, etc is not a problem. The things do not heat up fast enough to a level where it causes problems. If you are worried, you can adjust the trip point down a little to compensate for the lag/lack of direct thermal coupling, etc. Besides, a proper thermistor circuit is MUCH more complicated than just hooking the thermistor to ground and relying on the internal pullup (or an external resistor) to drive the thermistor.

Halo...
Halo...'s picture
Offline
Last seen: 1 year 1 month ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Here is my guess. Hoping you could tell me if I’ve missed anything. Well, besides the change needed since the pin voltage would drop with increasing temp. :~

tk-attiny.h:
#define TEMP_CHANNEL PB4

Plus add another digital input disable like on otc pin and voltage pin
#define TEMP_DIDR ADC4D // Digital input disable bit corresponding with PB4

tk-voltage.h ,
#ifdef TEMPERATURE_MON :

You already have this waiting
//DIDR0 |= (1 << TEMP_DIDR);

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

Halo… wrote:
Here is my guess. …

tk-attiny.h:
#define TEMP_CHANNEL PB4

Plus add another digital input disable like on otc pin and voltage pin
#define TEMP_DIDR ADC4D // Digital input disable bit corresponding with PB4

tk-voltage.h ,
#ifdef TEMPERATURE_MON :

You already have this waiting
//DIDR0 |= (1 << TEMP_DIDR);


Yeah… I originally tried to set DIDR, but the compiler didn’t recognize any of the symbols I used so I suspect it might not be relevant for the internal sensor. TBH, I’m not 100% sure I’m doing it right… but it does at least work. Smile

It should be straightforward for a pin-based sensor, if I look up the symbols it uses for the lone unused pin. It’s probably the same as setting up voltage or OTC, only with a different pin.

Halo...
Halo...'s picture
Offline
Last seen: 1 year 1 month ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Just checked, looks like it is ADC2D for PB4.

#define TEMP_DIDR ADC2D // Digital input disable bit corresponding with PB4

Halo...
Halo...'s picture
Offline
Last seen: 1 year 1 month ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Bistro is fabulous. Using it on a tiny85.

Pages