14 Memory System
Dr K. Vani
In this lecture, the semiconductor memory will be discussed in detail. Memory address decoding and the interfacing of 8051 will also be discussed.
1.Semiconductor Memory
1.1 Memory Capacity:
The number of bits that a semiconductor memory chip can store is called chip capacity. It can be in units of Kbits (kilobits), Mbits (megabits), and so on.
This must be distinguished from the storage capacity of computer systems.
While the memory capacity of a memory IC chip is always given in bits, the memory capacity of a computer system is given in bytes. If a 16M memory chip is present, then 16 megabits is stored in the semiconductor memory. If a computer comes with 16M memory, 16 megabytes can be stored which means that 16 words are stored, each with the capacity of 8 bits.
1.2 Memory Organization
Memory chips are organized into a number of locations within the IC. Each location can hold 1 bit, 4 bits, 8 bits, or even 16 bits, depending on how it is designed internally. The number of locations within a memory IC depends on the address pins. The number of bits that each location can hold is always equal to the number of data pins. In general, if x is the number of address lines in a memory chip, it contains 2x locations. Dynamic RAMs (DRAMs) are exceptions to this as indicated in a later section (1.9.2). Each location contains y bits, where y is the number of data pins on the chip. The entire chip will contain 2x × y bits.
Figure 1.1 shows the memory capacity where x is the number of address pins and 2x the corresponding memory capacity.
1.2.1 Example for memory organization
A 512K memory chip has 8 pins for data. Find: (a) The organization, and (b) the number of address pins for this memory chip.
Solution:
(a) A memory chip with 8 data pins means that each location within the chip can hold 8 bits of data. To find the number of locations within this memory chip, divide the capacity by the number of data pins. 512K/8 = 64K; therefore, the organization for this memory chip is 64K × 8.
(b) The chip has 16 address lines since 216= 64K.
1.3 Speed
The speed of the memory chip is commonly referred to as its access time. The access time of a memory chip varies from a few nanoseconds to hundreds of nanoseconds, depending on the IC technology used in the design and fabrication process.
1.4 ROM (read-only memory):
ROM is a type of memory that does not lose its contents when the power is turned off. For this reason,
ROM is also called nonvolatile memory. There are different types of read-only memory. They are:
✓ PROM
✓ EPROM
✓ EEPROM
✓ Flash EPROM
✓ Mask ROM
1.5 PROM (programmable ROM) and OTP:
For every bit of the PROM, there exists a fuse. PROM is programmed by blowing the fuses. If the information burned into PROM is wrong, that PROM must be discarded since its internal fuses are blown permanently.
✓ PROM is also referred to as an OTP (one-time programmable) device.
✓ Programming ROM, also called burning ROM, requires special equipment called a ROM burner or ROM programmer.
1.6 EPROM(Erasable Programmable ROM) and UV-EPROM:
EPROM was invented to allow making changes in the contents of PROM after it is burnt.
✓ In EPROM, one can program the memory chip and erase it thousands of times. A widely used EPROM is called UVEPROM.
✓ UV stands for ultra-violet.
The only problem with UV-EPROM is that erasing its contents can take up to 20 minutes. All UV-EPROM chips have a window that is used to shine ultraviolet (UV) radiation to erase its contents. The major disadvantage of UV-EPROM, is that it cannot be programmed while in the system board.
1.7 EEPROM(Electrically Erasable Programmable ROM) :
EEPROM has several advantages over EPROM. Its method of erasure is electrical and therefore instant, as opposed to the 20-minute erasure time required for UVEPROM. One can select which byte is to be erased, in contrast to UV-EPROM, in which the entire contents of the ROM are erased. One can program and erase its contents while it is still in the system board. EEPROM does not require an external erasure and programming device. The designer incorporates into the system board the circuitry to program the EEPROM.
1.8 RAM(Random Access Memory) :
RAM memory is called volatile memory since cutting off the power to the IC will result in the loss of data. Sometimes RAM is also referred to as RAWM (read and write memory), in contrast to ROM, which cannot be written to.
There are three types of RAM:
✓ Static RAM (SRAM),
✓ NV-RAM (nonvolatile RAM), and
✓ Dynamic RAM (DRAM).
1.9.1 SRAM (static RAM) :
Storage cells in static RAM memory are made of flip-flops. Therefore, they do not require refreshing in order to keep their data. This is in contrast to DRAM.
1.9.2 DRAM (Dynamic RAM):
DRAM (dynamic RAM) uses a capacitor to store each bit. It requires constant refreshing due to leakage of charge from the capacitor.
Packaging issue in DRAM:
In DRAM there is a problem of packing a large number of cells into a single chip with the normal number of pins assigned to addresses. To solve this problem, multiplexing is used. Column address and row address are multiplexed onto the same pins here. Row Address Strobe (RAS) and Column Address Strobe (CAS) are used to indicate whether the row address or the column address are carried on the address lines. This requires only half the number of address pins. As shown in Fig 1.3, in the 256Kx1 DRAM, the address lines A0 to A8 are used along with RAS and CAS to carry row address and column address respectively. Thus with 9 pins we can address 256K locations
1.9.3 Non-volatile random-access memory (NVRAM)
NVRAM is random-access memory that retains its information when power is turned off (non-volatile). This is in contrast to dynamic, random-access memory(DRAM) and static random-access memory (SRAM), which both maintain data only for as long as power is applied. The best-known form of NVRAM memory today is flash memory.
Memory Address Decoding
Large capacity memories are constructed using smaller blocks of memories. Hence the required block has to be selected based on the memory address. This is done by decoding the memory addresses. There are three ways to generate a memory block selector a) using simple logic gates, b) using a decoder, such as, 74LS138, and c) using the programmable logic. We discuss the first two methods here.
2.1 Decoder using NAND and other gates
Figure 2.1 shows 4K*8 memory chip Decoder with NAND and other gates. There are twelve address lines from A0-A11 for accessing the location and data lines from D0-D7.CS, RD and WR are the control signals. CS is the Chip select pin which is enabled by the address lines A15 to A12. If RD is set to 0, then we can read the Content, and if WR is set to 0, we can write into the chip. The chip select can be enabled by giving the address lines A15-A12=0011. This will correspond to an address range of 3000 to 3FFFH.
2.2 74LS138, 3-8 Decoder
The 3 inputs A, B, and C generate 8 active low outputs Y0 – Y7. O/P Y is connected to CS of a memory chip as shown in figure 2.2. It selects 8 memory blocks. A,B and C select which o/p is to be activated. Additional i/p’s G2A and G2B are both active low, and G1 is active high. If any one of the inputs G1, G2A, or G2B is not connected to an address signal, they must be activated permanently either by Vcc or ground, depending on the activation level.
2.3. Accessing On-chip and off-chip code ROM
In this section we are going to discuss the interfacing of 8031 microcontroller with external ROM. EA pin of 8031 microcontroller is connected to Vcc to indicate that the program code is stored in the C’s on-chip ROM. Figure 2.3 shows the on-chip and off-chip program code access.
To indicate that the program code is stored in external ROM, this pin must be connected to GND.
If we have EA= Gnd, then it refers to the on-chip Program. If EA=VCC, it refers to the off-chip program. However, , upon reset the 8051 executes the on-chip program first. Then, when it reaches the end of the on-chip ROM, it switches to external ROM for the rest of the program code.
2.3.1 8051 Interfacing with External ROM
CPU gives the address of the data required. Decoding circuit has to locate the selected memory block. Memory chips have CS (chip select) pin, which must be activated for the memory’s contents to be accessed.
The pins 29, 30 and 31 of the 8051 microcontroller (shown in Fig. 2.4) are used to provide the memory interface related signals.
Pin 29: PSEN-If we use an external ROM then this pin should have a logic 0 which indicates that the Microcontroller should read data from memory.
Pin 30: ALE/PROG- This pin is used for ALE that is Address Latch Enable. This pin is used to demultiplex address and data lines. This pin also gives program pulse input during programming of EPROM.
Pin 31: EA/VPP- If we have to use multiple memories then applying logic 1 to this pin instructs 8051 to read data from both memories – first internal and then external.
2.3.2 Steps to be followed when connecting external memory
CPU data bus is connected directly to the data pins of the memory chip. Control signals RD (read) and WR (memory write) from the CPU are connected to the OE (output enable) and WE (write enable) pins of the memory chip. The lower bits of the address from the CPU are connected directly to the memory chip address pins. The upper ones are used to activate the CS pin of the memory chip.
P0 and P2 role in providing addresses:
• The PC (program counter) of the 8031/51 is 16-bit, it is capable of accessing up to 64K bytes of program code.
• 16 bit address is provided by port 0 and port 2 to access external memory.
• P0 provides the lower 8 bit address A0 – A7.
• P2 provides the upper 8 bit address A8 – A15.
• P0 is also used to provide the 8-bit data D0–D7.
• P0.0 – P0.7 are used for both the address and data paths (address/data multiplexing).
The ALE signal is used to determine whether P0 carries address or data signals.
2.3.2.1 ALE (Address Latch Enable):
• ALE (address latch enable) pin is an output pin for 8031/51.
• When ALE = 0, then 8031 uses P0 for the data path.
• W hen ALE = 1, then 8031 uses P0 for the address path.
• To extract the addresses from the P0 pins, it is connected to 74LS373 D Latch. The pins and structure of 74LS373 are shown in figure 2.5.
• Separation of address and data can be obtained by using 74LS373. Figure 2.6 shows the address/data de-multiplexing. In the figure it is noted that when ALE=0 and P0 is used as a data bus, sending data out or bringing data in. Whenever the 8031/8051 wants to use P0 as an address bus, it puts the addresses A0-A7 on the P0 pins and activates ALE=1 to indicate that P0 has the addresses.
•PSEN is the Program store enable and it is an o/p signal. It is used to handle the Program memory and Data memory. PSEN is connected to OE pin of Program ROM. PSEN and EA of 8031/8051 are used to access external ROM. If the Memory is the Program memory then PSEN is connected to External Memory which reads the Program from the external Memory. If EA is connected to Ground then external ROM is accessed. If EA is connected to VCC, then the internal ROM is accessed. Figure 2.7 shows the Data, Address and Control buses for the 8031/8051.
While accessing the address, ALE should be equal to one, and for accessing the data ALE should be equal to zero. When accessing the external program memory, PSEN pin of 8051/8031 should be connected to the chip enable (CE and OE) pins of external memory, as shown in Figure 2.8.
2.44 8051 Data Memory Space
The 8051 has 128 bytes of address space.
- 64 bytes are set aside for program code.
- Program space is accessed using the program counter (PC) to locate and fetch instructions.
2.44.1 External ROM for data:
For the ROM containing the program code, PSEN is used to fetch the code.
For the ROM containing data, the RD signal is used to fetch the data. Figure 2.9 shows the connection to the external data ROM. Figure 2.10 shows the external memory for data.
2.44.1.1 MOVX instruction
We will now look at how the MOVX instruction is used to connect 8051 with the external data as shown in figure 2.11 .MOVX is a widely used instruction allowing access to the external data memory space. To bring externally stored data into the CPU, we use the instruction MOVX A,@DPTR.
Example: The word “SAM” has been burned in external data ROM locations starting from 4100H. Write a program to read this data into RAM locations of an 8031 starting from 60H.
Solution:
MOV DPTR, #4100H ;DPTR=4100H(points to first source location )
MOV A, @DPTR ;get ‘s’ from location 1000H
MOV 60H, A ;move it to data RAM location 60H
INC DPTR ; DPTR=4100H(points to next location)
MOVX A, @DPTR
MOV 61H, A
INC DPTR
MOVX A, @DPTR
MOV 62H, A
END
2.44.2 A single ROM for both program and data:
To access same external memory for data and program, PSEN and RD are connected to an AND gate to signal the OE pin of the ROM chip. Figure 3.1 and 3.2 shows the 8031 connection to external Program ROM, Data RAM and Data ROM.
Exercises: ( Refer figure 3.2)
1. Find the address space of the data RAM, data ROM and program ROM
2. Write a program to access bytes of data which is in data ROM, divide it by 2, and save the quotient in the data RAM
3. Re-write the program for the case that the data byte is in the program ROM
Solution for Exercise 1:
The address line A15 and A14 of data RAM =10 for the chip to be selected. Thus address space is 1000 0000 0000 0000 to 1011 1111 1111 1111(8000H to BFFFH).
For the data ROM, A15 and A14 of data RAM =00 for the chip to be selected. Thus address space is 0000 0000 0000 0000 to 0011 1111 1111 1111(0000H to 3FFFH).
For the program ROM, address lines A15 and A14 are not used in address decoding. However , if A15 and A14 are 0, then the address space is from 0000H to 3FFFH. But , it does not create a clash with the address space of the data ROM or RAM, because different instructions are used to access the code space and the data space.
Solution for Exercise 2:
Let the required data be in first location in data ROM and let us transfer the quotient to the first location in the data RAM. Note that MOVX instruction is used to access the data ROM.
ORG 0000H ; load the program in 0000H of program memory
MOV DPTR,#0000H ; let DPTR point to data location
MOVX A, @DPTR
MOV B, #02
DIV AB
MOV DPTR,#8000H
MOVX @DPTR, A
END
Solution for Exercise 3:
Assume that the required data has already been burnt into location 0100H of program ROM . Here MOVC instruction is to be used to access data from program ROM.
ORG 0000H
MOV DPTR,#0100H ; let DPTR point to data location
CLR A
MOVC A.A+@DPTR
MOV B, #02
DIV AB
MOV DPTR,#8000H
MOVX @DPTR, A
END
2.5 Interfacing to large External Memory
In some applications we need a large amount of memory to store data. Figure 3.3 shows 8051 Accessing the 256Kx8 External NV-RAM. For accessing the larger memory, some extra pins are used for accessing as address lines. P0 is address multiplexed. P2 is used for the address on the higher side. The 8051 can support only 64K bytes of external data memory since DPTR is 16-bit wide. To solve this problem, we connect P0 port and P2 port(A0 –A15) of the 8051 directly to the external memory’s A0 – A15 pins, and the additional A16 and A17 address pins are connected from P1.1 and P1.2 of 8051. Usually P0 and P2 ports are used as address ports, if needed P1 port pins can be used for additional address lines.
3.Summary
In this module, we have discussed different semiconductor memories in terms of capacity, organization and access time. We have also discussed interfacing of ROM with 8051, and demonstrated accessing code and data from external memory through assembly program.
4. References
- Muhammad Ali Mazidi, Janice Gillispie Mazidi, Rolin D. McKinlay, “The 8051 Microcontroller and Embedded Systems Using Assembly and C -Second Edition”, New Delhi(2000).