RAM/ROM Overview for Quartus II
Group: Wireless Instant Messenger
Kevin Ogden
Nick Hutniak
James Ding
Boldwin Li
Horace Chan
Brian Tsang

Introduction
Implementing a significant amount of RAM or ROM on an Altera FPGA such
as the APEK20KE can be done using MegaWizard Plug-In Manager using Quartus
II. The Plug-In manager allows you to create commonly used custom modules
that take advantage of the specific FPGA hardware. In this case the plug-in
wizard allows the user to create custom RAM/ROM which takes advantage of
the EABs (embedded array blocks) inside the FPGA. The trade-off here is
while using the on-board hardware, such as the EABs, the design becomes
more difficult to port to other devices. This document compares using the
EABs and logic elements, goes through a tutorial to instantiate custom
RAM/ROM on Quartus II, Describes mif files providing an example of file
generation, and compares the device usage with a LPM RAM with a RAM which
does not use this library.
EABs vs. Logic elements
To avoid using up a lot of space in your design, EABs can be used for RAM
and ROM. Implementing RAM without using Altera's LPMs requires the use
of flips flops inside the logic elements of the device. Since each logic
element has only a single D Flip-flop this requires a logical element for
each bit of memory in the RAM. For a specific example the APEK20K-200EFC484-2
contains only 8,320 LEs and therefore would capable of just over 8Kbits
of RAM if the EABs were not utilized. However the same device has 106,469
EABs which is capable of storing the same number of bits as RAM. If the
Plug-in wizard is used the compiler can recognize to use apropriate EAB
for the design which frees up LEs for the remaining design.
MegaFunction Wizard for Quartus II- RAM Tutorial
1. Go to: Toolbar >> Tools >> MegaWizard Plug-In manager
2. Select Create a new custom megaFunction variation
3.
Specify the Megafunction: STORAGE / LPM_RAM_DQ
Choose the device family, output name ect....
Make sure to specify the output file as VHDL
Next....
4.
The next couple of windows let you specify parameters for your design
such as data and adress width, and clock specifications
Next....
5.
Now a you are asked to supply the name of the file which initialize
the contents of your RAM/ROM:
Specify a *.mif (memory initiliazation file) so you can edit
the contents of the RAM
You have now sucessfully generated a RAM module which utilizes the EABs.
There will be two *.vhd files generated: filename.vhd (the custom function
design file) and filename_inst.vhd (a template showing how you would instantiate
the design). The first file is not intended to be read from or written
to, therefore filename_inst.vhd is supplied to allow the user to create
an instance of the design in a seperate file.
Note: the design file output from the MegaWizard needs to be included
in the project for sucessful compilation.
toolbar >> project >> add.remove files from project
Memory Initialization Files
The mif file are used to initialize the contents of the LPM RAM or ROM.
This file is a generic parameter of the module, lpm_file and will be set
for you if you have used the wizard. The following is a description of
the syntax of a *.mif file, which is useful if the conents need to be generated
by a C program which parses a file already containing the contents or calculate
the contents.
%%The sample file below is for a ROM with 16 address locations each
containing 3 bits of data.
DEPTH = 16; % the number of address locations
WIDTH = 3; % the width, in bits, of the stored data
ADDRESS_RADIX = DEC;
DATA_RADIX = OCT;
-- various ways of specifying the initial contents
CONTENT BEGIN
0 : 7; % single assignment - M[0] = 7
[1..3] : 2; % multiple rangle assignment - M[1] = M[2] = M[3] = 2
6: 0 1 2; % multiple assignment goes downwards in address - M[6] =
0 ,M[5] = 1, M[4] = 2
[6..15] : 3; % most recent value is used if multiply assigned - M[6]
= 3
END;
Using C code to generate a *.mif file
In our design for an instant messenger we have decided to use blowfish
encryption to keep the conversations secure. We have taken open-source
VHDL code from the intenet to implement the design. The blowfish algorithm
requires the first 33,344 bits of pi stored in ROM to be able to process
the key. The ROMin the original design is written such that it is portable,
therefore it does not use Altera's LPM. The LPM modules for ROM were
used instead, however it would be a painstaking task to initialize the
first 30,000+ bits of pi by hand using the .mif syntax above. A parser
written in C++ was developed to extract these values from the original
file and output them in *.mif format.
The following is a sample of the ROM initialization from the original
VHDLcode
contents(0 ) <= x"3a39ce37";
contents(1 ) <= x"d3faf5cf";
contents(2 ) <= x"abc27737";
contents(3 ) <= x"5ac52d1b";
contents(4 ) <= x"5cb0679e";
.... many more
The output of the parser in *.mif syntax
0 : 3a39ce37;
1 : d3faf5cf;
2 : abc27737;
3 : 5ac52d1b;
4 : 5cb0679e;
... many more
mem_parse.cpp
Results of expirementation
The use of the LPM_RAM_DQ made it possible to fit the blowfish encryption
core onto an FPGA. To illustrate this we will compare two RAMs each used
to store a chunk of the expanded key. For the first attempt at compilation
the unmodified code obtained from the internet is shown below:
167% of the total logical elements are used! LEs are not good
for large amounts of memory.
Now the resources used by an LPM_RAM_DQ created by the MegaWizard
Only 7% of the EABs (Total memory bits are used) and none of the LEs
are used for the same size of RAM.
References:
EE552 Lab#5 http://www.ee.ualberta.ca/~elliott/ee552/#LabAssignments
Blowfish code taken from: http://sourceforge.net
Kevin Ogden March 3, 2003
Questions/Comments? kogden1@hotmail.com