ATmega48V wakes up from power down unexpectable

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

This is something I did it a lot of times using the ATtiny13V, but I cannot do it using the ATmega48V.

I try to put the cpu in power down mode and to wake it up using the watchdog overflow (every 2 sec) and then reset function (I don't mind if watchdog consumpts some microAmps while the cpu is in power down mode), because the whole cpu consumption is what I need. Using any other sleep mode the consumption is more than the maximum limit, so power down mode with the watchdog functionable (only) is the best for my aplycation.

Before put the cpu in power down mode I handle all other consumptions by setting the I/O ports and stoping used peripherals like ADC and Timers. After this I reset the watchdog timer and then I put the cpu in power down mode. Using this code:

void cut_off(void){
programState = CUT_OFF;
adc_stop();
timer0_stop();
timer1_stop();
wait_int();
timer2_stop();
__disable_interrupt();
io_init(SLEEP);
pinOpampSupply = 0;
sleep(POWER_DOWN);
}

const UC POWER_DOWN = 0x04;
const UC POWER_SAVE = 0x06;

void sleep(UC mode){
CLKPR = 0x80;
/* clock division factor = 2 */
CLKPR = 0x01;
__no_operation();
__no_operation();
#ifdef DEBUG
/* minimize power consumption */
PRR = 0xEB;
#else
PRR = 0xEF;
#endif
__watchdog_reset();
SMCR = mode;
SMCR |= (1 __sleep();
SMCR = 0x00;
}

After the execution of sleep instruction the cpu unfortunately goes to the next instruction imediately, without the pass of 2 seconds (Watchdog timeout). Then it exits this function and it executes other functions. At this time all interrupts are disabled and the watchdog resets only in interrupts so after 2 seconds it resets the cpu.

The result is that for an unknown for me reason the cpu wakes up just after the __sleep instruction execution.

I have read the ATmega48V errata.
Somewhere I maust be wrong.

I need help,

Thanks for your time,

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys I found it.

Look 3 lines before the end of program. I mean the instruction:
SMCR |= (1

Things like that can make us mad.

The correct typing is:
SMCR |= (1<<SE);

Anyway,

Thanks for your time.

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer