Attiny25/45/85 FW Development Thread

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.

I was rather surprised to hear that one of my projects compiled and worked on the attiny25, with no modifications!

So, it sounds like we already have a few firmwares which work (or almost work) on nicer hardware, and it’s time to get the hardware out there to more people. :slight_smile:

If I understand correctly, it should be fairly straightforward. Just toggle back and forth between voltage and temperature every other cycle, with different code to handle each. I think the MCU can only measure one at a time, but it’s not hard to swap between the two fast enough for it to be useful.

+1, I read it the same - only one at a time, based on the MUX bit definitions (allows only one channel to be selected), and the description of free running mode, which states one conversion at a time, then auto starts the next conversion. But certainly/definitely the firmware can be written to support LVP A-D conversions and temp sensor A-D conversions.

The accuracy doesn't sound too great though for the temp sensor. Even after a single cal point at room temp, the accuracy is only within +/- 10C. I would think we would want better? Better to get two points, but I'm not sure how to best create then measure a 2nd point. Guess I could use a heat/hot air gun, but not sure how to accurately measure the temp of the chip. I wouldn't trust my cheap IR thermometer. Dunno if my Chinese $15-$20 meter is any good, or would the Fluke or Extech units be that much better in the $70-$80 range? Or is an IR meter the right tool?

TK wrote:

. . . Just toggle back and forth between voltage and temperature every other cycle, with different code to handle each. I think the MCU can only measure one at a time, but it’s not hard to swap between the two fast enough for it to be useful.

Cool. Thanks. So my EDIT2 idea should work. You conveyed the idea much more eloquently than I did.

TK wrote:

I was rather surprised to hear that one of my projects compiled and worked on the attiny25, with no modifications!

So, it sounds like we already have a few firmwares which work (or almost work) on nicer hardware, and it’s time to get the hardware out there to more people.

I would stress "almost work". In that example you cite, I believe said he reported LVP didn't work. Although Atmel only changed a few Memory Names, they did change the Addresses a good bit. Also, some bits changed. So a full port is really needed for all FW one wishes to install on the 25.

Tom E wrote:

The accuracy doesn't sound too great though for the temp sensor. Even after a single cal point at room temp, the accuracy is only within +/- 10C. I would think we would want better? Better to get two points, but I'm not sure how to best create then measure a 2nd point. Guess I could use a heat/hot air gun, but not sure how to accurately measure the temp of the chip. I wouldn't trust my cheap IR thermometer. Dunno if my Chinese $15-$20 meter is any good, or would the Fluke or Extech units be that much better in the $70-$80 range? Or is an IR meter the right tool?

Perhaps a hidden mode that lets the user click when the light gets too hot. That way, no calibration is needed. The loop switching from LVP to Temp would be by-passed and just ADC4 would be active during the user :"calibration". Boy, it seems that extra 1K of memory can get used up fast with new code like this.

It’s already possible to have that functionality with a turbo timer - without a temp sensor. If using the temp sensor, it should be easier than this (for the end user).

^ Great. So some code already is available to start out with. Good to hear.

I think the FW could have a default setting that would have margin for the -+10 degrees C and thermal lag for heat to get to a typical MCU. That way there is some safety measure in place in case the user doesn't calibrate. I think user calibration is pretty critical as each light is so different and as each person will have their own level of heat tolerance they are comfortable with.

Yeah, but my point is that if you are doing a user calibration, you don’t need the temp sensor at all, because a turbo timer will do fine. Well, I could understand user calibration of a temp sensor if the user had multiple different cells that they might use with that light. One cell gets it hot at 2 minutes, but a different cell takes 4 minutes to get it to the same temp, etc.