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 without any real-time clock access?

Thanks to the sun streaming through 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 through 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 meantime, 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!

21 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!

  7. Andrew

    I have just come across your very interesting experiment. I should have realised what was happening as recently I had two PIC projects running both self powered with a common ground and many interconnected port pins. I wanted to reset one PIC and as the reset pin was used as an input I decided to toggle the power to reset. However it didn’t work and after a bit of experimenting I realised one PIC was being powered by the port pins of the other PIC project! With your experiment I did wonder with your test circuit configuration, if the LED anode was connected to the VCC rail and pulled low by the port pin whether it would work better or not at all as it would now power the AVR through the Vcc pin?

    Andrew
    Australia.

    • bigjosh2

      Good question! My guess is that would probably continue to power the chip if the output pin was HIGH or HI-Z because as soon as the chip voltage started to go down, the high side clamping diode would shunt the voltage from the pin to the chip’s power rail (the drop across the diode at those low current levels would be negligible). But what would happen if the pin was LOW? My guess is that the chip would brown out, and if it reset with the pin HI-Z then it would cycle up and down like that. But you’ll have to test and let us know what you find!

Leave a Reply