Watchdog Timer Reset from Sleep Mode Help WDT

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

Hi, hoping someone can maybe give me a snippet of code or point out what I'm doing wrong in my watch dog timer code.

Here's what I did using Atmega88, internal 8MHz, GCC compiler... I want my processor to execute a small piece of code, sleep for 8 seconds, wake up, re-execute the same thing, sleep for 8 seconds, etc, (doing this for power considerations, code works fine with delays but I need to put the thing to sleep...)

#include
#include
#include
#include
#include
#include

int main()
{

WDTCSR |= (1<<WDE)|(1<<WDCE)|(1<<WDP3)|(1<<WDP0); //initialize a 8 second timeout/reset

[instructions to be repeatedly executed to transmit data points here]

SMCR |= 0b00000100;
SMCR |= 1<<SE;
sleep_cpu();
return 0;
}

It seems like the code stops executing after it sets the bits in the WDTCSR register but IDK.... How do I do what I want to do? What'd I do wrong? I read everything in the atmega88p datasheet, no help, All I know is that I need to set some bits to reset. My WDTON fuse is turned off as well.

I try not to ask too many questions on here unless I'm totally stumped so thanks guys...

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

Quote:

WDTCSR |= (1<<WDE)|(1<<WDCE)|(1<<WDP3)|(1<<WDP0); //initialize a 8 second timeout/reset

Doesn't your toolchain have a facility to do proper watchdog setup? (Hint: without looking it up, a single line isn't going to do anything.)

Note that instead of a full reset, that AVR model also has an interrupt mode for the watchdog that can be used to periodically awaken your AVR.

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

Ok, I read in the dataasheet it did have an interrupt mode but my code was just so perfect if i could have gotten it to work with a full blown shut down and reset. =/ figured it'd just be easy to do like a uart or eeprom or something but oh well thanks

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

Quote:

Doesn't your toolchain have a facility to do proper watchdog setup?

Yes:

http://www.nongnu.org/avr-libc/u...

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

Quote:

my code was just so perfect if i could have gotten it to work with a full blown shut down and reset.

Perhaps. Isn't it easier to call the proper watchdog setup and create the ISR than it is to run a program without any local/global variables that persist from one "run" to the next?

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

Quote:

Quote:

Doesn't your toolchain have a facility to do proper watchdog setup?

Yes:

http://www.nongnu.org/avr-libc/u... ... chdog.html


Aah, yes, now I remember discussions. IIRC the provided facilities of wdt.h don't do the watchdog interrupt, requiring one to roll-their-own? Which again introduces the usual caveats about optimization level and the 4-cycle limit.

In any case, smkipus, a single line surely isn't correct for watchdog enable.

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

Ok, looked at
http://www.nongnu.org/avr-libc/u... and followed the examples given, got my program working the way I wanted it to with the reset, just had to go and do what that page told me to. Sure would be slick to not have to rerun all my initializations every time it woke up, the WDT library gave me the hard reset wakeup when I used it.