is it possible to save a variable to Eeprom in the case of hard reset ?
your solution is not useful in my case because maybe i have power loose at the same time of emergency pressedHello!
In case of hard reset, assuming the system wasn't powered down exactly at the
same time, you are likely to have a constant power supply. One way to do it would
be a simple RC circuit. If it has been powered on for ages, the capacitor is fully
charged, and if you measure its voltage, you will find VCC.
If you just powered the board, then the capacitor is not fully charged. So if the first
thing you do in your program is to measure the cap voltage, then you can have
a hint whether it was powered or whether it has just been switched on.
But: you have to specify your timeout with great care. For example, what about if
you make a short power off, a few 100s milliseconds, the cap might not be discharged.
Or maybe find a trick to discharge it quickly with some FET just when the power goes off.
Dora.
im reading the datasheet for this flagsHi,
There are flags telling you why the microcontroller is restarted.
Power_on, external reset, watchdog .. and others.
I don't have the complete datasheet in mind, so I had to read the datasheet....
Less save method:
You may store a magic number in RAM. If it already exists at power up (be sure the compiler does not clear variables) then there was no power down. After power down memory content is lost.
Alternative methods:
* external circuits, like some kind of RS-FF that is cleard on power up, set by software.
* not using RESET at all, but Interrupt to force the MCU controlled in inactive state.
Klaus
There is no general answer, it's application specific. Context variables could be considered, but depend on their change rate, you could not save to EEPROM everytime but from time to time, tolerating some losses; counters for example are candidates to be restored, as well as user specific last configurations such as alarm on/off , etc...how can i decide which its restarted after Hard reset or normal power on ?
I could no believe this. So I downloaded the datasheet, did a search for "reset source" (like recommended) and the 5th hit gave:Klaus idea about a register of reset was great but i couldnt find it
The part has a configurable brown out detection interrupt where you can set the trigger Vthanks Dana
Alot of useful ideas in the avrfreaks post
its something can be done But the main problem is that i dont have more free pin to detect power
so Klaus idea about a register of reset was great but i couldnt find it
i will try another external solution which save the situation of my sensors before doing hard reset to main Mcu
thanks
Johnny
are you sure?The part has a configurable brown out detection interrupt
While you can perform code while an interrupt is pending..That should be more than
enough to accomplish EE or FLASH write.
i have downloaded the datasheet again & yes i didnt search the same way you have mentionedHi,
I could no believe this. So I downloaded the datasheet, did a search for "reset source" (like recommended) and the 5th hit gave:
10.9.1 MCUSR – MCU Status Register
The MCU status register provides information on which reset source caused an MCU reset.
--> You need to improve your datasheet search skills. It's really simple and straightforeward:
* open datasheet in PDF viewer
* start the "text search" feature
* type in "reset source" and start the search
* if the current highlighted is not what you are looking for --> press the "next search" button
Klaus
i need to read more as i see i cant write to eeprom when reset occursi
i have downloaded the datasheet again & yes i didnt search the same way you have mentioned
& yes there is EXTRF External Reset Flag.
So all i have to do is save the flag to Eeprom when Reset occurs & then on Restart Read the Saved Flag & do whatever i want
thanks
yesThere is a flag that gets set on brownout -
complete: RESET and Interrupt table...And there is a vector executed in the interrupt table....
What exactly?Manual leaves a LOT to be desired.
Where exactly?There is a statement in manual that if brownout occurs , which cause an ISR
True.the EEPROM operation will be completed if Vcc stays above min level, not the brownout selected level.
Disabling ISRs has nothing to do with BOD.Then there is disable ISRs and detect BOD flag and do the save.....
are you sure?
Afaik, there is no brown Out Interrupt --> to run an ISR
It´s just a Brown Out Reset, to stop code from running.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?