Watchdog timer promblem in ATmega32

Started by John B October 12, 2006
I am trying to change the watchdog prescalar in an ATmega32
application. The data sheet implies that the watchdog timer registers
can be written at time with no special requirements. Is this the case?
I am finding that the following code works in AVR Studio but not in the
hardware.

void WatchdogInit(void)
{
  WDR();
  WDTCSR = 8;  // Set prescalar to ~1/4 second timeout.
}

Compiler is Imagecraft 7.08.

Any clues.

-- 
John B
"John B" <spamj_baraclough@blockerzetnet.co.uk> wrote in message
news:452e2d03$0$29542$4c56ba96@master.news.zetnet.net...
> I am trying to change the watchdog prescalar in an ATmega32 > application. The data sheet implies that the watchdog timer registers > can be written at time with no special requirements. Is this the case? > I am finding that the following code works in AVR Studio but not in the > hardware.
In the ATmega162, any change to the watchdog timer, including times, must be preceeded by setting the WDCE (Watchdog Change Enable) bit, wich is the same bit on the ATmega32, where it is called WDTOE (Watchdog Turn Off Enable). I wouldn't be surprised if you have to set this bit on a '32 too before changing the WDT time. Meindert
On 12/10/2006 the venerable Meindert Sprang etched in runes:

> > "John B" <spamj_baraclough@blockerzetnet.co.uk> wrote in message > news:452e2d03$0$29542$4c56ba96@master.news.zetnet.net... > > I am trying to change the watchdog prescalar in an ATmega32 > > application. The data sheet implies that the watchdog timer > > registers can be written at time with no special requirements. Is > > this the case? I am finding that the following code works in AVR > > Studio but not in the hardware. > > In the ATmega162, any change to the watchdog timer, including times, > must be preceeded by setting the WDCE (Watchdog Change Enable) bit, > wich is the same bit on the ATmega32, where it is called WDTOE > (Watchdog Turn Off Enable). I wouldn't be surprised if you have to > set this bit on a '32 too before changing the WDT time. > > Meindert
Thanks Meindert. In that case, the WDTOE bit seems to be mis-named. I've just looked at the ATmega48 etc. datasheet and it has a code example for setting the watchdog timer which is like the mega162 that you describe. I guess all megas will use the same WDT module so will require the same code. -- John B