my atmega 128 wont sleep!!

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

so I have a function that attempts to implement an idle sleep...Im watching it hit the code, but it dosen't sleep...i see see leds, and it pluggs along

..As it looks in the datasheet I am doing things in the right order...but Ive screwed up simplier stuff in my life so on with it:-P

atmega 128
avr studio 4

the code

set_sleep_mode(SLEEP_MODE_IDLE);
			sleep_enable();
			sei();
			sleep_cpu();
			sleep_disable();

It is called from within a timer overflow isr. Maby being called from inside the isr is doing something I dont realise.

Or perhaps my implementation of waking it up is screwing up something

I just left a blank isr triggered from int4
heres the code

ISR (INT4_vect){
}//user buttion press interrupt

So in my mind if you ever push the button on int4 the thing should wake up....too bad it never sleeps to test it....Could it be somehow preventing sleep?

Thanks for any help. Been looking at this for 2 hours and need fresh eyes

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

well i answered the int4 isr part...it still dsent sleep with it commented out

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

Make sure your optimization is not set to -O0 -- some of these functions require strict timing of the CPU instructions to work, and without optimization it doesn't work.

The optimization level of -Os should be your default.

Stu

PS: Insomniac CPUs are the pits, aren't they? :wink:

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

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

good thought...but im useing -0s already

Quote:

PS: Insomniac CPUs are the pits, aren't they? Wink

haha you know it! :-P

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

Its not because its in an isr ...i ran it from main and nothing still

guess ill change it to not use avr libc code and see if that does anything

oh snap i was just looking through the datasheet and it says in idle mode leaves "other port pins" on...perhaps i chse the wrong state, it has been working, and im a fool...

tune in to find out

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

ok! i got it to work....and yes i am a fool :P

it was the power save state i chose that was my predominate problem...idle mode kept getting knocked out by the timer interrupts

power down mode is the way to go

so heres the working code if anyone is interested
i ended up using the shorter version of avrlibc sleep...though the original individual steps worked as well

set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			sei();
			sleep_mode();
			sei();

and im waking it up on the rising edge of int0

ISR (INT0_vect){
}//user buttion press interrupt

oh and the int0 external interrupt registers for completeness

	EIMSK=0x00;
	EICRA=0x03;
	EIMSK=0x01;

So one last question ... why do my leds stay on when i power down...i can see the device stops progressing...the states stop changeing...but the leds that were lit when the thing powers down stay on....WTF...i mean I can clear my LEDs so thats no big...but is this supposed to happen????? is there any other upkeep(like turning off stuff I thought the Uc would do) I should be aware of?

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

anyone? it seems so wierd to me....

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

You used the word "power down" - but sleep mode is nothing to do with powering down?!? It's simply stopping some of the internal clocks in the device. So the (powered) PORT latches are just going to maintain their state at the moment it entered sleep - where's the mystery in this?

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

Quote:
You used the word "power down" - but sleep mode is nothing to do with powering down?!?

Hey! I didnt come up with the use of "power down" for the definition of any sleep state...direct your complaint to Atmel for describing it in the datasheet,...or perhaps the avrlic people because thats how they described it too (their functions are even called sleep mode power down)...

Now from that general description you can't see where one would see some mystery as to why everything isn't really powering down???...

Perhaps the mystery is why would they mislable their datasheet....

Last Edited: Mon. Dec 10, 2007 - 07:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But thanks for the clairfication..at least i know my uC aint doin something it shouldnt

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

Yeah, I guess all of us are just too stupid to make all those inferences. I just did it the slow dolt way when doing my low-power designs: I read the description of the various modes in the Power Management and Sleep Modes chapter. I studied the table on clocks and wakeup sources Active Clock Domains and Wake-up Sources in the Different Sleep Modes. I determined my power budget based on the tables and charts for the processor, and added the subsystem draws for those enabled. I examined the schematic and system design to ensure no hidden power suckers. I prototyped starting with the bare chip and a skeleton program to enter the desired mode and measured the current draw. I worked with that until it matched the datasheet. Then I added circuitry and enabled/disabled peripheral subsystems one-by-one and retested.

Yeah, that's the way surly old curmudgeons do it. If I were more clever I could just divine all of the above and have a Eureka! moment.

Lee

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

A good practice to follow... Ill use that next time..

nice bunny avatar ;-)