So, I found an interesting article the other day, and I'm trying to build a project that could benefit from a battery-backed memory (no wear limits, but keeps data over power cycling). The article lists how an extremely small current from an LED (acting as a photocell in the lit room) accidentally powered the AVR during a RAM-endurance test.

But, what if this is done on purpose with a battery?

(Article here: https://wp.josh.com/2014/03/03/the-mystery-of-the-zombie-ram/)

The problem with this idea (since the RAM can already be backed up, as shown in the article, though the author does not seem to have considered this) is that I need a way to keep an array of memory ignored by the C initializer. It would be the height of hilarity to have the memory survive the power-off event only to be nuked by the chip's powerup reset code. The listed example at that article would work, for the first requirement, but would break almost anything else I might try to do (since it overrides the entire initializer). (Comment on the reset issue: https://wp.josh.com/2014/03/03/the-mystery-of-the-zombie-ram/#comment-598)

Also, assuming I tried this, would I simply damage the pin rather than provide power? I plan to use a pin continually set to input attached to the positive side of a lithium coin cell, with a common ground. In theory, powering the AVR (and I think at any voltage) through the VCC pin would cause the chip's diodes to disconnect the battery, but if it's unplugged, the core would receive enough power to keep the RAM alive.

Of course, my question is whether it would instead stupidly try to keep the core running when power is disconnected (in the original article, the nanowatts from the LED couldn't do that, so it's forced to shut down, but I don't know if this is solely due to power limits or if it would shut down the main systems if there's no connection over VCC). In this case, it might try to draw more than the 1mA rating over that parasitic supply, and try to power the entire chip when I don't want it to (thus frying the clamping diode or something equally bad).

I wonder if it would be possible simply to put a large resistor (10K? 1M?) in series with the battery in this case? That would automatically limit the supply to less than 1mA.

  • 1
    You're mad. Just use an NVSRAM chip. microchip.com/wwwproducts/en/23LCV512 – Majenko May 23 '19 at 21:50
  • 1
    Re “keep an array of memory ignored by the C initializer”: just add __attribute__((section (".noinit"))). – Edgar Bonet May 23 '19 at 21:58
  • I probably am. But I'm trying to avoid purchasing stuff (and its shipping times) for now. It does seem to work though, so thank you, Edgar. This is actually fairly awesome, in the fact that it can be done, in a "Oh, how is that even a thing?!" fashion... – RDragonrydr May 24 '19 at 0:22
  • 1
    @EdgarBonet - use the Answer box to answer, please. People are not supposed to look in the comments under the question for the answer. Then it can be accepted and you can get some rep. :) – Nick Gammon May 24 '19 at 5:50
  • 1
    this is not an Arduino question – Juraj May 24 '19 at 8:05

Expanding on my previous comment...

I need a way to keep an array of memory ignored by the C initializer

You can achieve this by instructing the compiler to store the array in the “.noinit” memory section:

int my_array[ARRAY_LENGTH] __attribute__((section(".noinit")));

Your array will end up sitting somewhere between the .bss and the heap (if any), and will not be touched by the __do_clear_bss routine from the C startup code.

my question is whether it would instead stupidly try to keep the core running when power is disconnected

Most likely. In order to avoid that, I suggest you enable the brown-out detection by setting the BODLEVEL fuses. This feature of the ATtiny is specifically meant to prevent the CPU core from running if the supply voltage is below some configurable threshold.

| improve this answer | |

For anyone wanting to know further how I implemented this, I did set the BOD fuse on my device. Still, not wanting that sort of fun (referring to having the chip try to actually run via the backfed power) to happen at all, I wired a 1M resistor in series with the supply backfed through the pin (which was set to INPUT in all cases. HIGH would result in attempting to charge the backup battery, and LOW may well sink the input current and negate the benefits) in an effort to force the current to be high enough to power the RAM but too low for it to run. It also makes sure that too much current cannot flow through the pin.

My results were somewhat inconsistent, and it doesn't help that the device can actually end up powered by whatever indicator LED is added to show that it worked!

Still, there's a good chance that this can be used as an NVRAM if the code is written for it. As for that, just store an array with the values, and write onReceive and onRequest code to index that and send it back out!

Fair warning: If the power bus is connected to other components, the AVR won't keep its memory. Use a diode to prevent power from escaping.

| improve this answer | |

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.