Hi all,
I'm trying a new idea - making a battery powered device that operates once when the AVR (tiny85) is reset, then it goes to sleep. Much simpler than using an interrupt to detect a button.
Anyway, please see the attached piece of code and tell me if:
- I'm doing it correctly (the right order)
- My assumptions about "useless" parts are correct - can they be removed?
- I've missed any power saving functions that I SHOULD be using.
// low power settings based on Nick Gammon's info:
// http://www.gammon.com.au/power
int main (void)
{
IO_DDR = 0x00; // all pins inputs
IO_OUT = 0x00; // disable pullups
timerInit (IR_FREQ); // setup 8 bit timer for IR carrier frequency
sendCmd (shutter, 3); // data, repeat 3 times
wdt_reset(); // reset watchdog (useless?)
wdt_disable(); // disable it (useless? WDT already disabled in hfuse)
ADCSRA = 0x00; // disable ADC (important: this MUST come before PRR)
power_all_disable(); // power off everything (does nothing in PWR_DOWN mode??)
set_sleep_mode (SLEEP_MODE_PWR_DOWN); // set full power down mode
cli(); // disable interrupts
sleep_enable(); // enable sleep mode
sleep_bod_disable(); // disable brown-out detector (useless? BOD already disabled in hfuse)
sei(); // enable interrupts (necessary? we activate via reset)
sleep_cpu(); // MUST do sleep_cpu directly after brown-out disable
}
Input will be appreciated!
(edit to add): Note most pins have external pullups (except the crystal pins - which has a 1 meg across, a 16.000 crystal across and 18 pf from each to ground). One pin has an external pull DOWN and is also connected to the base of a little TO-92 BJT base through a 220 ohm.