1. Create a
new project and label it as Lab7. Then
add a new Schematic design to your project and save it as Lab7.bdf
2. Use the
following steps to set-up the ROM for this project. This ROM
will store the Binary to seven-segment mapping of data. To build
the ROM, you will use a megafunction provided by Altera.
Magafunction is a complex or high-level building block that can
be used to design a complex logic system. We will use MegaWizard
Plug-In Manager to build a megafunction.
a. Open the
Symbol dialog
box and enter lpm_rom under Name: text
box. Then click OK.
b. A new
dialog box named MegaWizard Plug-In Manager will
appear.
c. Now you
need to select the type of output file that you need to build.
Since we are working with Altera, select AHDL as the
type of output file. AHDL stands for Altera Hardware Description
Language.
d. Then
click Next.
Then you need to select the
parameters and dimensions of the ROM that you are going to
build. We will be building a ROM with 256 addresses and each
address will contain a 24-bit word.
e. Select Cyclone II as the
Currently
selected device family:.
f.
Select 24 as the
width of the output bus (i.e., word size).
g. Select 256 as How many 24-bit
words of memory (i.e., number of addresses).
h. Then
select Next. Click Next again.
Next we need to store the content
of the ROM (i.e. the mapping between Binary to BCD). The content
of the ROM can be given as a separate file named Memory
Initialization file which we will create. Follow the steps
below:
i. Select
Yes, use this file for the memory content data. Type
the file name as: Bin_to_BCD.mif.
j.
Then select Next. We
will use the simulation file automatically selected by the
wizard so click Next again.
k. To
finish the wizard click Finish.
Then you can place the newly
generated ROM on your schematic design. Note that the new ROM
has buses instead of individual input/output pins (except for
the clock input).
3. Next we
need to add input/output pins to the schematic design. Let's
create 2 buses for input and output.
a. Add 2
input pins and 1 output pin. Label the first input pin as Address[7..0] this
will create a 8-bit address bus. Label the output pin as BCD[23..0] this
will create a 24-bit output. Connect the second input pin to the
clock.
4. Next we
will create a Memory Initialization file.
Create a new Text file in your project folder.
Open the Notepad file
and copy the following to create a Memory Initialization file.
DEPTH = 256;
WIDTH = 24;
ADDRESS_RADIX = HEX;
DATA_RADIX = HEX;
CONTENT
BEGIN
[00..FF] : 00;
END;
Here DEPTH
indicates the number of address in the
Rename the file as Bin_to_BCD.mif.
Make sure that the format of the file is now changed from
.txt to .mif.
5. It is
more convenient to open and further edit this file using Quartus
II software. Note that you can also create the Memory
Initialization file using Quartus II however the manual approach
makes the file simpler and clearer (you can play with auto
generated files when you are experienced).
a. Open Bin_to_BCD.mif file
using File > Open menu in
Quartus II software.
b. In the
Memory Initialization file copy and paste the memory contents
from the excel sheet you created, so that you can show the
appropriate 7-segment output for the given binary number. Note
that data stored in a block with address 'XXX' with be outputted
by the ROM when we provide 'XXX' as input.
c. To view
delimiter spaces, click View > Show Delimiter
Spaces. You will now see your inputs as 3 blocks of 2
hexadecimal digits.
d. To avoid
any confusion lets select pin A of the 7-segment display as the
LSB in each 8-bit output block.
e. For an
example in address 000 (i.e. to display 000 in BCD) using all
three 7-segment displays set the memory content as 40 40 40.
Similarly for 1 and 2; 40 40 79 and 40 40 24. Make
use of the pre-lab to fill up the rest of the table.
Remember that the 7-segment display
in DE2 board need logic levels to be inverted. So above values
are selected based on that.
6. Compile
your circuit and make sure there are no errors.
7.
When you assign pins select the 7-segemnets in DE2 board as
follows. HEX0 should be the LSB in
Decimal and HEX2 should be the MSB in
Decimal. Assign switches SW0 to SW7 as the
addresses (i.e. inputs to ROM). Connect the clock to KEY0.
8. Then
recompile the circuit.