ASIC Design Lab
Lab 2
Spring 2018
ASIC Design Lab 2:
Introduction to Various Styles of Verilog Source Code and
Design Test Benches
In this lab, you will:
• Create and Test Verilog code for the STRUCTURAL model of the Sensor Error Detector System
using ModelSim (sensor_s.sv)
• Create and Test Verilog code for the DATAFLOW model of the Sensor Error Detector System
using ModelSim (sensor_d.sv)
• Create and Test Verilog code for the BEHVIORAL model of the Sensor Error Detector System
using ModelSim (sensor_b.sv)
• Modify the Makefile to optimize the 3 versions of the design that you are examining
• Create and Test Verilog code for a 1-bit Full Adder using Modelsim (adder_1bit.sv)
• Create and Test Verilog code for a 4-bit Ripple Carry Adder using Modelsim (adder_4bit.sv)
• Create and Test Verilog code for a parameterized N-bit Ripple Carry using Modelsim
(adder_nbit.sv)
• Create and Test Verilog code for two Synchronizers using Modelsim (sync_low.sv & sync.high.sv)
NOTE: For this class you must name the Verilog source code file the same name as the module name, plus
the ".sv" extension. For example, if the module name is "sensor_d", then the file name should be
“sensor_d.sv”. Also, all module, port, and filenames must be all lowercase in this class.
1. Lab Exercises
1.1. Lab Setup
In a UNIX terminal window, issue the following commands, to setup your Lab 2 workspace:
mkdir –p ~/ece337/Lab2
cd ~/ece337/Lab2
dirset
setup2
The setup2 command is an alias to a script file that will check your Lab 2 directory structure and give you
file needed for starting the lab. If you have trouble with this step please ask for assistance from your
TA.
Make sure to add this new workspace into your 337 Repository, like you did in Lab1. This way, you will
always have the original copy in storage.
1
ASIC Design Lab
Lab 2
Spring 2018
1.2. Sensor Error Detector Design
1.2.1. Structural Style Sensor Error Detector Design
1.2.1.1. Structural Style Sensor Error Detector Specifications
The required module name is:
sensor_s
The required filename is:
sensor_s.sv
The module must have only the following ports (case-sensitive port names):
input wire [3:0] sensors
output wire error
Create the source file using the following ‘ch’ script command from your Lab2 folder:
ch sensor_s.sv
1.2.1.2. Structural Coding of Sensor Error Detector
A structural model for a Verilog model is much like what would be consider a pure netlist description of
the cell. A netlist is essentially a text representation that describes a circuit in terms of the explicit
interconnections between sub-blocks. This explicit description describes what signals are input to a subblock and what signals are outputs from this sub-block and how they interact with the other sub-blocks in
the design. This is the style that is probably the easiest to understand and create a design in. This is the case
because it is relatively easy to map a K-Map derived expression for a logic function into this style of
Verilog. Therefore, this is the Verilog style that will seem the most logical to most students; however, this
style is not the most powerful of the design styles for Verilog. The structural model is one that lends itself
to directly illustrating a hierarchal design in Verilog. A hierarchal design is one in which you use several
smaller designs to create a larger design. An example of a hierarchal design would be a 16-bit adder that is
built from a combination of 1-bit adders. In this design, you would have 16 instantiations of the 1-bit adder
design that are interconnected in order to perform the function of a 16-bit adder.
The hierarchal design methodology is what is employed in industry. This should make sense to you simply
from a design point of view. The majority of the designs being done in industry are at such a degree of
complexity that no one person on the design team knows every detail of the overall system. Instead, the
overall system is divided into units which are divided into blocks, which are divided into sub-blocks. These
sub-blocks are relatively easy to manage aspects of the overall project that one engineer or a small group
can be responsible for. Even these sub-blocks have a hierarchal aspect to them. For instance, one portion
of the design may be highly optimized because it is the most critical portion of the sub-block. This optimized
portion of the sub-block is then encapsulated in a symbol and placed into schematic at a higher level in the
sub-blocks internal hierarchy.
This hierarchal design methodology has an additional benefit in terms of testability of a design also.
Logically, small blocks are able to be more thoroughly tested than larger blocks. This statement is derived
from the fact that smaller blocks generally have fewer inputs, so it is possible to run a small block through
its entire range of input values to make sure it is functioning correctly. However, as one moves up the levels
in the design hierarchy the ability to thoroughly test a design becomes more difficult. In the case of
microprocessors, thoroughly and completely simulating a design is simply not a feasible option. In order to
test a microprocessor all its possible input vectors would require an enormous amount of compute cycles,
not to mention the incredible amount of engineer hours it would require to generate the test vectors and
ensure that the person designing the test vectors also determines the correct response that should be
generated from each test vector. From this, one should see that it is imperative that the lower levels in the
hierarchy be tested thoroughly to ensure that they function properly. Ensuring that the lowest levels in the
2
ASIC Design Lab
Lab 2
Spring 2018
hierarchy function correctly allows the top-level design testing process to be an attainable goal, as opposed
to an insurmountable goal.
In lab 1’s post lab, you derived a logic expression from a K-Map for the Sensor Error Detector circuit. This
logical expression that you derived was in the SUM OF PRODUCTS form. You are now going to
implement this logic equation using the structural Verilog coding style. The list of 2-input logic cells (and
their ports) that you might need from the standard cell library is as follows:
Logic Cell Function
Logic Cell Module Declaration
2-Input AND Gate
AND2X1 (input A, input B, output Y)
Inverter
INVX1 (input A, output Y)
2-Input NAND Gate
NAND2X1 (input A, input B, output Y)
2-Input NOR Gate
NOR2X1 (input A, input B, output Y)
2-Input OR Gate
OR2X1 (input A, input B, output Y)
2-Input XOR Gate
XOR2X1 (input A, input B, output Y)
2-Input XNOR Gate
XNOR2X1 (input A, input B, output Y)
For example, the following line of code creates an instance of a 2-input AND gate with a label of ‘A1’,
with signals ‘a’ and ‘b’ connected to its inputs, and signal ‘int_and1’ connected to its output.
AND2X1 A1 (.Y(int_and1), .A(a), .B(b));
Utilizing this information, the specifications in section 1.2.1.1, your sum-of-products equation from lab 1’s
postlab, and any Verilog code syntax references, create the structural style sensor detector code in your lab
2 source folder.
1.2.1.3. Testing of the structural style Sensor Error Detector
Part of what the setup2 script did was give you a copy of a Verilog code file (tb_sensor_s.sv), which is what
we call a test bench file. This code file is a module that creates an instance of the design file it is used to
test and controls the values of this instance’s inputs in order to force the design being tested through a
variety of test cases that were implemented with the test bench module. This is the way all designs for the
rest of the course will be tested, as it is much more powerful and more efficient than using force statements
like you did in lab 1. To simplify the usage of test benches for testing designs, the makefile provided by
dirset also has simulation targets for simulating test benches of single file designs. To simulate the provided
test bench for the structural sensor detector module, execute the following command from your lab 2 folder.
make tbsim_sensor_s_source
This make target compiles both the test bench file tb_sensor_s.sv and the design file sensor_s.sv if needed
and then starts a simulation of the tb_sensor_s test bench module. Once the simulation has loaded, add the
design’s port signals and the signal named ‘test_number’ to the waves window and then tell ModelSim to
run for 200 ns. At this point have your TA verify your Waveforms window.
3
ASIC Design Lab
Lab 2
Spring 2018
Now check the design’s output for correctness for each test case (‘test_number’ should always increment
when a new test case starts). If an incorrect output is found, make corrections to your design’s code,
recompile the design (this can be done easily from within modelsim by right clicking on the design instance
in the “source_work” library and selecting recompile), and restart the simulation (“restart –f”), and rerun
the simulation.
After a fully correct source simulation, synthesize the design and simulate the mapped design with the same
provided test bench to check for any errors during design synthesis. The command for simulating the
mapped design with its test bench is
make tbsim_sensor_s_mapped
Once you have a fully working design proceed to the next section.
1.2.1.4. Automated Grading of the Structural Sensor Error Detector
In this class all design code will be graded via a set of grading scripts and custom grading test benches that
are run during via submission commands. To submit your structural sensor detector design for grading,
issue the following command at the terminal (can be from anywhere).
submit Lab2s
1.2.2. Dataflow Style Sensor Error Detector Design
1.2.2.1. Dataflow Style Sensor Error Detector Specifications
The required module name is:
sensor_d
The required filename is:
sensor_d.sv
The module must have only the following ports (case-sensitive port names):
input wire [3:0] sensors
output wire error
Create the source file using the following ‘ch’ script command from your Lab2 folder:
ch sensor_d.sv
1.2.2.2. Dataflow Coding of Sensor Error Detector
Utilizing the dataflow syntax examples from the lab 1 manual, lab notes, and other Verilog references,
create a dataflow style design according to the requirements in section 1.2.2.1. Remember that a purely
dataflow style design cannot have any procedural blocks and all value assignments must be done with the
‘assign’ syntax. Additionally the setup2 script has provided you with a test bench module for the dataflow
style sensor detector as well (tb_sensor_d.sv). Make sure that the design is fully working before proceeding
to the next section and submitting it for grading.
Also, as a reminder of the use of the makefile’s pattern rules for simulation, the make targets for simulating
the dataflow source and mapped versions respectively are
make tbsim_sensor_d_source
and
make tbsim_sensor_d_mapped
1.2.2.3. Automated Grading of the Dataflow Sensor Error Detector
To submit your dataflow sensor detector design for grading, issue the following command at the terminal
(can be from anywhere).
submit Lab2d
4
ASIC Design Lab
Lab 2
Spring 2018
1.2.3. Behavioral Style Sensor Error Detector Design
1.2.3.1. Behavioral Style Sensor Error Detector Specifications
The required module name is:
sensor_b
The required filename is:
sensor_b.sv
The module must have only the following ports (case-sensitive port names):
input wire [3:0] sensors
output reg error
Create the source file using the following ‘ch’ script command from your Lab2 folder:
ch sensor_b.sv
1.2.3.2. Behavioral Coding of Sensor Error Detector
Utilizing the dataflow syntax examples from the lab 1 manual, lab notes, and other Verilog references,
create a behavioral style design according to the requirements in section1.2.3.1. Remember that a purely
behavioral style design cannot have any functional/logic code outside of the procedural blocks, and the
combinational logic should be handled inside an ‘always’ block with each of its input signals in the
sensitivity list. Also, for this class initial blocks are forbidden inside design modules, and are only allowed
to be used in test benches. Additionally the setup2 script has provided you with a test bench module for the
dataflow style sensor detector as well (tb_sensor_b.sv). Make sure that the design is fully working in its
mapped/synthesized form before proceeding to the next section and submitting it for grading.
Also, as a reminder of the use of the makefile’s pattern rules for simulation, the make targets for simulating
the behavioral source and mapped versions respectively are
make tbsim_sensor_b_source
and
make tbsim_sensor_b_mapped
1.2.3.3. Automated Grading of the Behavioral Sensor Error Detector
To submit your structural sensor detector design for grading issue the following command at the terminal
(can be from anywhere).
submit Lab2b
5
ASIC Design Lab
Lab 2
Spring 2018
1.3. Design Schematics for Synthesized Design Code
In this section you will be viewing schematic representations of the gate net lists synthesized from your 3
sensor detector implementations.
1.3.1. Viewing the Structural Style Schematic
In your terminal, in your Lab 2 directory, bring up the Design Compiler GUI (yes, our synthesis tool has a
GUI, called Design Vision, but we won’t be using it much) by typing
dv
In the window that comes up, select:
File → Read
Open the file “mapped/sensor_s.v” and select OK.
At the very right of the toolbar below the menu is a box where can choose the current design.
Make sure that the top-level module name is selected (sensor_s). Now go to the menu and select
Schematic → New Design Schematic View
If you zoom in (View → Zoom) you can see the component types and names, as well as signal names. If
your design has sub-components (though this design probably won’t), you can see their schematics by
selecting them with the LMB and selecting Schematic → Move Down. You can return to the top level by
selecting Schematic → Move Up.
Once you have generated a schematic view using Design Vision, have a TA check off your work up
to this point.
1.3.2. Viewing the Dataflow Style Schematic
Analyze the schematic of your mapped dataflow implementation (mapped/sensor_d.v) with Design Vision,
as before.
Once you have generated the schematic in Design Vision, have a TA check off your work up to this
point.
1.3.3. Viewing the Behavioral Style Schematic
Use Design Vision to examine the schematic for you mapped behavioral implementation
(mapped/sensor_b.v), remembering that you can view internal blocks in the design hierarchy by moving up
or down in the schematic. Once you have a clean schematic (no extraneous wires), have a TA check off
your work up to this point. Also, make sure to update the versions of your sensor code in Git using
the checkin (‘ci’) command.
6
ASIC Design Lab
Lab 2
Spring 2018
1.3.4. Design Synthesis Optimization
The designs you just synthesized are incredibly simply hardware systems and so will be naturally very fast
and easy for the tools to optimize. This will likely result in your three design schematics looking either
identical or very similar. When working with more complex designs such as the provide 16-bit adder design
it may become necessary to utilize different synthesis commands in order to guide, and sometimes force,
the tools to optimize the design further than initial synthesis attempts in order to meet either area or timing
constraints for the design usage.
Therefore, you are going to alter your “SYN_CMDS” variable in the makefile so that it will cause Synopsys
to perform two compilation passes. In modifying your makefile to accommodate a second compilation
pass, you will add a timing constraint to the compile options and instruct Synopsys to allow the
mapped design to be restructured. In order to apply the timing constraint, you will have to use the
command 'set_max_delay’, which has the following syntax:
set_max_delay -from "" -to "
Source Exif Data:
File Type : PDF
File Type Extension : pdf
MIME Type : application/pdf
PDF Version : 1.7
Linearized : No
Page Count : 17
Language : en-US
Tagged PDF : Yes
XMP Toolkit : 3.1-701
Producer : Microsoft® Word 2016
Title : Lab 2 - Introduction to Structural Source Code and Test Benches
Creator : Administrator
Creator Tool : Microsoft® Word 2016
Create Date : 2018:01:15 19:04:40-05:00
Modify Date : 2018:01:15 19:04:40-05:00
Document ID : uuid:B1865883-69E0-4616-ADB0-02A6E57FAB8C
Instance ID : uuid:B1865883-69E0-4616-ADB0-02A6E57FAB8C
Part : 3
Conformance : A
Author : Administrator