Despite the great flexibility that MCUs offer, configuration changes typically require a programmer and software support, which is often unnecessary complicated. For some settings solder jumpers or dip switches are used, practical applications are limited by the number of IO available.
avr-rid uses an external resistor to encode up to 5 bit per IO pin. The build-in ADC is used in conjunction with internal pull-up resistor and only one additional external resistor is required for self-calibration. The code works independently from the supply voltage and over a large temperature range. Possible applications include detecting various plug-in modules, setting the device address for ie. I2C, setting a software controlled voltage/current/power limit and much more.
- simple: just one resistor and few lines of code - that's it!
- precise: algorithm takes all major error sources into account
- lightweight: minimal demo code is less than 0.5kB in size
I have noticed that unfortunatly the provided code example will not work on newer AVR devices over the same, large temperature range. Compare the pull-up resistor current graphs of the ATTINY13A (upper) to the ATTINY202 (lower):
Finally I got around to "verify" the stated operational temperature range. "Verify" in quote marks because my setup the bare minimum possible:
A small test PCB (from a yet unreleased project) is the DUT and contains an ATTINY13A, the reference resistor, a test resistor (screw mounted) and a a temperature sensor. Well, not a proper sensor, but a 3904 SMD transitor whose BE forward voltage changes at about -2.1mV/°C . Both the base and the collector are soldered to GND to improve heat transfer into the transistor. The voltage is measured with a multimeter. The calculated id value is send to the uart TX pin, received by a uart-usb adapter and displayed on terminal on my phone.
The test procedure is simple:
Initialize the code at room temperature (in my lab 15°C = 0.64V)
Connect a resistor to test
Heat up the board with a hot air rework tool until the reported value is incorrect
I've measured three 1% resistors, all of them are edge cases with the worst expected performance:
1.0k (0x01): heated up until 0.35V (15°C +
138°C = 152°C) without a change in output value, than the MCU crashed.
This is not surprising as it is only rated at up to 125°C. After a power
cycle it worked again.
4.7k (0x05): heated up until 0.42V (15°C + 104°C = 119°C), then output value changed to 0x04.
1.0M (0x1E): heated up until 0.44V (15° + 95°C = 110°C), then output value changed to 0x1D.
Although this is not a precise test by any means, I'm very happy that the results exceeded my expectations. I'm confident that the code will work on most AVRs reasonably reliable until 70°C, maybe 85°C. For critical applications where an incorrect detection could lead to permanent damage I'd still recommend to only use the even values and interpret all odd ones as an error.