Due: Friday, October 5 at 16:30
May be completed in groups of maximum two students.
Note: Important changes indicated in red.
Introduction |
The purpose of this assignment is to construct a Memory Controller (MC)
that interacts with Static Random Access Memory (SRAM) through read and
write operations. The assignment is to complete a design and verify complete
functionality through simulation. The VHDL code can be developed and simulated
using the Altera MAX Plus II software.
The MC will be tested using
a simple host module that repeatedly makes use of the MC. A second method,
which you may undertake as an optional bonus component,
uses an external module that sorts the entries stored in the memory unit.
Background |
Current methods of storing memory are in large grids, or arrays, of cells that are associated to an individual address value. The width of these cells are variable and usually match the word length of the system. Memory blocks are most notably used to accompany Central Processing Units (CPU), however they can be used for other applications where storage of large amounts of information is necessary.
For satellites and other systems used in space, radiation bombardment can cause latchup and bit flipping. In order to combat these problems, data can be encoded in the form of Huffman codes. Huffman coding allows the detection of two errors, and can detect and correct one error. Therefore, a data word can be stored with its Huffman code and then checked when the data is read back. If one of the bits is incorrect when the data is read back, the error can be corrected.
The Assignment |
The requirements of this assignment is to construct an MC with Huffman coding to perform error correction. The SRAM is provided. During a write operation from the MC to the SRAM, the MC will have to compute the Huffman error code and load it into the SRAM along with the data word. When the data is to be read, the data will be retrieved along with the error code. The error bits will be used to determine if there was an error and if it can be corrected. Figure 1 shows a block diagram of the entire system including input and output signals. The external module that uses the memory unit is referred to as the host.
Figure 1: System Overview
The Static RAM |
A memory block entitled SRAM is provided. The SRAM is available in two versions. The first SRAM should be used to test the system and demonstrate functional operation. The second SRAM includes random error generation. It should be used to demonstrate that your Huffman coding works properly. You may need to simulate over an extensive period to find an error in the memory block.
In order for data to be written to and read from the memory correctly, specific read and write procedures must be followed. Both the read (read_n) and write (write_n) lines are active low.

Figure 3: Write Procedure
The addressing scheme of the SRAM allows the cells to be addressable in 8 bit increments, even though the word size is 16 bits. The memory block is addressed as if the data bus is only 8 bits wide. However, 16 bits are actually being written and read during a memory access. Therefore, adjacent 16-bit cells differ by an address value of two instead of one.
Figure 4: SRAM Addressing
The next example is accesses to two adjacent 8-bit words. The first address value would be 4 and the next would be 5. The difficulty with writing with 8-bit words is the fact that 16-bits are always written. As a result, if the MC is to write 8-bits into cell 4 again to overwrite the existing data, the value in cell 5 would also be overwritten. If the MC was writing a 16-bit word, then this would not matter. The write procedure for 8-bits must include a protective measure to ensure that the most significant bits are not lost (i.e. the data in cell 5 is preserved) This can be done with a read procedure before writing an 8-bit word.
The Memory Controller |
The memory controller has the purpose of accessing the memory. It must adhere to the timing specifications in order to read and write data properly. The common bus that is used to interact with the SRAM can be made private under the assumption that it is a direct connection between the components.
Since the data word is 16 bits and the Huffman error code is only 5 bits, only three 8-bit cells should be used. Since the data bus is only 16 bits, two write and read operations will be necessary to access all of the data and error bits. Also, the data should be packed as tightly as possible to save space (i.e. in 8-bit increments, not to pack every single bit).
From the point of view of a host connected to the MC, the MC appears to be a linear array of ten 16-bit memory cells. The host addresses the MC in word increments. The MC maps this address to its actual location in the SRAM. For example, if the host device wishes to store a word in address 1, the MC will be placing it with its error code in cells 3, 4, and 5.
Huffman Coding |
Huffman error coding is an algorithm that allows the detection of two errors and the correction of one error. For a 16 bit word, there are 5 error bits. They are calculated as follows:

Once these check bits are computed using XOR gates, they are stored in RAM with the data. When the data is retrieved, the error check bits are computed again and then compared with the error check bits retrieved from the memory block.

If errors do not exist, C[4..0] should be “00000”. If there is one error, the numerical value of C corresponds to the location of the error in the following manner.
Table 1: Value Mapping
| Numeric
Value |
Bit | Numeric
Value |
Bit | Numeric
Value |
Bit |
| 1 | P0 | 8 | P3 | 15 | B10 |
| 2 | P1 | 9 | B4 | 16 | P4 |
| 3 | B0 | 10 | B5 | 17 | B11 |
| 4 | P2 | 11 | B6 | 18 | B12 |
| 5 | B1 | 12 | B7 | 19 | B13 |
| 6 | B2 | 13 | B8 | 20 | B14 |
| 7 | B3 | 14 | B9 | 21 | B15 |
Therefore, the value of the data bits can be corrected before they are
transmitted by the MC.
Testing the SRAM and Memory Controller |
The SRAM and memory controller will be tested by writing a simple host module that repeatedly reads and writes to the SRAM through the memory controller. The second method (optional as bonus)
involves designing a circuit which performs the bubble sort algorithm on the contents of the memory unit. Both of these methods are explained in greater detail below.
Figure 5: System overview with bubble sorter attached to MC.
for (i=0; i<n-1; i++) {
for (j=0; j<n-1-i;
j++)
if (a[j+1] < a[j]) { /* compare the two neighbours */
temp = a[j]; /* swap a[j]
and a[j+1] */
a[j] = a[j+1];
a[j+1] = temp;
}
}
As shown above, the index j in the inner loop travels up the array, comparing adjacent entries in the array while the outer loop causes the inner loop to make repeated passes through the array. After the first pass, the largest element is guaranteed to be at the end of the array, after the second pass, the second largest element is in position, and so on.
Note that the code shown above is a software implementation of the bubble sort algorithm and therefore cannot necessarily be implemented in hardware in the same way. To successfully implement this algorithm in hardware, you must think carefully about the states needed to perform the desired operations (see the section below).
The Report |
The design should be fully tested, simulated, and assured to be functional.
The report will be based on the design, simulation and analysis.
Mark Breakdown |
The assignment will be graded as follows:
Memory Controller (85%)
Proper documentation and commenting will play an important role in the marking. Each file header should include the filename, title, author, date, and a brief description. The brief description should explain how the functional block represented by that file works from a black box point of view. It should be written in such a way that someone could read the description and look at the ports in the entity declaration and understand what the functional block does and how it can be used. This does not need to be very long. There should also be a few descriptive words of comment next to each port in the entity declaration. Each process should have another brief description just before the process declaration. It should describe how the process works. If the process is a finite state machine, describe each state and its purpose along with the other states it would transition to and why.
The simulations should include the important signals in the external and internal operation of the blocks. There should be clear and concise indications on the simulations describing what is happening. Key points in the simulation should be pointed out. Simply write on the simulations with a pen (multicolored would be best) indicating what state the block is in and what transitions are important. However, there should not be any clutter. The simulations should be large and found in the appendix. Important simulations should be reproduced in the report body.
The report should include a short description of the design and any interesting or important elements encountered in the design process. Also, the interesting features of the design should be pointed out. The important diagrams should be shown in the body of the report, however there may be references to diagrams and simulations in the appendices. The exact organization of the report is left to your discretion.
The size of the design should be indicated by the number and % of logic blocks that were used. Excepts from the .rpt file should be included in the appendix in order to demonstrate this value. Only the important parts of the .rpt file should be included such as the Device Summary and the Resource Usage. DO NOT INCLUDE THE ENTIRE REPORT FILE IN THE APPENDIX.
Discuss limitations of your design and possible improvements.
Enclosures |
The hardcopy report must contain all VHDL code and simulations and excerpts from the .rpt file. Also, all the simulation files (.scf), VHDL files (.vhd), and the overall design report file (.rpt) (i.e. not one for each component) must be tared, uuencoded and emailed to the instructor. Refer to assignment #1 for the exact procedure. Replace 487-A1-LASTNAME by 487-A2-LASTNAME or by 487-A2-LASTNAME1-LASTNAME2 in the case that you worked on this assignment in groups of two.
Note that there is no mini-presentation component for this assignment.