In the previous tutorial, it was mentioned that primary memory can be of two types – random access memory and read-only memory. These memories are an essential part of any processor or controller based system. In this tutorial, these memories will be discussed in detail.
Figure 1: Typical Image of Primary Memories – RAM and ROM
Random Access Memory (RAM) –
Random access memory is used to store binary information during the execution time of a program. Data and instructions are loaded into RAM from secondary storage when a program is executed by the processor. The data and instructions and results returned by the processor remain temporarily in RAM until the program is executed. After the program exits, the data and instructions in RAM are also erased (or may remain in RAM as junk value until new data and instructions are written to RAM when another program runs).
RAM is read/write memory. The process of storing data in memory is called write operation. The process of transferring data stored in memory to the processor or secondary storage is called read operation. RAM is random access memory, so data can be read or written directly from any memory location. It takes the same time to read or write data to any location in RAM. This is different from sequential access memories, where the time required to read or write data depends on the location in memory. Like in a RAM, the access time to read or write binary information from or to any location respectively remains the same and is always extremely less compared to any secondary storage, it is generally expensive.
RAM is a volatile memory, meaning the data stored in it is lost when the power is turned off or whenever there is a power failure. Consequently, most desktop computing systems use a backup uninterruptible power system (UPS) to buy time to complete processing and shut down running programs appropriately. RAM is a semiconductor memory, so it is generally compact in size. Because they are expensive and semiconductor-type, commercially available RAM memories generally have limited capacity.
Data is stored in RAM in groups of bits called words. In any read or write operation, complete words are read or written to memory respectively. The length of words is generally a multiple of 8 bits, i.e. 8 bits, 16 bits, 32 bits, 64 bits, and so on. The length of the words depends on the type of computing system, be it 8-bit, 16-bit, 32-bit, 64-bit, and so on. The group of 8 bits is called a byte. Therefore, words can be 1 byte, 2 byte, 3 byte, 4 byte in length, and so on. Data stored in memory is read through parallel data output lines and written to memory through parallel data input lines. The number of data input and output lines must be equal to the length of the words stored in memory, as a complete word is read or written at any time.
Each word in memory is identified by a unique address. There must be n number of address lines to read 2n words from a memory. In addition to the data input, data output, and address lines, there are two control inputs to specify the direction of data transfer to memory. These control inputs are read and write. Reading causes data to be transferred from memory to the processor, and writing causes data to be transferred from the processor or secondary storage to memory.
The addresses of words in memory are used to access the memory location identified by the address. Addresses range from 0 to 2 n – 1 where there are n number of address lines.
The capacity of any RAM memory is expressed in bytes such as Kilobytes, Megabytes and Gigabytes by the number of words and word length. For example, it can be said that RAM memory that stores 16-bit words with the capacity to store 1K words has a capacity of 1K X 16 words or 16 KB of capacity.
Read and write operation –
There are two operations that can be performed on any RAM memory – Read and Write. The write operation is performed by implementing the following steps –
1) Apply the binary address of the word that should be written to memory in the address lines.
2) Apply data bits written to the selected memory address on the data input lines.
3) Activate the write control input, so that data bits are written to the specified memory address.
The read operation is performed by implementing the following steps –
1) Apply the binary address of the word that should be read from memory to the address lines.
2) Activate the read control input, so that data bits from the specified memory address are read through the data output lines.
In some RAM memories there is an additional control input called memory enable. This input must be active to apply any reading or writing operation. Memory read and write operations are controlled by the processor (or central processing unit in desktop and server systems). The time required to read data from RAM is called access time. The time required to write data to RAM is called cycle time. The CPU is synchronized by its own clock, the memory has no internal clock to trigger read or write operation. Therefore, the access time and cycle time must always be less than a time equal to a fixed number of CPU cycles. For example, if the RAM cycle time is 50 ns, the access time is less than 50 ns, and the CPU cycle has a period of 20 ns, the read and write operation can be performed in three CPU cycles.
When data needs to be written to RAM, the memory enable and read/write signals must be activated after the signals on the address line and data input lines are stable, otherwise the data will be lost. The control signals – memory enable and read/write must remain active for a time equal to the memory cycle time. Signals on the address and data input lines must remain stable for a short time even after the control inputs are turned off.
Access time is generally much shorter than RAM memory cycle time. During the read operation, some period of time must be spared to handle another read operation request. Read and write operations in RAM are usually demonstrated by timing diagrams. Timing diagrams show the memory enable status, read/write control signal, address line, and data input or output line in contrast to CPU cycles.
Types of RAM –
RAM memories are categorized by their mode of operation. Based on mode of operation, RAM is classified into two types –
1) Static RAM – Static RAM consists of internal latches that store binary information. Because latches can retain data until they receive power, data stored in SRAM remains intact until power is supplied to it. In case of power failure or shutdown, data stored in SRAM is lost. SRAM has short access and cycle times. It is easy to interact with and use as data remains on it until the power supply is interrupted. SRAM chips use a 6-transistor array without the use of capacitors. Transistors do not require power to prevent leakage, so SRAM does not need to be updated regularly.
Due to the extra space on the die, SRAM uses more chips for the same storage. This is why SRAM is quite expensive. Some static RAM is also used as cache memories. These SRAMs have very limited capacity and extremely small access and cycle times.
2) Dynamic RAM – Dynamic RAM stores binary information as charge stored in capacitors inside a MOS transistor chip. As the capacitors are discharged over a period of time, the data in dynamic RAM needs to be refreshed periodically. The data is updated by cycling through the words periodically for a few milliseconds, restoring the charge on the capacitors. Therefore, dynamic RAM is updated hundreds of times per second. DRAM consists of memory cells where each memory cell is constructed from a transistor and a capacitor. Due to this construction, dynamic RAM is small and cheaper compared to static RAM.
Memory decoding –
During read or write operation, memory addresses are selected by applying the address number to the address lines. The signals on the address lines are decoded by a decoder circuit to select a memory location. The memory enable input is usually connected to the decoder circuit to enable or disable read/write operations.
Error detection and correction –
There are possibilities of error in storing and reading data from memory. Therefore, employing error detection and correction techniques is a common practice during read and write operations. The most common error detection technique is the parity bit. The parity bit is generated and stored along with the word in memory. When data is written to memory, it is accepted when the bit parity is correct, while when data is read, the parity is checked again to confirm word accuracy. If the parity does not match, it means that an error occurred in the read/write operation. If there is an error, the check bits generate a pattern that is called a syndrome. The pattern is used to identify the bit of the word that contains an error. The specific bit is flipped to correct the error. Error detection codes generate several parity check bits that are stored along with the words.
Read-only memory (ROM) –
Read-only memory (ROM) is a primary memory from which only data can be read but cannot be written to by a user. This is a non-volatile memory in which data, once transferred, remains in memory even without any power supply to the memory unit. Binary information is permanently stored in these memories during their own manufacturing.
ROM generally stores the instructions required by the computing system when it is powered on. This operation is known as bootstrapping. These memories are commonly used in desktop computers and servers. Many embedded devices, such as washing machines, televisions, and microwave ovens, also use these memories to initialize embedded programs.
The process of transferring binary data into ROM is called writing or programming. In recording, fixed interconnections between logic gates are formed on the ROM chip that represents binary information. Data in ROM is read using a decoder circuit.
ROM Types –
There are the following types of ROM memories –
1) Masked ROM (MROM) – The first ROMs were hardwired devices that contained a pre-programmed set of data or instructions. These types of ROMs are known as masked ROMs. These ROM memories are not very expensive.
2) Programmable read-only memory (PROM) – PROM is a read-only memory that can be modified only once by a user. The user purchases a blank PROM and inserts the desired content using a PROM programmer. Inside the PROM chip there are small fuses that blow during programming. It can only be programmed once and cannot be erased. Most single-use programmable microcontrollers have PROM to store application logic.
3) Erasable and programmable read-only memory (EPROM) – An EPROM can be erased by exposing it to ultraviolet light for a period of up to 40 minutes. Typically, an EPROM eraser is used to erase data from the EPROM. To program the EPROM, an electrical charge is trapped in an insulated gate region. The charge can be retained for more than ten years because it has no leakage path. To extinguish this charge, ultraviolet light passes through a quartz crystal window (cover). This exposure to ultraviolet light dissipates the stored charge to erase the stored binary data. The quartz cover remains sealed with an adhesive during normal chip use.
4) Electrically erasable and programmable read-only memory (EEPROM) – The EEPROM is electrically programmed and erased. It can be erased and reprogrammed up to ten thousand times. Both erasing and programming take about 4 to 10 ms (milliseconds). In EEPROM, any location can be erased and selectively programmed. The EEPROM can be erased one byte at a time, rather than having to erase the entire chip. Consequently, the reprogramming process is flexible, although quite slow.