Help to Wake-up Tiny13 from Power-down Sleep Mode.

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

I'm sorry guys, I disturb you here with avr. I hope you have a good mood before winter holidays and I wish to all of you and your families be happy and healthy. let's don't forget as this is a magic time for our kids. My best wishes from Ukraine!

 

Ok. Here is my problem.

 

I can't wake up Tiny13 from "Power-down" sleep mode, but it awake if set "Idle Mode". I checking current consumption with my multimeter, Tiny13 goes to sleep successfully -  only 0,5 microA. If sleep mode disable it takes 1,2mA.

 

According to datasheet (table 7-1 on page 30) it should awake from INT0 interrupt source, which I need.

 

What am I doing wrong? Should I enable watchdog? (but I don't need to wake-up from it.) Thank you.

 

#define F_CPU 1200000UL 
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

#define LED_ON			PORTB |= (1 << PB0)
#define LED_OFF			PORTB &=~(1 << PB0)
#define LED_TOG			PORTB ^= (1 << PB0)
#define BACKLIGHT		5000

void setup () {
	
	// *** Port Setup ***
	
	// PB1 - Button
	// 0 input
	
	// PB0 - LED
	// 1 output
	
	DDRB  = (0 << PB5) | (0 << PB4) | (0 << PB3) | (0 << PB2) | (0 << PB1) | (1 << PB0);
	PORTB = (1 << PB5) | (1 << PB4) | (1 << PB3) | (1 << PB2) | (1 << PB1) | (0 << PB0);
	
	// Analog Comparator Disable
	ACSR |= (1 << ACD);
	
	// *** Interrupts Setup ***
	
	// Enable External Interrupt on INT0
	GIMSK |= (1 << INT0);
	
	// The falling edge will generate an interrupt (H to L)
	MCUCR |= (1 << ISC01);
	
	// Enable Sleep Mode: Power-down
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);

}

ISR (INT0_vect) {
	
	asm("nop");
	
} 

void go_to_sleep_mode () {
	
	//MCUCR |= (1 << SM1);
	//MCUCR |= (1 << SE);
	//asm("sleep");
	
	sleep_enable();
	sleep_cpu();
	
}

int main(void)
{

	setup();
	sei();
	
    while(1)
    {
        
		
		// Please sleep now
		go_to_sleep_mode();
		
		cli();
		
		LED_ON;
		_delay_ms(BACKLIGHT);
		LED_OFF;
		_delay_ms(BACKLIGHT);
		
		sei();
		
    
	}

}

 

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

Aleksey_ua wrote:
According to datasheet (table 7-1 on page 30) it should awake from INT0 interrupt source, which I need.

 

First, it helps if you are a bit more specific about the model and datasheet revision.

 

Do you see the footnote?  Only low-level will awaken, but your code

Aleksey_ua wrote:
// The falling edge will generate an interrupt (H to L) MCUCR |= (1 << ISC01);
says falling edge.

 

Now, when you do level-triggered it will keep firing for as long as the condition exists.  So you want to disable the interrupt source in the ISR.

 When the INT0 interrupt is
enabled and is configured as level triggered, the interrupt will trigger as long as the pin is held
low. Note that recognition of falling or rising edge interrupts on INT0 requires the presence of an
I/O clock, described in “Clock Systems and their Distribution” on page 23.

Perhaps because of that, pin-change interrupt is very useful to awaken AVRs even from the deepest of sleep.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

According to datasheet (table 7-1 on page 30) it should awake from INT0 interrupt source, which I need.

Only when INT0 is configured for 'level' interrupt.  It won't wake on edges (neither falling, nor rising):

 

 

 

I'd suggest you use pin change interrupts.  They will wake the t13 on either edge.

 

 

EDIT:  Lee beat me to it.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Wed. Dec 30, 2015 - 08:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you. Working!

 

I saw the note, but I have understood it wrong and stuck on falling edge from H to L with interrupt.

You poked my nose into important detail.