This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

power fail recovery

hello;
can u explain me about power fail recovery in microcontroller.
i m using c8051f020 controller,in that RSTSRC register is present, its 7th bit is set when power fails.
but how to write the code after that, means suppose if my test is going on, and power fails, then depending upon RSTSRC.7 bit how to get back to test.
on reset microcontroller starts from 0000h, then how to store the status before power fail
can u provide me sample code, i m using 'c' language
thank u all.

Parents
  • I will only comment a bit for the general case - I have never looked at the chip you are using.

    Most microcontrollers have a register that informs why the program was restarted.

    Some possible values may be:
    - cold start (i.e. power-on)
    - brownout (the voltage got lower than what the uc is configured to accept, but not low enough to be detected as a cold start.
    - external reset (external logic, reset button, ...)
    - watchdog (the program has failed to kick the watchdog)

    The processor will not save any information about your application state. For that, you must use a battery-backed RAM, an EEPROM or similar, and regularly write down a good restart point.

    Some processors have a function where a browout interrupt can be trigged before the supply voltage gets too low. If the brownout level is high enough - and your PSU capacitors big enough - you may be able to save some application state in the brownout interrupt, before the chip dies. However, it is very important that you don't try to save too much. Writing to EEPROM or flash memory when the supply voltage is failing can result in broken data in the chip - and can fool some chips into activating page-protection.

    In some situations, you may be able to use an ADC to constantly monitor the supply voltage, and quickly save required state info if you notice that the voltage is dropping.

    By the way - people can't just supply sample code. They would not know what information you want to save. And unless the chip has a battery-backed RAM area or built-in EEPROM, it wouldn't be too easy for them to know where to save any information. It is only you who have all the required info to make the correct decision what to do. If you have experience enough to make a good decision is a different thing. The problem here is that the readers on this forum do not have all required information.

Reply
  • I will only comment a bit for the general case - I have never looked at the chip you are using.

    Most microcontrollers have a register that informs why the program was restarted.

    Some possible values may be:
    - cold start (i.e. power-on)
    - brownout (the voltage got lower than what the uc is configured to accept, but not low enough to be detected as a cold start.
    - external reset (external logic, reset button, ...)
    - watchdog (the program has failed to kick the watchdog)

    The processor will not save any information about your application state. For that, you must use a battery-backed RAM, an EEPROM or similar, and regularly write down a good restart point.

    Some processors have a function where a browout interrupt can be trigged before the supply voltage gets too low. If the brownout level is high enough - and your PSU capacitors big enough - you may be able to save some application state in the brownout interrupt, before the chip dies. However, it is very important that you don't try to save too much. Writing to EEPROM or flash memory when the supply voltage is failing can result in broken data in the chip - and can fool some chips into activating page-protection.

    In some situations, you may be able to use an ADC to constantly monitor the supply voltage, and quickly save required state info if you notice that the voltage is dropping.

    By the way - people can't just supply sample code. They would not know what information you want to save. And unless the chip has a battery-backed RAM area or built-in EEPROM, it wouldn't be too easy for them to know where to save any information. It is only you who have all the required info to make the correct decision what to do. If you have experience enough to make a good decision is a different thing. The problem here is that the readers on this forum do not have all required information.

Children
No data