Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
lgiancristofaro
PostPosted: May 11, 2012 - 01:35 PM
Rookie


Joined: Jan 21, 2010
Posts: 49


Hi all,

I found many posts with this subject, but none seems to help me. I am porting my bootloader from ATmega8A to ATmega164A. I found out that the micro resets itself even if I disable the watchdog and stops to do so if I periodically reset the watchdog timer. What could I check to find out where the problem is?
I attach my code. If I comment "wdt_reset()" I see PB3 continually going up and down...
I don't see significant differences between Atmega8a and Atnega164a to explain this strange behaviour...

Any help would be greatly appreciated!

Luca

Code:
void __jumpMain     (void) __attribute__ ((naked)) __attribute__ ((section (".init9")));

void __jumpMain(void)
{
   SPH = (RAMEND) >> 8;
   SPL = RAMEND & 0xFF;
    asm volatile ( "clr __zero_reg__" );        // r1 set to 0
    asm volatile ( "rjmp main");                // jump to main()
}

int main() {
   uint16_t c;

   general_init(); // sets PB3 as output
   PORTB|=(1<<PB3);
   Set_Timeout(_INIT_WAIT_);
wdt_disable();
   if(eeprom_read_byte((uint8_t *)EEPROM_GOODAPP_ADDR) != MARK_FOR_UPDATE)
   {

      while( Get_Timeout() && (rx_index!=6) ) // I stay 5s in boot mode
      {
         if ((c = getchar()) != EOF)
         {
            buf[rx_index] = (uint8_t) c;
            rx_index++;

            if (rx_index == 1)
               initCrc();

            if (rx_index<=_EOH_INDEX_)
            {
               update(c);
            }
            else
            {
               if (rx_index<=_EOH_INDEX_+buf[_LENGTH_INDEX_]+1)
                  update(c);
            }
         }
         Dec_Timeout();
         wdt_reset(); // Reset wdt

      }

   }
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 11, 2012 - 02:12 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62220
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

I don't see significant differences between Atmega8a and Atnega164a to explain this strange behaviour...

Really? Did you read the paragraph starting "Note that for newer devices..." on this page of the manual:

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

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
lgiancristofaro
PostPosted: May 11, 2012 - 03:05 PM
Rookie


Joined: Jan 21, 2010
Posts: 49


oops... I did not. Thanks very much!
 
 View user's profile Send private message  
Reply with quote Back to top
lgiancristofaro
PostPosted: Jun 20, 2012 - 08:16 AM
Rookie


Joined: Jan 21, 2010
Posts: 49


Hi all,

unfortunately I still have problems with the watchdog. I modified my code adding this lines at the beginning:
Code:
      
   MCUSR = 0;
   wdt_disable();

I added this lines at the beginning of the main function in both my bootloader and user code. I just use the watchdog to go to boot from the user code, but sometimes I observe unexpected resets and monitoring MCUSR I find out they are due to watchdog. Shouldn't it be enough the code I wrote to disable the watchdog?
I have not set the WDTON fuse.

Thanks,
Luca
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jun 20, 2012 - 08:45 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20325
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Maybe a optimisation issue? What level are you using? I think the the WDT requires a precise number of cycles to be disabled.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
lgiancristofaro
PostPosted: Jun 20, 2012 - 08:50 AM
Rookie


Joined: Jan 21, 2010
Posts: 49


I am using the -O2 optimization. I try to check out if this is the problem.

Thanks,
Luca
 
 View user's profile Send private message  
Reply with quote Back to top
lgiancristofaro
PostPosted: Jun 20, 2012 - 09:53 AM
Rookie


Joined: Jan 21, 2010
Posts: 49


I tried with -O1 and the reset occurs again. The strange fact is that I don't get a reset immediately, but after some minutes of code execution.
Furthermore, I read this passage in the datasheet:
Quote:
If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out
condition

So, I don't understand, can a Brown-out enable the watchdog? Is it possible that a brown out reset is seen as a wdt reset through the MCUSR?

Thanks,
Luca
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jun 20, 2012 - 10:02 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62220
Location: (using avr-gcc in) Finchingfield, Essex, England

In brownout any register in the AVR might assume random values and I guess that includes WDT. As long as you have the BOD fuse set you should not be subject to brown out anyway.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
lgiancristofaro
PostPosted: Jun 20, 2012 - 10:18 AM
Rookie


Joined: Jan 21, 2010
Posts: 49


I have BOD set to 4.3V and my power supply voltage is stable at 4.8V (+-0.1V due to the switching regulator resistors tolerances).
Anyway, I always see the reset source as 0x04, so it seems to be deterministic...
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jun 20, 2012 - 10:36 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20325
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
the reset source as 0x04
That's not the wdt but the BOD resetting then.
MCUSR

Code:
JTRF WDRF BORF EXTRF PORF
     0x08 0x04  0x02 0x01

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
mtaschl
PostPosted: Jun 20, 2012 - 10:41 AM
Resident


Joined: Aug 21, 2002
Posts: 895
Location: Austria

I would never set the BOD level so close to the supply voltage. AFAIK, VBOT(4.3V) is 4.1V to 4.5V.
Very likely a short drop on Vcc (maybe a response to a change in current consumption) will drigger BOD.
Do you have proper decoupling caps on the supply pins of your AVR?
Try to set BOD to 2.7V.

_________________
/Martin.
 
 View user's profile Send private message  
Reply with quote Back to top
lgiancristofaro
PostPosted: Jun 20, 2012 - 10:59 AM
Rookie


Joined: Jan 21, 2010
Posts: 49


I think you are right, I'll change the BOD setting to 2.7V. Thanks,
Luca
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits