When designing a product, there are so many features and aspects that need to be considered. How much will the product cost? How much will it cost to package it? And what kind of development time can I expect? In this article we will ask the question “How Much Memory Does My Product Need?”
What Kind of Memory Do I Need?
Since many, if not all, products contain some kind of processing core these days they will also contain memory. But using the word memory is somewhat incorrect since there are many different types of memory depending on the CPU architecture.
For Von Neumann-based CPUs, memory can include...
- RAM: External memory used to hold programs and/or variables
- ROM: External memory used to hold programs and constants
- FLASH: External memory used to hold programs and store files
- Cache: Memory internal to the CPU that allows it to operate at faster speeds when using slower external memories
For Harvard-based CPUs, memory can include...
- Data RAM: Internal memory used to hold variables
- Program ROM: Internal memory used to hold the main program
- FLASH: External memory used to hold files and configuration details
- EEPROM: Internal rewritable memory inside the microcontroller that can store config
Products that require a microprocessor (such as a computer, laptop, Raspberry Pi, etc.), will normally be of the Von Neumann-type while microcontrollers (such as PICs, AVR, and Arduinos), use Harvard architecture.
Microprocessor products are usually very powerful (as compared to microcontrollers), with faster CPUs, larger memories, and higher throughput. Of course, memory can still be a concern, so areas where memory may be a source of concern include...
- Graphical routines including rendering, encoding, and decoding
- Programs using large number of objects
- Multi-tasking/multi-processing systems
- File storage
Example 1: Raspberry Pi-Powered Security Camera
This product requires a portable Pi with a security camera to both stream the footage online and store video files that it records. In this case, you will obviously need as big an SD card that you can get, as video files are often very large. For example, if our camera records at 640x480 at 25fps, we can expect a single frame to be approximately 461KB uncompressed. Therefore, one hour of footage would be equivalent to 461KB x 25 x 3600, which is approximately 41GB. Having said that, video files are often compressed, so assuming that we save the video footage as an MP4 with an average compression ratio of 50:1, the total file size would be closer to 1GB.
Example 2: Game Arcade System (MAME)
A product like an arcade machine may need plenty of RAM or not much at all. This all depends on what games it will be playing; retro games may need very little RAM, while modern games may need large amounts to cope with level loading, object storing, and video generation. Having said that, if an arcade machine is designed to have all retro games in existence, a hard drive space of many gigabytes could be necessary.
RAM in the computer is not the only place you may need to consider. GPUs also need memory, and where they get this from matters! Integrated graphic processors may take up a portion of install RAM, which means you may need to increase the RAM size to account for this. Modern dedicated graphics cards do not do this, however older models may consume system memory.
It can be tough to determine how much memory a microcontroller-based project needs if the exact nature of the project is not fully realised. So the best way to understand how much memory we need is to look at a few examples!
Example 1: Video controller/Graphics
In this project, we will use a microcontroller to show graphics on a display and have it perform some basic functions, like text plotting. So, how much memory would a system like this need? This project could do one of two things to display video:
- Print text only
- Print full black/white graphics
If we are printing text, we need to start by figuring out how many characters will be on the screen. So let’s say that in this example we will have a screen of 32 by 16 characters. The total number of characters on the screen will be 32*16, which is equal to 512. Assuming that we are using only ASCII characters, the total RAM needed to store all the text is 512 bytes. Instead of storing all the graphical information in RAM, we can take the character ASCII bytes and pass them through a ROM table (character ROM), which points to graphical bytes. But if we assume that each character is 8 x 8 pixels, the total amount of bytes needed to store the bitmap of a single character is 8 bytes. Since there are 128 ASCII characters (maximum), we will need at least 128 x 8 bytes of ROM, which is equal to 1024 bytes or approximately 1KB.
If we are printing a bitmap screen instead (like those graphical 128 x 64 bit LCD displays) and we want a resolution of 320 x 240, the total number of bits would be 76800, which is approximately 9.6KB. This, however, would be stored in RAM and not ROM, since only RAM is fast enough to be written to frequently (50 frames a second). Since there is no character ROM, the amount of ROM needed for the project is near 0, but this does not include the actual program and routines itself.
Example 2: Wi-Fi System
A product needs to be able to connect to Wi-Fi networks, remember login details, and be expected to make GET and POST requests. Sending commands to connect to Wi-Fi networks requires very little program memory, but we will need to remember login details. This means that we will need to store permanent data such as SSIDs and Passkeys. However, these are often very small, so assuming a 20-byte length SSID and 20 byte password, we could easily have an internal EEPROM as small as 64 bytes. If, however, we want to start storing SSH keys, we could be looking at EEPROMs of 512 bytes to 1KB (remember, keys can be as long as 256 bits).
The product also needs to make GET and POST requests, which also come with response headers. Such responses can be rather large (especially when the requested page could be a website), and since the response will need to be temporarily stored, we could need a RAM size of at least 1KB. However, we don’t only need RAM, since we would need to compile a GET or POST message before we send it, so we can expect to need 1KB of program ROM for storing a GET/POST template.
When choosing memory, recognize what tasks you intend to do and then determine what type of memory those tasks will need. File and configuration storage can be offloaded to an external FLASH IC, while object-oriented programs will need large amounts of RAM as well as stack space. If in doubt, always get a little extra memory than you need, so when future additions are included, you won’t run out of memory!