Pages: [1]   Go Down
Author Topic: Hardware Reset  (Read 1136 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Question, is there a way to test if the Arduino had a Hardware reset via the reset button or from some unknown reason that caused it to reboot?

The reason I asked is, I would like for a ESC Calibration routine to run only on the initial power up and no other time in the event of a reset.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12743
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Yes.  Search the datasheet for the MCUSR register.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The same code gets run when the Arduino resets, whether from power on, pressing the reset button, opening the serial port, or poor code causing a reset.

So, no, when the Arduino starts up, you can not tell why.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
run only on the initial power up and no other time in the event of a reset
This begs the question, why does it have to be reset?


______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17261
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This begs the question, why does it have to be reset?

Well a reset (at least power-up or manual/auto reset) is required to activate the Arduino bootloader program. But if your point is that good program structure should not require a 'running reset', I agree.

 I guess one exception would be if the watch dog timer was being utilized, but there is a way to determine in code if the watch dog timer did the biting.

Lefty
« Last Edit: December 17, 2010, 12:56:37 am by retrolefty » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But if your point is that good program structure should not require a 'running reset', I agree.
Yes, that's what I was referring to.

______
Rob

Logged

Rob Gray aka the GRAYnomad www.robgray.com

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, perhaps the best way is to get it to save a value to EEPROM on startup after it has run the ESC calibration routine.

So the code would be:
Check for value in EEPROM
if value exists, ignore calibration code
else, run calibration code and write value to EEPROM

Then you could have a physical button to reset the value in EEPROM if you wanted to run the routine on next startup.

Mowcius
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Ok, perhaps the best way is to get it to save a value to EEPROM on startup after it has run the ESC calibration routine.

So the code would be:
Check for value in EEPROM
if value exists, ignore calibration code
else, run calibration code and write value to EEPROM

Then you could have a physical button to reset the value in EEPROM if you wanted to run the routine on next startup.

Mowcius

Good Point, thank you.
Logged

Pages: [1]   Go Up
Jump to: