Attiny25/45/85 FW Development Thread

It looks like Mitko has gotten outstanding results on a FET he found. To me, the packaging looks like a SIR800DP, but I can't find it anywhere around.

Post #615 here: https://budgetlightforum.com/t/-/30080, data sheet: https://store.comet.bg/download-file.php?id=7648

Talked about here as well: https://budgetlightforum.com/t/-/35815

If anyone can find it, please post. Mitko was seeing 5-8% bumps on amps, and he mentioned they were even pretty cheap. Dunno about any side effects though.

For those who can shed some light on it, please check out the data sheet. I'm thinking there may be an equivalent sold under another name/part # somewhere.

The big deal for us is the amount of gate charge at a given gate voltage. Usually, the lower RDS on FETs have a higher gate charge. We are switching relatively slow (<20 KHz) but we are are also asking a lot more from the MCU than it was designed to do. We get away with it most of the time in the name of compactness and simplicity, but it would be best if there was a gate driver, even a makeshift one, that drove the FET gate. I have experimented a bit with this, and while it does work great I don't think that it is necessary to add the extra cost, however small, and complexity to these drivers.

Since we aren't really pushing the thermal dissipation limits on these FETs in the partial duty cycle modes, I think that adding a gate resistor back into the mix may be the easiest solution. This will ease the load on the MCU and we don't really care if the FET spends a few more microseconds in the linear region with the loads we are switching with them.

The way I see it is that we want highest amps at low cost and stability. It is not surprising that all three cannot be met without design changes. I’d say that only two out of three goals are possible.

  1. high amps and low cost but low stability (current design)
  2. moderate amps and low cost and stability can be achieved by inserting current limit resistor or FET with higher RDSon or gate resistor
  3. high amps and stability can be achieved by redesigning the board for better power distribution and filtering (power plane and bypass caps)

An analogy I’d like to make is building your own PC. Pairing a budget motherboard with a maximally overclocked CPU will result in an unstable system that reboots under load. Upgrading the motherboard can give you higher speed and stability but cost more money.

Ahhh - I really don't know what a gate driver is, but there is a real problem here -- both on a SupFire M6 (triple) and a single 219C light running a Tiny85 at 8 Mhz, the MCU was having all sorts of problems. The small cap seemed to have solved it for me. For the M6, I was using a 22 mm wight FET+1 driver, so plenty of room extra pad for the cap. For the 219C EDC light, wiring the cap over the MCU isn't a good solution, but it worked.

So you think the gate resistor would work? I can't recall now, but though I had a gate resistor on one that was failing -- I could be wrong. I've been pulling off the 10K-22K gate resistors I had on there, because I was using them previously thinking they would/could solve the flicker problem when going from hi to moon, but they made the flicker less bright, but it still occurred. The firmware change is what really fixed that problem, so, I thought they are no longer necessary.

Richard - I've used two of your 85 FET+1 drivers btw (MTN-17DDm 85 v0.01), both in 18650 EDC tube lights, but the LED- pad is a problem for sure.

How about trying 4mhz?



CLKPR divides the clock.

6.5.2 of the datasheet, page 32-33.

This should do 4mhz if I’m not mistaken.



// special procedure required to change clock prescaler

cli(); // Interrupts must be disabled

CLKPR=(1<<CLKPCE); // Enable clock change for next 4 cycles

CLKPR=1; // Clock/2, 4mhz

sei(); // Re-enable interrupts



I have not tested this. My lights aren’t having any problems and my tiny85 is in use.

Reducing the clock also reduces power consumption. :slight_smile:

Hhmm, I should try it. So I assume you still set the fuse(s) for 8 Mhz? The PWM's would be 1/2 the speed they are now at 8 Mhz? Think the clock is shared?

Yep, leave the fuses set to 8Mhz. It divides whatever the clock is set to in the fuses. Except the “Divide clock by 8 internally; [CKDIV8=0]” fuse. That fuse actually already uses the CLKPR.

The CLKPR should affect everything. It changes the clock entirely.

Didn't try the clock yet, but ran into yet another 85 FET+1 driver that had the same flaky problems, but with a single XM-L2. This time, it seemed to only behave bad with a LG MJ1 cell (3500 10A). Other cells, like a 30Q worked fine. The cap between the 85 grnd and Vc pin did the trick once again. This was in a swm C20C using RMM's 85 FET+1 driver.

I tried 8 MHz, 6.4 MHz, 4 MHz, and 128 kHz. They all had the same power spike issue. However, at least slowed down to 128 kHz I discovered that it seems to reset on the trailing edge of the strobe pulse instead of a leading edge. So it seems to reboot when the FET power is turned off.

I also tried each brownout setting but it didn’t seem to make any difference.

Oh, and after flashing at 128 kHz, it doesn’t seem to want to be flashed any more. Anyone have any idea how to recover that?

You have to slow down the ISP clock rate (to < 1/4 the CPU clock rate?)

I use a STK-500 for programming… don’t know the magic word for avrdude to change the clock rate.

With USBasp, try bridging JP1 that enables slow SCLK.

I tried -B and -i for avrdude, but it can’t set SCK on this usbasp. I think it’s a newer one which does it “automagically”. I tried bridging JP3 and it didn’t seem to change anything. I think JP2 is its self-programming jumper. JP1 is used for 5V/3.3V select, and doesn’t help either. I could try to update the usbasp firmware, but it requires extra hardware I don’t have.

So, no luck yet.

:~
I should have mentioned not to go too low. Unless one has a usbasp with updated firmware. I too noticed that we can’t seem to set SCK in our cheap chinese usbasp clones. And that slow jumper doesn’t seem to work either. Sorry, TK. :ghost:

Would you happen to have an arduino laying around? You can use one of them to update the usbasp firmware. Or use the arduino to reprogram your attiny. Looks like you need a slow sck version of the ardunioISP sketch. Like this one.

I suppose I could probably use a raspberry pi 2 to do it… or get an arduino and use that. But not for about a month, at least. I’ll have very limited access to things for a while.

Yea, if you have one available a raspi can do it. I see adafruit has a guide.

For the ATTiny13 I’ve been using:

avrdude -p t13 -c usbasp -u -Uflash:w:battcheck.hex:a -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m

What should I be using for ATTiny85?

I use 3 different .BAT files in my \AVRDUDE folder - one for testing the connection, one for fuses, and one for downloading. There are 3 fuse bytes for the 25/45/85, not two like the 13A.

T85.BAT:

avrdude -p t85 -c usbasp -n

85FUSES.BAT:

avrdude -p t85 -c usbasp -Ulfuse:w:0xe2:m -Uhfuse:w:0xdf:m -Uefuse:w:0xff:m
rem C3 for low byte is 6.4 Mhz

85NARSIL.BAT:

rem 85Narsil - downloads Narsil (Tiny85 e-switch UI configurable)
rem
avrdude -p attiny85 -c usbasp -u -Uflash:w:\Tiny254585Projects\Narsil\Narsil\Release\Narsil.hex:a

-Ueeprom:w:\Tiny254585Projects\Narsil\Narsil\Release\Narsil.eep:a

This is a great tool and reference for the fuses: ATMEL Fuse Calculator. It will generate the fuse params formatted to use with 'avrdude'.

Thanks guys. I am new to this arena and discussion like this is helpful.

It was only 6 months ago when I ordered my first 18650 (Latticebright “XP-E”) flashlight. Initially, I merely wanted to play with the electronics to modify the driver. Eventually, I concluded it is easy to get an MCU based driver, write my own firmware to achieve what I want to do. I was very apprehensive when I first considered the ATTINY85v. So I share my experience here for the next guy. May be he/she can approach with a bit more confidence.

I already have my own firmware written for the ATTINY13A. It has all the functions I wanted but a very bad UI for selection. I was at around 1020 bytes. So, to do a better UI, I need more flash space.

While I was still deciding, I blew my ATTINY13A by mistake. So, no more deciding, Mouser was happy. With my ATTINY85V from Mouser at hand, I rush to install it. My first one did not went well. I must have a hidden solder bridge somewhere. Removing it and resolder again, the thing worked like a charm. For some reason during initial install, the ADC always read around 2.7V to 2.8V, yet measuring with DMM, the ADC pin is reading right at 4.7K to ground and 19.1K to diode. I double check the code for mistaken where I might have set the ADC pin to OUT and send a 1 there, but that was not the case. So believing it is a dry joint, I desoldered the TINY85 and resoldered it. It works.

Beside the on for the test/development board, I have another 4 for real flashlights. After the first one , the other 5 were no problem. No technical problem anyway. All went very smooth except the 4th one. The next paragraph is a distraction:

The SAGA of Chip#4
My “work flow” is: first put it on SOIC clip to check for chip operations - read the flash, eeprom, fuses, etc., then bend legs, then install. On ATTINY85V #4, it slipped the clip and shoot out of the spring-clip away from my electronic work area to somewhere around my PC desk. An hour later, a miracle that I found it in that rat-nest of wires on the ground between the PC desk and the wall. So, I finish my read-test, programmed it, and re-read it AOK. I bend the leg on this 4th one. About ready and on final check, it felt off my plier. So problem, this is not like behind the desk… An hour later, I found somehow it landed BEHIND my backup SLA battery. Ok, at least I got it. So on to soldering. After testing the TINY13A and the NANJG105c, I removed the TINY13A and reach for my ATTINY85V#4 - it is missing! The chip is gone! I looked at the floor a dozen times, I just couldn’t figure out where this chip went. It is not on the table, it is not on the floor, and it did not felt into or behind anything! I looked, and looked, on the floor, move the stuff on the table, move the stuff from boxes around around the table… Where the hell is chip#4!!!

Back to about the 85V. I took it as a challenge to find out what I needed to do for code change. I did the research by the datasheets alone as a challenge. I came back to this thread to see what changes are recommended and I did do all those from the datasheet research alone. So I passed my own challenge.

  1. FCPU change
  2. ADC reference voltage bit change
  3. PWM change
    and, I did one more that I didn’t find mentioned here
  4. eeProm write address needs to change to H & L both since it has 512 bytes, L alone is not going to do 512.

The bending of the leg is not hard. it is best to re-flatten/re-align the end-part of the leg to ensure good contact with the pad on the PCB. Secure one outer leg (nearer to edge of PCB) first, check all leg for good positioning, then secure one more leg and recheck again. Then finish soldering, check the soldering and clean up any bridging.

Now, my 4 ATTINY85V flashlights has the features/functions I wanted exactly.

That was at times a frustrating project, but it works well now. I have four “new” flashlights with TINY85V, and still have a TINY85V on my work-bench “flash light” for more playing-around-with for future versions. Getting the TINY85V’s leg bend right and installed it right requires a lot of patience, but it fits very nice and the result is very rewarding.

The SAGA of Chip#4 Episode 2
By now, it was > 4 hours on this chip alone. I cleaned the floor slowly and gently an inch strip at a time - as far as 6 feet from the table clear wall-to-wall but found nothing. By now, I am totally puzzled. How can a chip this big just vanished! I gave up, sat on the floor, and a bit dumbfounded. Suddenly, something caught my eyes in mid-air. I grab a working flashlight - this time, not on the floor, not on the table, and about 2 feet off the floor. There it was, hung on a small spider-web between the table-leg and the wall in mid-air. Well, no spider in my house was going to eat silicon for dinner that night. That chip took me half a day to finally finish. Like I said, not really a technical problem. Just a hungry spider.

Hi,
i think i have a problem with bistro firmware or my board components.

It doesn’t access to hidden modes, instead it enters in configuration menu when i do a med tap, no matter what mode is set.

Setting memory on/off makes no difference, always works as next mode memory.

Any idea what the problem could be? :~

Rick NJ,

Thank you for sharing your experience. I really appreciated your chip searching experiences. I've have a couple 13a's I never found. I need to search for spider webs in the future. That is wild.

As far as bending the legs. I don't bend the legs until after I flash them. I then push the legs in at the inward arch that is just above the "foot". That approach as worked fine each time. I do find that I touch some pins up with a fine solder tip just to make sure vibration doesn't break the connection of pins that seem light on solder. With the pins some much taller, the extra solder doesn't interfer with future reclipping (reflashes).