Advanced AVR 3.0 Core - Sleep, software and hardware-based power button Double click
How can 1 button and 2 LEDs be classified as advanced? How complicated can it be? This button is used in ways that utilizing hardware level techniques to detect signal edges, to denounce the noises generated by the button, to wake up the MCU from sleep mode and this button is also timed by semi-hardware for having 2 types of triggers: 1 for putting the MCU back to sleep mode and 2 for changing the LED brightness by means of double click.
High code efficient and responsive and precise and glitches free and energy efficient. The MCU is underclocked to 2.4MHz, required only to generate a true 8-bit pwm dimming signal at 888Hz, and once the MCU is Off, it consumes neglectable among of energy. Example Written for battery friendly power switch such as a flashlight. The CPU can be underclocked even lower, but 2.4MHz is faster to program and tinkering with, and at 2.4MHz Idle mode, the power consumes by the MCU is minimal.
Sleep:
The LED is powered by the timer with the MCU in idle mode underclocked essential using tiny amount of current in sub 600uA range. The MCU can generate a PWM signal even with its CPU halted, so this saves only few mA of power, a tiny percentage in comparison to a power LED. In power down mode, the MCU is operating in sub 600nA range. The power ON indicator LED consumes few mA as well, so the power On routine blinks it few times and turns it off to save some power.
In short, double-click to change the setting and single-click to turn the MCU/LED ON/OFF, simple idea, and simple project, written in the highest quality and using the lowest power possible. The code has been fully tested and polished over and over again, a very really good practice.
Note 1: the mini PWM board is not designed with low power in mind, just its 50K POT consumes about 100uA at 5v. One end of the POT can be connected to an I/O pin, so the POT can be disabled using software in power down mode.
Note 2: 146Hz is picked as the PWM frequency to minimize transistor switching power loss. It would be very dumb to power a LED using high frequency PWM signal.
Note 3: 1.4mA measured with a LED powered at 4%; 7.6mA at 48%; 14.4mA at 97%; There is a 1k resistor to the LED; 90uA measured when powered off, so VCC much be 0.00009*50000=4.5v;
Note 4: This is very low power, but to get that ultra-low power. VCC can be step down with a synchronizes buck converter to the lowest voltage, and the CPU clock can be dialed down as slow as required. The tiny13 can be underclocked to as low as 37KHz.