2

I am using an Arduino Mega 2560 board. I have tried connecting a 115 Ω resistor from 5V to Reset, and 10 µf capacitor form reset to GND (to disable autoreset), and the variables still seem to reset themselves when I unplug and replug-in the Arduino. Any way to stop this from happening?

Basically I am making a device that is sensitive to time, and must run for about 2 months, but if it is unplugged, it can't lose its place in time and reset the whole program.

I think one alternative would be for me to have it actually write how long it has been running into a .txt file on the microSD card and then verify that in the start-up...

Any ideas?

1
  • You have a power supply other than the USB connection, right? Aug 25 '16 at 19:04
5

Save the variables you need to EEPROM.

1

Arduino Mega board has RESET-EN "jumper". If you cut the trace, it won't reset MCU by DTR from USB-to-Serial chip. If you have to upload new sketch, you'll have to short it by piece of metal.

There is also possibility to use .noinit section for storing variables, so if you don't loose power, it won't get overwritten by automatic init. However, bootloader could be messing with that memory too. So it might not help without erasing this bootloader and using ISP(SPI) interface to program it.

Or you can use for example RTC (if you already have one) and it's battery backed RAM.

1

If you can't give the MCU enough warning of a power-down to save its critical variables, you'll have to keep it alive with batteries, sleeping if necessary, until the power comes back.

Tying Reset high won't help. The chip resets at power-up - that's built in. In fact, a power-up reset and a grounded-Reset-pin reset behave a bit differently - see the datasheet. Even if it didn't reset on power-up, the RAM needs power to maintain its contents, so it loses them when it drops.

0

Take power from UPS (uninterruptable power supply).

3
  • 1
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
    – jfpoilpret
    Aug 28 '16 at 9:33
  • 1
    Not all questions have direct answer. Variables are stored in volatile memory that doesn't work without power and upon power reset variables are reset. There is no way to stop it from happening due to Arduino (and most other uC) design restrictions. But workaround solutions are possible, as almost always ;-) SD card, duplicate power supply, UPS, car accumulator of big capacity, Ethernet shield are just several examples.
    – Dmitri
    Aug 28 '16 at 18:46
  • 1
    The question is not on how to prevent power shortage but on restoring state after power shortage, hence I don't consider this answer relevant to the question. Also I guess the OP knows about UPS and did not need anyone to mention it.
    – jfpoilpret
    Aug 28 '16 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.