RTL Coding in VHDL
This portion of the lab consists of 3 parts:
- Parity Generator
- Special Counter
- Yards-Feet-Inches Converter
RTL coding in VHDL - Parity Generator
All source code and background files are located in the Google Folder under the appropriate lab folder.
See subfolder Labs/Lab01/VHDL/Parity
.
Description
A(n) (odd) parity generator gives a high output if the input data has an odd number of 1’s and a low output if the input has an even number of 1’s. So, this is a simple combinational XOR function of all the bits of the input. This can easily be described in HDL using a for
loop in a combinational process. You know that the for
loop is unrolled by the synthesis tool. You also know that the for
loop in a combinational process does not imply any hardware iteration like in a serial parity generator. In VHDL, the parity value should be a variable declared in the process, and not a signal declared in the architecture. It should be initialized to zero and it is XOR’ed with every bit of the input (one bit per iteration) and hence, after the for
loop is executed, it is effectively the xor of all the bits of the input.
Procedure
- Go through
parity.v
and understand the design - Run the Simulation tool (e.g. Modelsim, Questasim, etc) using the testbench file
parity_tb.v
and verify the result by reading messages in the transcript panel. - Make a file
parity_vhdl.vhd
by convertingparity.v
to VHDL.parity_vhdl.vhd
should have an entity namedparity_vhdl
and should have a 32-bit input calledin_data
and an 1-bit output,parity
. Please make sure to follow this naming convention otherwise it will not be compatible with the given VHDL testbench fileparity_vhdl_tb.vhd
. Our grading scripts on Unix also use these names. - Now repeat simulation, but this time with the VHDL version,
parity_vhdl.vhd
andparity_vhdl_tb.vhd
and verify the result.
Online Submission
submit -user ee560 -tag parity parity_vhdl.vhd names.txt
Ensure you:
- Make ONLY one submission for a lab team of two students.
- Take a snapshot of your successful submission on
viterbi-scf1.usc.edu
orviterbi-scf2.usc.edu
and save it to serve as a proof of your submission.
RTL coding in VHDL - Special Counter
All source code and background files are located in the Google Folder under the appropriate lab folder.
See subfolder Labs/Lab01/VHDL/Special-Counter
.
Prelab
Review pages 101 and 102 of the document EE201L_counters_blocking_non_blocking_r1.pdf
in the shared folder. You can also review EE201L_Special_counter_blocking_non_blocking_r1.pdf
.
Procedure
Review the skeleton files provided:
- Go through the following files (complete) and copy them to the above directory.
src/des/special-cntr.v
[Complete]: special counter design in Verilogsrc/tb/special-cntr-tb.v
[Complete]: testbench filesim/vlg/special-cntr-vlg.do
andsim/vlg/special-cntr-vlg-wave.do
[Complete]:.do
files to run simulation
Make a simulation project in the sim/vlg
folder, add the source files (design and testbench) – but avoid copies, just reference the given source files by adding “existing” items – and simulate the design using the .do
files. You can reference the EE457_ModelSim_PE_Testing_USC.pdf
file in the Lab01/VHDL
folder for a general walk through of how to setup a simulation project, though you don’t need to run through the actual example. Just use it as a guide for how to do the similar work with this codebase.
In this lab, we’re going to use .do
files so please type the following command in the ModelSim transcript panel after you make a project and start simulation.
do special-cntr-vlg.do
Then, analyze the output file special-cntr-results-vlg.txt
and verify your understanding of this special counter.
- Create a new project in the
sim/vhdl
folder calledspecial_counter_vhdl
. - Go through the following VHDL files (exercise files)
src/des/special-cntr.vhd
[Exercise]: special counter design in VHDL. Fill in the incomplete parts, looking for theTODO
instructions in the comments.src/tb/special-cntr-tb.vhd
[Complete]: testbench filesim/special-cntr-vhdl.do
andsim/special-cntr-vhdl-wave.do
[Complete]:.do
files to run simulation
- Simulate this VHDL design using the VHDL testbench and the appropriate
.do
files with theVHDL
labels. - If your design is correct, then it will produce
special-cntr-results-vhdl.txt
. Compare it with corresponding Verilog results which you obtained earlier.
Online Submission
FTP the appropriate individual vhdl
files to your UNIX account and submit them online to the ee560 class account using the following unix command:
submit -user ee560 -tag special-cntr special-cntr.vhd special-cntr-tb.vhd special-cntr-results-vhdl.txt names.txt
Ensure you:
- Make ONLY one submission for a lab team of two students.
- Take a snapshot of your successful submission on
viterbi-scf1.usc.edu
orviterbi-scf2.usc.edu
and save it to serve as a proof of your submission. - Celebrate your success!
RTL coding in VHDL - Convert Inches to Yards-Feet-Inches
All source code and background files are located in the Google Folder under the appropriate lab folder.
See subfolder Labs/Lab01/VHDL/Yards-Feet-Inches
.
Prelab
Before coming to lab, please go through the documents in the Google folder related to the Moore Machine question and solution for the Inches => Feet => Yards conversion
ee201_Quiz_Sp2010_Page_10_DataPath_Inches_Feet_Yards.pdf
ee201_Quiz_Sp2010_Pages_9_10_DataPath_Inches_Feet_Yards_sol.pdf
- Prof. Puvvada’s video explanation
Procedure
- Go through
src/des/divider_mealy.vhd
, andsrc/tb/divider_mealy_tb.vhd
. Understand the VHDL programming for state machines. (Note: Both files are for reference. While thedivider_mealy.vhd
can be used as the loose basis (starting point) of your newyfi
design, the testbench is primarily provided for reference. You could use it to simulate thedivider
design if you like, but you will not need to use it for theyfi
design.) - Create a VHDL file
yfi.vhd
in thesrc/des
folder, withentity yards_feet_inches
and update the top-level I/O to match that shown below.
entity yard_feet_inches is
port(
-- inputs
inches_in : in std_logic_vector(7 downto 0); -- inches
start : in std_logic;
ack : in std_logic;
-- outputs
done : out std_logic;
inches_out : out std_logic_vector(7 downto 0);
feet_out : out std_logic_vector(7 downto 0);
yards_out : out std_logic_vector(7 downto 0);
-- clock and reset
resetb : in std_logic;
clk : in std_logic
);
end yard_feet_inches ;
- Notice we use 8-bit signals for the
inches
input and output and thefeet
andyards
outputs. Finish this file according to the state diagram solution given above. Useyfi_long_tb_r1.vhd
as the testbench to test your design. This testbench is provided for your reading as it demonstrates various methods for testing your hardware:- Testing through for loop in the test bench.
- Testing through FileIO (Inputs & Outputs to/from files)
- Outputs to “Transcript” Screen
- Inspect the input (
yfi_input_operands.txt
) and result (yfi_output_actual.txt
). Ensure the calculations are correct.
Online Submission
FTP the appropriate individual files to your UNIX account and submit them online to the ee560 class account using the following unix command:
submit -user ee560 -tag yfi yfi.vhd yfi_output_actual.txt names.txt
Ensure you:
- Make ONLY one submission for a lab team of two students.
- Take a snapshot of your successful submission on
viterbi-scf1.usc.edu
orviterbi-scf2.usc.edu
and save it to serve as a proof of your submission. - Celebrate your success!