Attiny25/45/85 FW Development Thread

We need a PWM-less thread to discuss getting these MCU's working Tongue Out.

Well current progress:

  • I reflowed a replacement 45, and back to working Smile
  • turbo timeout works, and it's dead-on accurate for 2 mins, better than I've seen on 13A's Smile
  • timing with the e-switch firmware is great - clicks vs. click/hold works perfect Smile
  • strobe works great Smile
  • mode changing is working flawlessly so far on one FET channel Smile
  • just can't get the alternate PWM channel working with the 7135 - tried FAST PWM on all modes and get no output at all Frown
  • tried LVP and doesn't seem to work with a cell even at 2.8v, maybe even 2.7v. It's a 22 wight FET+1 driver so I'm using a 22K resistor. Haven't experimented with values yet, but suspect something basic is not working Undecided.
  • did not confirm low power sleep mode yet - would be nice to know it's working with a low parasitic drain Undecided

Wish I could get a better handle on exactly how these MCU's differ from the 13A. Thought there was some differences in clocks, ports, etc., just cant' find it.

Update: Ok, I got LVP working now as well. Looked at the ADC support, and with the added features in this area (temp sensor, etc.), setting the 1.1v reference is now a different bit in the ADMUX register. I had a weak cell at about 2.7v, and sure enough, the firmware backed down output in steps til output dropped altogether - just what it supposed to do!

Now, still got dual channel support to figure out, with the PB0, pin #5 7135 output.

Great work Tom! I'm planning on working on this some more early next week. Want to get that temperature sensor going.

Hhmm. It all seems to be working now. Even the Phase Correction on 7135. All tests seem to be correct - amps indicate is truly working off the 7135 in the 1st 3 modes. Dunno what was wrong before - didn't "fix" anything, I don't think... Weird, but this is really nice!! Now I can do some serious programming with a whole nother 1K bytes (Tiny25) of code space SmileSmile!

Yes - the temp sensor would be huge as well, for sure.

Update: ZIP files of project/source code and BAT files are shared here: drive.google.com-244585. Hope this link works. You may have to sign in to Google in order to download, not sure...

This is for a wight style FET+1 driver with default 5 modes, first 3 on the 7135. It has a turbo timeout set to two minutes. I've only tested it on a ATTiny45 which should be running at 8 Mhz. It's not taking advantage of the 45's extended capabilities yet: temp sensor, extended available memory, etc.

Way to go Tom. You are the man! I finally got a 22mm board working and tested the UI of the FW you sent me earlier today. Same results as you reported. It worked great except for the Alt PWM channel. I started examining the code and came back to report and call it a night. My gosh, you got a lot done tonight.

Tom E just opened up the hobby to a whole new level!

EDIT: Status in OP updated.

Wow, guys, this is awesome! What I’d like to see is a guppydrv style mode group selection but using more advanced mode groups like we have on the BLF-A6 FW.

Funny, I was think'n the same exact thing - guppy style mode group availability w/advanced mode nav, w/all the bells and whistles of LVP, OFF time detection using a cap or brownout detection, temp sensing based output limiting, full e-switch and/or power switch support. And, of course, it should all be done in one firmware version.

This opens the door to a whole lot more versatility.

My first step (for me) is to get back to adding full power switch support w/OFF time detection to the e-switch firmware, so lights that have both can have it both ways - lights like the X6R, Yezl Y3, L4, and many others. I ran out of program space when a I tried this before. Could also be used for e-switch lights with a lock-out feature, so you have the effectiveness of a twisty, still with full e-switch support.

So, you’re saying that the firmware will have all the fancy mode groups and UI controls available to either e-switch or clicky, or even both in the same light - all supported in one firmware to rule them all? And, it would be cool to have both tighten-for-on (the standard twisty UI) and tighten-for-off (not very common, but better, IMHO) capabilities in the same firmware. Oh, and to complete the laundry list - both forward and reverse clicky support optimized. All of this should be user-programmable (or rather user selectable ) through the UI. Am I asking too much? 0:)

Probably short answer is yes - you are asking too much, or dreaming like me Smile. Besides, “There is only one Lord of the Firmware, only one who can bend it to his will. And he does not share power.”

However, “That there’s some good in this world, Mr. Frito… and it’s worth fighting for.”

Ran Tom E's FW through some paces and it did great. UI is solid and reliable. Strobe is great. I think Turbo timed out at 2min 6sec. Could not get it to exhibit any glitches. Very nice.

I tried working the LVP, but fried an emitter due to a careless turn of the bench top voltage dial. I never get reliable results trying to test LVP with my bench top power supply anyway. Don't have time to try testing with cells tonight.

It's a winner in my book. I'm going to go work on designing the OSH Park boards I discussed in the OP. Want to get those available and also place an order since they can have long lead times.

I did the bench PS testing, and it trips at 3.1v, so the ADC_LOW should be set at 120, and ADC_CRIT at 110 to get 3.0v and 2.8v, respectively.

Darn - just bricked another 45 MCU (can't verify the dnld). It doesn't work after this occurs, so something must be goin wrong in the AVRDude dnld process. I was able to do quite a few dnlds though before it happened again.

I know this is a little late but it has an interesting tidbit on the programing. Atmel for whatever reason chose to change the instruction set between the 13 and higher models.

Although it appears that the ATtiny x5 parts are a superset of the ATtiny13 parts, they are not code compatible - not even source code compatible, since not just the register addresses, but the bit locations in them are different.

Love your work Tom E not that I really understand it. I'd suggest at the end of the day we will all win with the work your doing. Thanks.

The author sounds like he really did not attempt a port, I'd say, very little actual programming experience. Technically, the instruction set is the same between the 13 and the higher end MCU's, with minor enhancements to support the added functionality. I could not find one example of them making a change, in a register layout for example, where the functionality of the register stayed the same. In fact I'd say they went out of their way to keep it the same. I think it was 3 to 4 lines of code we had to change, out of 500 or so. There was only one line of code that wouldn't compile. His page is a great exaggeration, and the list of differences shown has very little to do with code changes. I've done tons of porting code projects over the years, from asm to C, C to C with MCU changes, C to C#, and many others, and this port was much easier than most. Porting is actually a specialty of mine, I got a rep for that, and I've gotten contract jobs with only that one goal in mind. The development tools stayed the same, and the compiler is actually the same, it's just that some pre-defined libraries and constants that are MCU specific had minor changes. Also our flashlight driver firmware versions don't use all the features the MCU offers, so it's not like we had to delve into every register, so it's simpler than what it could be.

For me with this project, testing is a challenge because I'm used to having more advanced tools available, such as simulators, and interactive debuggers.

All I have to say is WOW!!

Great work everybody!

Awesome work guys! Thanks for putting in the hard miles!

Thanks for the kind words guys. Not having C programming experience/knowledge, I spent a heck of a lot of time in proportion to my output. I learned a ton, but still feel like I hardly know anything. Thank goodness Tom E came on board. He catapulted this project forward. I would still be trying to work out the bugs in my version if I was still alone on it. In a way, it would have been good for my development to not have his assistance, but I have to admit that I much rather be working on lights than learning C and creating code.

Thanks to Tom, we have a fully functional FW for the 25 already. It sounds like he has much bigger ambitions though.

Before taking the plunge and purchasing the MCU's, I debated going with one of the PIC MCU's. Pin compatibility with the vast majority of drivers currently used by us was the biggest deciding factor in favor of the 25. Then when I got the chips and ported an older version of Tom E's FW, I was really glad I decided to go with the 25.

I'm off to read a bit about the thermal sensor in this MCU since I'm not allowed to install Eagle on my computer at work.

EDIT: I agree with Tom E's assessment of that article Diode663 linked to above. I had read that at some point back in time. Comments from others here at BLF and that article kept me from taking the plunge on the 25 for almost a year.

Some data sheet excerpts regarding the temperature sensor:

17.12 Temperature Measurement
The temperature measurement is based on an on-chip temperature sensor that is coupled to a single ended ADC4 channel. Selecting the ADC4 channel by writing the MUX[3:0] bits in ADMUX register to “1111” enables the temperature sensor. The internal 1.1V reference must also be selected for the ADC reference source in the temperature sensor measurement. When the temperature sensor is enabled, the ADC converter can be used in single conversion mode to measure the voltage over the temperature sensor.
The measured voltage has a linear relationship to the temperature as described in Table 17-2. The sensitivity is approximately 1 LSB / degree C and the accuracy depends on the method of user calibration. Typically, the measurement accuracy after a single temperature calibration is ±10degreeC, assuming calibration at room temperature. Better accuracies are achieved by using two temperature points for calibration.

Table 17-2. Temperature vs. Sensor Output Voltage (Typical Case)
Temperature -40C +25C +85C
ADC 230 LSB 300 LSB 370 LSB

The values described in Table 17-2 are typical values. However, due to process variation the temperature sensor output voltage varies from one chip to another.

There is some more info and reference tables on pages 134 - 137 that will be needed to make the Thermal Protection Code ("TPC").

Elsewhere, this is written:

The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA. Voltage reference and input channel selections will not go into effect until ADEN is set. The ADC does not consume power when ADEN is cleared, so it is recommended to switch off the ADC before entering power saving sleep modes.
The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL. By default, the result is presented right adjusted, but can optionally be presented left adjusted by setting the ADLAR bit in ADMUX.
If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read ADCH. . . . When ADCH is read, ADC access to the ADCH and ADCL Registers is re-enabled.
The ADC has its own interrupt which can be triggered when a conversion completes. When ADC access to the data registers is prohibited between reading of ADCH and ADCL, the interrupt will trigger even if the result is lost.

This is an English speaking forum

BTW....ALL of you are making huge inroads!! I just think about what can been done with double the space. We aren't talking guppies anymore, we are looking at whales if not actual sharks LOL

^ I hear you brother. It sounds like Greek to me for the most part too.

So Programming Gurus, if I may pick you brains (yum, brains. Oh, don't tell the BLF Zombie Slayanator I said that). Please learn me something here.

Base on the data sheet, it appears that much of the code for LVP can be adapted for the temp sensing. For example:

  • Bit ADEN appears to already turned on as needed by the existing code.
  • ADC feeds are left adjusted in the code by turning ADLAR on (= 1).
  • We only need to read register ADCH because we don't need more than 8 bits of resolution. So the existing code read seem appropriate.
  • The If, Then, Else loop for LVP just need to be copied and modified for temp sensing purposes.


So, I have 2 questions as follows:

  • Can we not have LVP and Temp Sensing at the same time as both feed ADC feeds dump in Register ADCH?
  • I appears we need 1111 in the 4 MUX# bits. Can we just insert the following for the first line and then squeeze the second bullet text below into the code below "inline void ADC_on()" in the existing code?:
    • #define ADMUX ob00001111
    • ADMUX = (1 << REFS1) |

EDIT: If the answer to my first bullet is "yes", than can we some how use one of the various memory capabilities of the 25 to collect and report one of the ADC feeds?

EDIT2: Or maybe a loop that, clears ADCH, turns ADC1, waits for feed to populate ADCH,, reads ADCH, turns off ADC1, clears ADCH, turns on ADC4 (temp sensor), waits for feed to populate to ADCH, reads ADCH, steps down if needed, turns off ADC4, rinse and repeat

Sorry for asking the above without researching more, but I want to get the OSH Park Attiny 13/25/45/85 piggyback PCB designed and published.