Mi chiedo se la riduzione di consumo avviene solo in sleep mode?
Se fosse così non potrei spegnere il timer2 o altra periferica che non uso per ridurre il consumo anche durante il normale funzionamento, e questo è un peccato. Nel datasheet del 644 non ho trovato informazioni in merito, voi sapete come funziona?
Non uso il timer2, il timer1, analog comparator e SPI.
Porto il micro in SLEEP_MODE_PWR_DOWN
Lo risveglio tramite PCINT18.
Il codice (non C++) è il seguente:
#include "controller.h"
#include <displaykey.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>
/* Enable IRQ on PCINT18 */
#define IRQ_PCINT18_ENABLE() \
PCMSK2 |= _BV(PCINT18);\
PCICR |= _BV(PCIE2)
/* Disable IRQ on PCINT18 */
#define IRQ_PCINT18_DISABLE() \
PCICR &= ~_BV(PCIE2);\
PCMSK2 &= ~_BV(PCINT18)
/* Controller switch power off */
void ctrlSwitchOff()
{
uint8_t kPwrCounter = 230;
display_power_off(); // switch off display
PORTC |= _BV(PC7); // set bit 7 of PORTC
IRQ_PCINT18_ENABLE(); // IRQ_PCINT18_ENABLE() must stand before sleep_mode().
sleep_mode(); // go to sleep
// when wake up, enter in while(kPwrCounter != 0)
// if Exit key is old pressed kexitCounter go to zero and exit from while, so power on is completed.
// if Exit key is not pressed, go to sleep.
while(kPwrCounter != 0)
{
if ((PINC & _BV(PC2)) != 0) // if PWR Button is pressed
{
kPwrCounter++;
} else {
kPwrCounter = 230; // if PWR Button is released
sleep_mode(); // go to sleep
}
_delay_ms(50);
}
ctrlSwitchOn(); // switch on the controller
}
/* Controller switch power on */
void ctrlSwitchOn()
{
IRQ_PCINT18_DISABLE();
PORTC &= ~_BV(PC7); // clear bit 7 of PORTC
display_power_on(); // switch on the display
}
void ctrlInit()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
PRR0 |= PRTIM2; // mmmm.. to be or not to be
}
// This is need? not know
ISR(PCINT2_vect) {
// it exist only to wake up from the sleep
}
Consigli?
Ciao.