I'm using an ATTINY85 for a portable application that uses a Lithium-ion battery; therefor I need to monitor the battery voltage so I don't kill the battery. Is there a way to go about this without using another pin? or using the reset pin? **NOTE: assume that there will be no regulated voltage such as 3.3V or the like. (this is because the circuit only uses one battery and should never go above spec; and saves on cost)
The reset disable fuse does just that - disables the reset function of the associated pin. If you set that fuse, there is no way to reset the device except:
- Power Cycle
- Watchdog Timer Expiration
In-Circuit Serial Programming (also known as ICSP), I believe, relies on resetting the device by way of the Reset pin, and so you will not be able to reprogram the device once this fuse is set using ICSP. There is more than one way to reprogram an AVR though. If the device supports High Voltage Serial or Parallel programming (HVSP or HVPP) that's always an option. Or if you can include a bootloader on the chip (which can be done with an ATtiny85 for example, not sure about the ATtiny13), that can work too.
That being said, the datasheet section 24.3.3 has the following excerpts:
Special combinations of fuse bits will lock the device for further programming effectively turning it into an OTP device. The following combinations of settings/fuse bits will cause this effect:
- 128 kHz internal oscillator (CKSEL[1..0] = 11), shortest start-up time (SUT[1..0] = 00), Debugwire enabled (DWEN = 0) or Reset disabled RSTDISBL = 0.
- 9.6 MHz internal oscillator (CKSEL[1..0] = 10), shortest start-up time (SUT[1..0] = 00), Debugwire enabled (DWEN = 0) or Reset disabled RSTDISBL = 0.
- 4.8 MHz internal oscillator (CKSEL[1..0] = 01), shortest start-up time (SUT[1..0] = 00), Debugwire enabled (DWEN = 0) or Reset disabled RSTDISBL = 0.
If you have no intention of supporting in circuit programming, you can safely program once then set the reset disable fuse and use the pin's alternate function. You do not want to leave the reset function enabled in production unless you don't care about your device resetting in arbitrary ways. Basically if the pin is "low" for a given period of time, it will reset, end of story. Per the datasheet Table 18-4, the range of possible threshold values for external reset to trip is 0.2*Vcc to 0.9*Vcc... you maybe just be getting lucky with devices that are closer to 0.2*Vcc.
Go ahead and use the variable resistor suggested by Reid if your project is a one-off sand box project. If you are designing a product where you will be building many of these then I would select a resistor voltage divider made up of precision resistors (0.5 or 1% types are good for this application as the detector has a 1% tolerance). The two resistors in series will connect from battery supply to GND. The junction between the two resistors would connect to the V+ pin of your voltage detector. Pick the two resistors so that when the battery supply is just at 3.5V that the divided voltage (using the standard voltage divider equations) to the detector is just at 2.0 volts. Deploy the 2.0V version of the detector in your circuit. Also select the size range of the voltage divider resistors so that the current is approximately 15 to 20 times greater than the current draw of the detector so that the current drawn by the detector can be ignored when computing the divider ratio.
You want to use resistors like this so that when the battery discharges slowly during use that the divided voltage tracks linearly down along with the battery. At the computed threshold point the battery at 3.5V will trigger the under voltage detector at 2.0V.
Using an LDO is not appropriate because the LDO would give a constant output irregardless of the battery voltage. A diode to offset the battery voltage to the detector would work if you could find an almost perfect diode with the correct forward voltage drop but sadly perfect diodes are hard to find. The resistor divider is a much lower cost approach and will work nicely in this application.