The mystery of the Zombie RAM

Turns out that the circuit only/always worked in the morning. I was (un)luckily that I happened to do my first test in the morning or none of this would have ever happened. But how did the circuit know what time of day it was with out any real-time clock access?

Thanks to the sun streaming though my window each morning.  But how is this incredibly simple circuit light-aware without any sensors (or associated software) of any kind?

It is all thanks to the innocent looking indicator LED. When the sun hits it, it generates an extremely tiny current thanks to the photoelectric effect. But how is that powering the RAM when the LED is connected to an IO port pin?

AVR microcontrollers have clamping diodes on the input pins. My bet is that this tiny current is running thought the high end diode into the internal Vcc bus on the chip and that is keeping the RAM alive. But could that tiny LED current really be enough to sustain the RAM indefinitely?

Apparently so. Keep in mind that this chip is spec’ed to use less than 0.15ua in power down mode. That is an vanishingly small amount of current. I actually backed uCurrent on KickStarter, so when it comes I’ll try to measure the current coming out of the LED and update this post with what I find.

In the mean time, I was able to easily test this theory using a flashlight. When the flashlight is shining onto the LED, the RAM persists infinitely. With the flashlight off and windows shades drawn, the RAM decays in less than 150ms.

Case closed!

17 comments

  1. Pingback: The Mystery Of Zombie RAM
    • bigjosh2

      I found that if you short the Vcc pin to ground while the chip is unpowered, then you loose the memory contents immediately. There probably is a tiny capacitor at work here – the intrinsic capacitance of the circuits on the chip itself. Now if you were going to splurge and use an actual external capacitor then you’d have so much excess power that you mind as well leave the chip powered in deep “shutdown” sleep. You should be able to get at least a 7 hour ride out of a 1000mF capacitor assuming you start at 5V and run down to 1.8V at a typical current draw of .15ua.

  2. rmd6502

    Very cool, can’t wait to find out how much current is needed to keep the RAM alive! I’d be careful about powering the chip through a pin other than Vcc tho…

  3. Pingback: The Mystery Of Zombie RAM | Hack The Planet
  4. Roelf

    Very interesting article, thanks. I had a look at your code and saw this line:

    void init0 (void) __attribute__ ((naked)) __attribute__ ((section (“.init0″)));

    From what I determine, this makes the code start with that function instead of main. Could you explain a bit more why you are doing this and how the code works. Or where I can get more information on this. Also is there a reason you did not want to run the code in main()?

    • bigjosh2

      The “naked” tells the compiler to omit the entrance and exit code for the function – so this compiled function will not get a return at the end. The init0 tells the linker to put this in section init0 which is where the very first code gets run right after the processors boots up. This is important because the normal C startup code clears all variables to their initial values (or zero), so we wouldn’t be able to see what was left in there. For more info on startup stuff and avoiding it, check out my post here..

      http://ognite.wordpress.com/2013/11/12/how-small-can-an-avr-c-program-be/

    • bigjosh2

      It seems to be reliable up to about 100ms in my test rig, but this is very dependent on the circuit layout. You really have to test the exact circuit you plan on using in situ to be sure.

  5. Pingback: The mystery of the Zombie RAM « adafruit industries blog
  6. Greg Meyer

    The code is oddly cut off in this post and in others of yours. I don’t think it’s my computer, I checked it on both Firefox and Chrome, though browser standardization is enough that a simple code td shouldn’t appear radically different from one to the other, and I’ve noticed it happening on your other posts as well. I love your code, it’s amazing, but it’s a bit hard to read because it’s cut off. (Pic enclosed, http://i.imgur.com/AlMDpjC.png).

    • bigjosh2

      AT least for this post, that’s all the code there is. All it does on power up is check the cookie, then light the LED if the cookie is right, then set the cookie, then go into an infinite loop. That’s it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s