NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Everything Else » Adding RAM

October 19, 2012
by Ralphxyz
Ralphxyz's Avatar

A couple of days ago, in the very interesting array limitation thread JimFrederickson said:

ATMega168 has 1KB of RAM.
ATMega328 has 2KB of RAM.
ATMega644 which has 4KB of RAM.

(you could also add RAM is necessary too.)

Can one add external RAM? How?

That would make a great Nerdkits Community Library article.

I have a couple of handfulls of old SIMMs.

Noter did a great job of describing using I2C EEPROM memory.

I2C is a serial protocol how would one be able to access a parallel SIMM?

Using I2C for the LCD output (thanks Rick) and other I/O I have 20 pins available for parallel use but is this feasible?

And then wouldn't I need a OS or could the compiler be modified to deal with the external RAM?

I "think" I can picture accessing external RAM with my Raspberry Pi but that will have a OS (if I ever get round to taking it out of the box).

I just can not picture how to access external RAM.

Even if one could not get external program memory it would be cool to just have external volatile memory storage for holding variable values. An extra 16/256kb (or more) of external volatile memory might be useful.



October 19, 2012
by Ralphxyz
Ralphxyz's Avatar

Of course using a SD card is using external RAM but I am wondering if anyone knows how to use a old SIMM?

Does the SD card use serial communications?

Of course I can look at the SD Card Project to get a idea about what the code might look like.


October 19, 2012
by JimFrederickson
JimFrederickson's Avatar

Hello Ralph,

Of course additional RAM can be added, but the RAM is not going to be like Microcontroller RAM. (It will be accessed MUCH slower, and will need to accessed in some "indirect manner"...)

In order to be able to utilize that RAM there would need to be specific routines made to either virtualize a segment of Microcontroller RAM or to provide some indirect access to external RAM.

At a minimum the following choices would have to be made:

Memory Page size
Number of Pages in external storage
Number of Buffers in Microcontroller RAM

Functions for:
    Locking a Page
    Unlocking a Page
    Background Functions to
        write contents of Unlocked Pages that are Dirty
        read contents of Locked Pages that are Invalid

    A structure would need to be created that will track
        Current Location of pages.  (locked/unlocked, and Valid/Dirty/Invalid)

    Locked - Pages that have been requested by a Process
    Unlocked - Pages that are no longer necessary by a process
    Valid Pages - Locked Pages whose contents have been synchronized to a buffer
    Invalid Pages - Locked Pages that are waiting to be synchronized
    Dirty Pages - Locked Pages whose contents have changed and need to be saved

How a Process Accesses a Page:
    1 - Process Locks a Page, Current Status of the Page is Invalid
    2 - Process waits for the Locked Page to be become Valid while a background Function reads the external RAM
    3 - once the Locked Page is Valid it can be accessed

While the concept of "Pages" do not have be used, it is common for that to be the case
because it allows for the "Pages" to become "Buffers" of Data.

Mostly though, any external storage is easiest/most effectively used as some sort or Array. Mostly then, it is best to be a log of some sort or a collection of data to be processed later.

There are several I2C RAM and EEPROM DIPs that are available that work on 5v. MOST now, and probably soon ALL, will be 3.3v.

If you REALLY wanted to be able to utilize external RAM as System RAM then you would need to create a Virtual Processor and use your AVR Microcontroller as a Microcode Engine.

With the ATMega168 I have really only found it reasonable to use external RAM/EEPROM as a log.

With the ATMega328 and the ATMega644 it makes more sense.

You can use the I2C Interface and create an effective Microcontroller LAN!

That way you can talk to multiple intelligent unit/peripherals as well as have several I/O pins available.

What would you do with the RAM?

October 19, 2012
by JimFrederickson
JimFrederickson's Avatar

I should have included...

Usually when I use external RAM/EEPROM as a log, or even as storage, I just divide it into a few arrays of structures of set sizes...

I read in and write out individual array entries.

It is a lot more "limiting", but it is also a lot more "manageable with resources available to the Microcontroller too.

October 20, 2012
by Rick_S
Rick_S's Avatar

One other note along with what Jim said. There are AVR's that support external SRAM directly such as the ATMEGA128. If memory serves me correctly you can add up to a 64K SRAM to it and set it up to be active above internal memory all done in hardware. I'm not too sure about compiler support though, I've never tried or needed external RAM.


Post a Reply

Please log in to post a reply.

Did you know that you can connect digital calipers to a microcontroller? Learn more...