Tuesday, January 3, 2012

How Does Flash Memory Work?

Flash memory is basically the awesomest thing ever invented: it's easy to fabricate (and the process scales well, meaning we can cram more and more memory into the same area every day), reasonably fast to read and write to, can be read and rewritten millions of times, and (most importantly) is non-volatile, meaning it holds its data even when you cut the power to it.  We've had lots of different types of computer memory for awhile that could do each one of those things, and sometimes even more than one of those things, but having one transistor-based memory technology that could do 'em all seemed like an insane fever dream until surprisingly recently, and even after flash was invented (in 1988, I believe) it took awhile to learn how to make it usefully small and fast.

For an example of how far and fast flash memory has come in the last decade, take a look at the Hitachi MicroDrive, which was the cutting edge of high-capacity digital camera storage as recently as 2005: it was considered easier to miniaturize an entire goddamn hard drive, magnetic platter, read-write head, control circuitry and all, than to cram more than a gigabyte or two of flash memory into a reasonable space.  These days you can spend about 50 bucks and get a 32GB microSD flash memory card that's about the size of a fingernail.  I don't care how jaded you are about technology; that's bananas. 

Hitachi MicroDrive, shown with hamster for scale because why not.  These were so popular when they came out that people would buy certain digital cameras just to take them apart and get the drive out.  Now they just look quaint.
 
Now that I've nerdgasmed over flash a bit, we come to the awkward part: I have a solid background in solid-state physics, particularly semiconductor physics, and yet I have no idea how flash memory works.  I could make some hand-wavey guesses about things like "electron traps" and "confinement," but at the end of the day I'd pretty much be talking out of my ass.  Luckily Wikipedia is way smarter than I am.

So it turns out flash memory cells are basically field-effect transistors (FETs) with a couple of added features.  Assuming you have no good reason to know what a FET is beyond "a thing that helps the pornography get from the internet to my eyeballs," a quick walkthrough is probably in order (see diagram and follow along):

The field effect transistor (FET) in both its "off" and "on" states.  More description of what the hell's going on in the paragraphs below.
 
So basically you start with a chunk of silicon.  Silicon in general isn't all that conductive, but two regions of our chunk in question have had enough other things added to them to make them conduct almost as well as metal (this is one of many neat things you can do with silicon).  Those are the "source" and "drain" electrodes.  In between them is a large expanse of regular old not-that-conductive silicon, so even if you put a pretty big voltage on one side you're not going to get much current flow between the two. 

Here's where it gets cute: sitting above the region between the source and drain is a piece of insulator with a metal contact on top.  This is called the "gate," because applying a positive voltage to it will pull lots of electrons in the bulk Si up toward the surface.  There's very little actual current flowing, because of that insulator, but the area under the gate is now very rich in electrons.  Unsurprisingly, lots of electrons = more conductivity, so now a voltage applied across the source and drain will cause electrons to flow from the drain to the source (that's not a typo, someone just screwed up way back when and made the electron charge negative when they were defining all this stuff, so current goes in the opposite direction of electron flow, confusing generations of EE undergrads).   So basically you've got an "electron valve," where the flow of electrons between the drain and source can be switched on or off by changing the gate voltage.  FETs aren't the only type of transistor, but since they're extremely scalable and really goddamn easy to make in huge numbers, they're the only kind you're going to find in digital electronics.  The computer I'm typing this on has a couple billion of them sitting on its not-particularly-modern CPU, for example.

Flash memory bits are essentially FETs with an extra piece of conductive material between the gate and the electron channel.  For lack of a better term, let's call it the "electron jail" for reasons that will become apparent.   When the flash bit is in its off (zero) state, the electron jail is just kind of sitting there doing nothing, so the flash cell works like a normal transistor would if you crammed another piece of metal between the gate and the channel.

Basic flash memory cell.  Readers with an attention span longer than a goldfish may recognize it.  Readers without an attention span longer than a goldfish are encouraged to scroll up a little.

Where it gets weird is when you decide to switch the cell from the off (zero) to on (one) state.  This is accomplished by putting a large voltage on the gate electrode (to turn the transistor part on) and then running an assload of current (relatively speaking) from the drain to the source.  Said assload of current will contain electrons at many different energy levels, including a predictable number of them that are energetic enough to jump across the insulating barrier between the channel and the electron jail via quantum tunneling, the specifics of which is probably a whole other blog post.  This phenomenon is known, without the slightest trace of irony, as "hot electron injection" in solid-state physics.  Per usual, the math is really awful but we don't care about it; all that matters is that after we've run our assload of current through the flash cell for awhile, there are a bunch of electrons stuck in the electron jail. 

Like Alcatraz, there's no escaping from the electron jail.  It's surrounded on all sides by insulating material, so the electrons that are in there are staying there for awhile.  Quantum mechanics, because it is awful, says that they have a slight probability of being able to tunnel through the insulating barrier and out of jail, but like escaping from Alcatraz it ain't too likely to happen, or at least not to enough electrons to matter.  In general, once you've charged up a flash cell this way it'll stay charged for something like tens of years (or "20 to life," as we say in the hard-bitten world of semiconductor engineering).

So now we've got a negatively-charged electron jail sitting between the gate and channel of our flash cell.  The fact that there's negative charge there means it takes more of a positive voltage on the gate to switch the transistor on.  This shift in the threshold voltage (the technical term for how much you have to juice the gate to get the transistor to switch on) is what gives us our "one" state: flash cells with a low threshold voltage are zeros and flash cells with a high threshold voltage are ones.

A flash cell in its "one" state.  Also probably a metaphor for our overcrowded prison system or something.

That's great, but what if we want to erase it (set it back to zero)?  We've already established that our dystopian electron prison is very, very secure, so how do we spring the prisoners?  Here's where my arch-nemesis quantum mechanics comes to the rescue.  Remember when I said that there was a slight probability that electrons would be able to escape by tunneling out of prison?  We can increase that probability by putting a large negative voltage on the gate.  Electrons hate other electrons, so the presence  of a large negative voltage just above our prison will suddenly make our trapped electrons much more keen on busting out of jail than they were previously, vastly increasing the probability that they'll tunnel back out into the silicon substrate to commit more crimes.  It should be noted at this point that the prison analogy is just convenient; there isn't any evidence that electrons are more prone to crime than other elementary particles. 

So that's the basic idea behind flash memory. Obviously it's not that simple; you have to wire up billions of these things in a way that makes them convenient to read and write to if you want to do anything practical, but the fundamental thing is the shift in threshold voltage caused by filling the electron jail with electrons. 

Oddly enough I had more or less guessed right on this one; I assumed there was some coercion of electrons to tunnel somewhere and be confined going on at some point.  Where I was surprised though is how much like a regular old transistor the basic flash cell is.  It explains a lot when you think about it though; we've gotten incredibly good at making tons of small, dense transistors in the last 50-odd years, so the fact that the structure of flash memory is so similar is probably one of the main things that has made it so amazingly scalable. 

As always, props to Wikipedia.

7 comments:

  1. So...which do you hate more, Quantum Mechanics, or E&M? I know how *I'd* vote...

    ReplyDelete
  2. That's like asking me if I hate Hitler or the kid who used to beat me up in gym class more. I know what my answer should be, but getting beat up hurts.

    ReplyDelete
  3. Wow, seems like I got beat up by Hitler in gym class. Which stands to reason, now that I think about it. That kid was an asshole AND a terrible artist.

    ReplyDelete
  4. Excellent post, thanks a lot!

    ReplyDelete
  5. Your article was both insightful and delightful

    ReplyDelete
  6. This blog article is amazing.
    Brand Animators - Bringing Your Vision to Life with Innovative Video Solutions. From start-ups to large corporations, every business has a unique story to tell. At Brand Animators, our mission is to help you tell that story in a captivating and memorable way. As a top quality 3d, 2d animation video production company in Houston, Texas and best explainer video company in San Antonio, Texas and professional Healthcare & Medical animation video making studio in Dallas, Texas offer services such as 2d animation videos 3d animation videos, Motion graphics, 3d medical animation, Healthcare videos, Corporate films, Whiteboard animation videos, 3d Architectural walkthrough animation, Marketing and training videos, Product videos. And more! Whether you're looking to promote your brand, educate your audience, or simply convey information in an engaging and visually appealing manner, Brand Animators has you covered. Our video solutions are tailored to your budget, timeline, and company objectives.

    ReplyDelete