Re: [bascom] ATMega8 Watchdog Question


From "Richard Prosser" <rhprosser@gmail.com>
Date Fri, 19 May 2006 08:01:16 +1200
Domainkey-signature a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oMy2cxqxizIwKxj8tZHJL+6pFwu6pQ99R696dWfB5sRd1EgEpoGmorKNmR5952iPbfPHE2n5NdimFxoddDwvVA7klvF6AU+1L5KZgzxR8yTmmo5a58njY+oJa385yFe/IN+pitmEXfEQbyjjhSWjRl+b8sw0HMHEP9Oy0YpYR8c=

Ian,
I think the watchdog timeout will always cause a reset - so you need
to do the timeout check at the start of the code. The wdrf flag is
reset by a normal reset and set by a timeout reaset - (as you have
determined) so you can create a jump from there to the powerdown
routine.

You'll just have to do the test before you start configuring
peripherals and writing to ram - so you'll have to figure out a way of
bypassing the normal BASCOM startup routines.
$noramclear and/or  $noinit may be be useful. but you'll then have to
write your own initialisation code.

That's my take on it anyway - the manual doesn't seem to spell it out
clearly but it's in agreement with your output messages (Partially
corrupted by premature shutdown?)

Also, Your INT0 interrupt handler terminates with a Retfi assembly
instruction wheras it should terminate with a BASCOM  "Return". There
may be no difference in this case but the "Return" instruction will
generate the context handling code required under normal conditions. I
can't see it causing this wakeup problem but it would create problems
later on when you're handling the INT0 interrupt.

Richard P


On 19/05/06, ian dobson <i.dobson@planet-ian.com> wrote:

Hi,

The watchdog interrupt causes a reset. It's normally used to catch program
crashes.

Regards
Ian Dobson

Home of the Atmel based UDP mobile web cam http://www.planet-ian.com
All mails scanned with av-filter.pl (F-Prot / perl)

----- Original Message -----
From: Fanie Terblanche
To: Bascom
Sent: Thursday, May 18, 2006 5:22 PM
Subject: [bascom] ATMega8 Watchdog Question

Hi All,

I have a question about the WDT. If the program wakes up from the WDT it
restarts the program, and i just want to reset the WDT and go back to sleep
if it was not INT0 that woke me up.

Thanks in advance
Fanie.

This is the output i get
-------------------------------------
START
Before Sleep
WDT
START
Before Sleep
WDT
START
This is the test program used.
--------------------------------------
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600

Config Int0 = Falling
On Int0 Measurepulse
Config Watchdog = 2048
'reset after 2048 mSec
Start Watchdog
'start the watchdog timer
Reset Watchdog
Enable Interrupts
Enable Int0

Print "START"

Do
  Gosub Shutdownpower
' The following code will only be executed if INT0 woke me up
  Reset Watchdog
  Print "INT 0 woke me up !!!!"
Loop

Shutdownpower:
  Print "Before Sleep"
__wdtr:
  Print "Reset WDT"
  Reset Watchdog
  cbi MCUCSR,WDRF
'Clear the MCUCSR Flags
  cbi MCUCSR,BORF
'Clear the MCUCSR Flags
  cbi MCUCSR,EXTRF
'Clear the MCUCSR Flags
  cbi MCUCSR,PORF
'Clear the MCUCSR Flags
  Powerdown
'Goto Sleep
  sbic MCUCSR,WDRF
'Check if the WDT woke us up
  jmp __wdtr
  Print "NOT WDT"
'NOT the WDT
  cbi MCUCSR,WDRF
  cbi MCUCSR,BORF
  cbi MCUCSR,EXTRF
  cbi MCUCSR,PORF
  Print "After Sleep"
Return

Measurepulse:
  Print "INT 0"
  Reset Watchdog
Reti




START
Before Sleep
WDT
START
Before Sleep
WDT
START