sunnuntai 22. toukokuuta 2016

A few non-volatile memory types


Many embedded applications need to store some data in case of power outage, unscheduled reset or whatever. Reasons are various: program code, calibration values, serial numbers, current state, active log data, timekeeping, anything.

To respond to these wildly different needs a multitude of memory types has been developed over the years, starting from simple ROMs and ending... well, these days, Flash or MRAM are "best" (subjectively speaking), but who knows what we'll have tomorrow.

Different memories of course have different strengths and weaknesses. Some can't be written, some can be rewritten few times, some practically infinitely. Some are slow, some fast, some cheap, some expensive. Here's a quick overview of common types available today.

Let's start from ROM, due to being the oldest type. They aren't really common these days but for historical reasons I'll include them here.
ROM, or Read Only Memory, is just that - you can read but you can't write. Before cheap MCUs with large memory spaces became common they were often used for program data, LUT (Look-Up Tables) and whatever static data your application might need.

Main drawback of the ROMs is that they must be ordered custom-built from factory and thus have very high up-front cost; factory needs to tool their line to make your chips, which costs some serious money. On plus side, once that's done, they're very very cheap. Just hope you don't find a bug there...


Not every customer and every application can afford such a high up-front cost, so PROMs to the rescue (Programmable Read-Only Memory). These aren't really used used these days either but I'm certain they still are available for specialized or legacy applications. As the name says they can be programmed, typically with a special programming device. Chips typically are first programmed, then placed in headers on PCB. A bit of extra trouble there, but still a huge improvement over ROM process.

PROMs are one-time-programmable, so once programmed they're set in stone. A bug found? Discard chip and program a new one. But still a huge improvement over ROM process.

And they are still available today (kinda-sorta): For example Microchip offers their PIC processors as OTP ("one-time-programmable") devices - essentially they come from factory with your program in them. And they cannot be reprogrammed, ever, so for your application use they are PROMs.


Then there are EPROMs, E standing for Erasable (note, just one E there.)  They are programmed like PROMs, but they can be erased too. You can identify EPROM device easily as they have a "window" on top of the chip. To erase an EPROM they must be exposed to UV light, often in special "ovens", so if that's needed, the chip needs to be taken out from PCB, put in over for a hour or so, reprogrammed and then replaced. Not something that you can easily do on field, but then again, if you know that you'll need to do a field upgrade, you'd bring a replacement chip with you. This window typically is covered with a sticker when chip is in use to avoid accidental erase due to sunlight.

A huge improvement over PROMs, but still a bit clumsy.


Then there were EEPROMs, Electronically Erasable PROMs. Oh joy! These can actually be erased and reprogrammed even by your program on the PCB. The very first EEPROMs required high programming voltage that circuit needed to be able to provide; typically logic voltage was 5 volts and programming voltage about 12 volts. High voltage is needed to erase (reprogram) the device. If there was no need to erase EEPROM in application (treating them as ROMs) that could of course be left out.
Newer EEPROM chips have built-in boost module for that so external erase voltage is no longer needed.

EEPROMs are first memory type from these that is commonly used even today. Especially in smaller form factors (8-pin chips, with SPI or I2C bus) they are very very easy and cheap way to add some persistent storage to your project. Every byte in them can be (re)programmed individually, without affecting neighboring data, so small updates are simple to handle. Writing to them still needs to be done page-wise; typically you can write to a 64-byte aligned block a time, then you need to wait a bit when chip does its magic (rewriting) internally. Delay isn't much, few tens of milliseconds per page, but still needs to be applied for write process to work.

The main limitation (depending on your requirements of course) is that they have limited number of write cycles, typically 1-10 million erases. So if your data changes very often this might actually be a problem. EEPROMs come in limited sizes (again, I'm speaking mostly of smaller packages here); 256kbits (32kB) is already near the upper size that can be found easily, going above that will seriously limit chip availability. But in smaller sizes they are dirt cheap; single euro will buy you few kilobytes of persistent storage (note, I haven't verified today's exact prices so all quoted prices here are ballpark figures.)


Then came the Flash. I'm focusing to Flashes you place on PCB (like SOIC package) here, not SSDs or SD cards, as their data storage behavior is completely different.
Flash memory is cheap and much larger than EEPROM ever, but they have two serious drawback: First, they have limited number of erase cycles (can be as low as 1000 or so, 10000 being fairly typical), and they must be erased per-page: If you want to change single byte, you have to erase entire page (often 4kB) and write entire page again. I'll talk more about them next time as they tend to be a bit more tricky to use than EEPROMs.


Then there are newer EEPROM-like technologies like FRAM or MRAM (Ferroelectric Random Access Memory and Magnetoresistive RAM). And these are very very cool chips indeed. Persistent, byte-accessible memory like EEPROM with practically infinite erase cycles and no EEPROM paging limitations. Really, what is there not to like? Except price, of course. These bad boys aren't cheap; while 2€ will buy something like 64Mbit Flash chip, you might get some 64kbits of FRAM for the same price. But if you want to store small amounts of data that changes often, they definitely are worth their premium.


Also NVRAM needs to be mentioned here. I don't really consider them as persistent memories as term refers to small RAM that is backed up with a battery or capacitor. If the battery dies the memory is gone. I don't like them at all, but they are an option for some use cases - typical being an clock that needs to keep time even with system is otherwise powered off.


These are the most common memories available these days. There are others, often variations with names generated mostly for marketing reasons, or some less common ones, but knowing about these will typically suffice in most cases. And next time I'll talk a bit more about these Flash chips and how you can use them effectively.




Ei kommentteja:

Lähetä kommentti