Go Down

Topic: Hardware Reset (Read 1 time) previous topic - next topic

Copter Richie

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.

Coding Badly


Yes.  Search the datasheet for the MCUSR register.

PaulS

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.

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

retrolefty

#4
Dec 17, 2010, 06:55 am Last Edit: Dec 17, 2010, 06:56 am by retrolefty Reason: 1
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

Graynomad

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

Rob Gray aka the GRAYnomad www.robgray.com

mowcius

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

Copter Richie

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.

Go Up