[AVR] a problem with WDT in atmega32

Status
Not open for further replies.

Amin Khorsandi

Member level 2
Joined
Oct 12, 2013
Messages
45
Helped
5
Reputation
10
Reaction score
5
Trophy points
8
Activity points
293
Hi everyone. I wrote this program in codevision just for testing WDT (watchdog)

Code:
#include <mega64.h>
#include <delay.h>

void main(void)
{
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/16k
#pragma optsize-
WDTCR=0x1F;
WDTCR=0x0F;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
#asm("sei")

while (1)
      {    
        xxxxxx
      }
}

If I put nothing instead of "XXXXXXX" the watchdog works and resets the program.
But if I replace "XXXXXX" by "delay_ms(1);" , watchdog won't work and won't reset the program.
And the funny part, if I replace it by "delay_us(1000)" , watchdog will work and will reset the program.8-O
it means that "delay_ms(1)" and "delay_us(1000) are different :!::!::!:
please give me some recommendations.
 

I rewrite program to better understanding.
Code:
#include <mega64.h>
#include <delay.h>

void main(void)
{
PORTA=0xFF;
DDRA=0xFF;
delay_ms(1000);
PORTA=0x00;
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/16k
#pragma optsize-
WDTCR=0x18;
WDTCR=0x08;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
#asm("sei")

while (1)
      {    
        //delay_ms(1);
        delay_us(1000);
      }
}

This program sets all of bits in PORTA. and after that the proram resets by WDT and we can't see any change in PORTA. but if "delay_ms(1);" replaces by "delay_us(1000);" the WDT won't work and won't reset the microcontroller. and we can see PORTA is 0x00.
 

Attachments

  • watchdog test.zip
    31.4 KB · Views: 109

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…