Checking reset source mega8...

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

Hi!
I managed to cram the bootloader and my application into a mega8...
Now, having some free space in flash, I decided to add an extra feature... so, I wrote a function to check the reset source at startup. I am mainly interested in brown-out and watchdog reset.
Here's the code that works ok:

 if(MCUCSR & (1 << 0)) // power-on reset
    ; // do nothing
 else if(MCUCSR & (1 << 2)) // brown-out reset
    brownOut++;
 else if(MCUCSR & (1 << 3)) // watchdog reset
    watchDog++;
 MCUCSR = 0;

... and here's the code that doesn't work ok:

 if(MCUCSR & (1 << 2)) // brown-out reset
    brownOut++;
 else if(MCUCSR & (1 << 3)) // watchdog reset
    watchDog++;
 MCUCSR = 0;

The second version increments (always) "brownOut" variable... [?!?]
I know I'm a little bit "tired" after a few beers (a friend's birthday), but... am I missing smthing here?
BTW: All I could see in the datasheet is:

Quote:
To make use of the Reset Flags to identify a reset condition, the user should read and then reset the MCUCSR as early as possible in the program. If the register is cleared before another reset occurs, the source of the reset can be found by examining the Reset Flags.

Regards,
Stanley.

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

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

I'm guessing that multiple bits could be set. For example, the brown-out could be latched when the Vcc falls below the tbrown-out threshold and the AVR goes into reset. In addition, the power-on might be signaled when Vcc falls below Vpot.

Lee

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

If you are just initiating a microcontroller hardware reset without removing VCC and the "Brown-Out" flag is being set, I can't answer the question.

But, I would think that the "Brown-Out" flag would be set at initial application of VCC as, VCC is in fact below threshold while VCC is coming up and isn't dependant on any other microcontroller resources to hold it off during the VCC power up event.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

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

Quote:
If you are just initiating a microcontroller hardware reset without removing VCC..

Definitely no... There's no external reset possibility for this device (pin C.6)... The only way to reset the device is to cut the power (disconnect the DC power cord).

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.

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

So Stanley, does my theory sound plausable or, did you just have a few too many beers and maybe got a little confused. I haven't been there lately, but in the days of old, I've deffenitly lost focus due to one vice or another...

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

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

microcarl wrote:
So Stanley, does my theory sound plausable or...

Affirmative... :wink:

Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies.