Attiny25/45/85 FW Development Thread

If it didn’t step back up, it’s probably still in the green zone on that middle graph. To avoid constant bouncing, it has a window of a few degrees where it won’t step up or down. If it gets above the window it steps down, and if it gets below the window it steps up, but if it stays in that zone, it won’t make any changes.

The MCU’s temperature units seem a bit odd. It gives me a reading of 74 for room temperature (70 F?), 87 if I hold a hair dryer on it at its hottest setting for a few minutes (135 F?), and 62 after resting in the freezer (10 F?). That seems to be something like 4 to 6 degrees F per thermal unit, and the no-change window is 2 of those units.

By default, it’s:

  • 79 or more: step down (95 F?)
  • 78: do nothing (90 F?)
  • 77: do nothing (85 F?)
  • 76 or less: step up (80 F?)

That could mean it needs to cool by 15 degrees F before it’ll step back up… which is a bit much. This is probably made worse by how slowly the heat transfers to the driver. Basically, the ceiling gets set a bit low in order to start the step-down sooner, but then when it later stabilizes it might end up too low.

Oh, and the readings differ by at least 5 thermal units between different MCUs of the same type. So, the hardcoded default is likely to be off by 25 F (or maybe more) due to manufacturing variances. I set the initial value to work just right on one light, then tried another identical light with identical code and it thought room temperature was “overheating”.

Anyway, I’d suggest reflashing it if you can, with the window set to maybe 1 unit instead of 2. That’s the minimum to avoid constant adjustments but small enough to make it step up easier. IIRC, I tried this and found it still adjusted too much, but your mileage may vary. Look for this part:

    if ((temp < maxtemp - 2) && (actual_level < output)) {
        actual_level ++;
    }

Soon.

That’s cool!

I’m rather targeting the less experienced modders who are not able to fiddle with code and like to use this driver for different lights - and the experienced modders who don’t want to flash the driver multiple times in order to find the best ramping curve.

Can’t believe I never seen this thread. Maybe because the thread title didn’t look interesting or just because it has to do with boards, drivers, programming and software stuff And all things I’m not able to do.

But some very interesting reads here. I’m not close to finish reading this thread yet though.

Don’t know if you are aware of reading the ADC left aligned which means only the highest 8 bits of a 10-bit temperature reading. Reading all 10 bits should show the specified temperature resolution of 1 LSB / °C.

I’ll have to try using 10-bit temperature readings next time. It looks like the useful range (in 8 bits) is about 50 to 110, or perhaps 200 to 440 in 10-bit mode, which should translate nicely back into an 8-bit integer for convenience. If I understand correctly, that would be enough to cover the entire range the MCU will ever see in a flashlight. It’d probably need to average several samples to reduce noise, but that’s not hard.

The only cost there is a few extra bytes of ROM. And it shouldn’t be much compared to what’s needed for a proper PID algorithm.

It could probably also use this data to adjust the OTC, as you suggested. Maybe just right-shift the temperature reading by a few bits and add or subtract it from the threshold to compensate for variable OTC drain. It seems safe to assume the OTC and MCU will be near the same temperature. I’m not too excited about doing the measurement and calibration on that though. :slight_smile:

There have been some efforts to resolve OTC variability in hardware too, using higher-value resistors for the voltage divider and adding an explicit OTC drain resistor to help it discharge at a predictable rate. And a little talk of adding a big capacitor to keep the MCU running as long as possible after power gets disconnected, going into a sleep mode, and measuring “off” time with a low-speed watchdog timer. None of these are ideal, but all of them seem at least promising.

Just my personal opinion regarding thermal regulation:
I don’t really like the light ramping up and down by itself caused by temperature change. If the light can’t hold the required brightness level I rather prefer the same step down as is done using a turbotimer and step up again with a short click later. If the user can configure the turbo stepdown delay, the temperature limit and the level to stepdown to - even better.

I did some more tests with otc temperature compensation. It now works almost perfectly when bleeding resistor has been removed, and with bleeding resistor in place still much better than without compensation. As Toykeeper mentioned there should be some calibration. This can easily be done when doing calibration for the maximum temperature limit: user has to start this calibration with "cold" light (room temperature), just when started store the (low) temperature into eeprom. For "better" drivers which need less compensation (don't have any) probably decreasing the shift value will help - or use a multiplication or a lookup table instead for more granularity. Look up table might even be the best solution since there are only a few values to look up and optimal compensation is not linear (medium press otc value could even need some more compensation).

My code for banggood driver without bleeding resistor is currently:

#define OTC_SHORT_PRESS 235
#define OTC_MEDIUM_PRESS 200

...
uint8_t thermal_compensation = adc_init_and_read(ADC_MODE_TEMP);
uint8_t thermal_low = eeprom_read_byte((const uint8_t*)EE_ADR_THERMAL_LOW);
if ( thermal_compensation > thermal_low )
thermal_compensation = (thermal_compensation - thermal_low) << 4;
else
thermal_compensation = 0;
...
if ( otc_voltage > (OTC_SHORT_PRESS - thermal_compensation) )
...
if ( otc_voltage > (OTC_MEDIUM_PRESS - thermal_compensation) )
...

Edit:

thermal_compensation must not grow larger than OTC_SHORT_PRESS and OTC_MEDIUM_PRESS, a check for this should be added. If someone calibrates his light at a very low temperature, "OTC_SHORT_PRESS - thermal_compensation" may overflow and result in a too high value which may hinder the user to enter configuration mode with short clicks ever again (at higher temperatures).

Any windows user knows how to flash attiny 25 ?

On attiny13 i used this in a script :

Except the t13 (t25), what else i should change ?

The fuses:
-Ulfuse:w:0xD2:m -Uhfuse:w:0xDE:m

If you don’t change them SPI will be disabled and you can’t program the mcu with USBASP anymore!

Thanks .
I still get an error :

Edit : i use bistro

The fuses have to match up with the firmware as well. Need to know what 25 firmware - the firmware MUST be written for a 25, not a 13A. Bistro is for the 25 for example.

The author of the firmware pretty much always states what fuse values to use. Most of the fuse settings are required to be specific values, to match what the firmware is written for.

The error is NOT related to the fuses. USBASP can’t connect to the mcu, check the connection. In case of wrong mcu type setting you will get an other error message.

Edit:
if you’ve programmed the ATtiny25 before with the fuse settings for Attiny13 you can’t program it anymore without a special programmer. In this case the above error message (2nd) may apply. It happened to me once but I can’t recall the specific error message.
The 1st error message is not important and can be ignored.

Got it working by desoldering the attiny from the pcb and flashing it alone .

My latest order from oshpark (fet+1 drivers) seems to have something wrong … Built today 4 drivers : one with attiny25 , and it works like a one mode driver (like the led - and the ground is connected) , and 3 with attiny13a that don’t even light up…. Checked all 4 for shorts , but there aren’t any….

Sharpie i posted on the drivers thread , seems one pcb (the one with tiny25) had a short from the factory .
The other 3 drivers i don’t know what’s the issue .

Anybody tried the SSN( 105c) version of those controllers? Cause currently my biggest issue is the overheating, on theory they shouldbe the same

Give a clue or link - what are you referring to? What is "those controllers"?

Talking about the 105 degrees C version of ttiny 13 and 25: i see they are awailable at Mouser, at least the 25v SSN

Dang, thought you were talk'n bout Nanjg drivers. Hhmm, never heard bout over-heating issues. What happens? Has anyone else said/noticed this? Are the 25's more prone than the 13A to overheating? What 25 boards are you using - those Astrolux ones?

I use wight’s boards from the development thread , v013 . i build them from scratch .

Sorry I was responding to Mitko. But anyway, what are doing to handle the voltage spikes that cause the 25 to reset? Are you scoping the signals? Generic 13A boards and parts usually result in flaky problems with 25/45/85's -- all noted earlier in this thread.

BangGood (or Manker) that developed the 25 driver for the X5/X6's (runs Bistro) used a 12 uF cap, not the standard 10 uF cap -- that seems to fix the problems on that board (well they think it fixed it mostly), But I've done more.