Updated Fall 2021 Robucci
In this lab you will learn how to write a structural Verilog for a circuit and simluate it to test its functionality. You will use DeMorgan’s Theorem to manipulate a logical expression to change its mapping to gates. You will use Verilog to describe the circuit. We will learn how a testbench is used to a test the circuit.
De Morgan’s laws
In propositional logic and boolean algebra, De Morgan’s laws are a pair of transformation rules that are both valid rules of inference. These rules can be expressed as:
–quoted from https://en.wikipedia.org/wiki/De_Morgan’s_laws Wikipedia contributors. “De Morgan’s laws.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 9 Sep. 2021. Web. 22 Sep. 2021.
In the following circuit, we are going to convert equation to map to nor gates and a inverter:
(pin numbers in this diagram correspond to pin numbers on your discrete 74LS ICs)
The output of the circuit can be expressed as:
Then we make complement both side of the equation:
Now we apply the De Morgan rule on the right side of equation:
Finally, we need another complement to get the from
As the equation shows, the function can be mapped by two nor gates as demonstrated in the following picture. The bubbles represent inversion:
The truth table of this circuit including inputs, output, and intermediate signals are given below:
Inputs | Intermediate Signals in Circuit 1 |
Intermediate Signals in Circuit 2 |
Output | |||
---|---|---|---|---|---|---|
A | B | C | p | m | n | F |
L | L | L | L | H | H | L |
L | L | H | L | H | L | L |
L | H | L | H | L | H | L |
L | H | H | H | L | L | H |
H | L | L | H | L | H | L |
H | L | H | H | L | L | H |
H | H | L | H | L | H | L |
H | H | H | H | L | L | H |
In the discussion session you are going to use Verilog to simulate the following circuit.
module first_verilog_str(A, B, C, F); input A; input B; input C; output F; logic x; logic y; and(x, C, A); and(y, C, B); or(F, x, y); endmodule
As an educational exercise in this lab, you will be provided models of the 74LS series chips with functions pin orders. You can use these to perform a digital simulation with a netlist matching your breadboard circuit.
The IC models are provided here: cmpe212_ic.v
module first_verilog_IC(A, B, C, F); input A; input B; input C; output F; logic x; logic y; IC74LS08 myand(.Y2(x),.B2(A),.A2(C),.GND(1'b0),.A4(C),.B4(B),.Y4(y),.VCC(1'b1)); IC74LS32 myor(.Y1(F),.A1(x),.B1(y),.GND(1'b0),.VCC(1'b1)); endmodule
To test the functionality of HDL codes unlike High Level Languages(HLL) such as C/C++, Python needs another code. This code is generally called testbench code. In the following testbench, we show how to model the switch in the picture with three reg variable A, B, and C. In this example, we just instantiate the first_verilog_IC module to test the functionality of it.
module test_bench(); /*anything that you set in the initial begin...end block should be declared as reg. Here A, B, C stand as the switch operation.*/ logic A, B, C; /* the outputs of instantiated module in the testbench are defined as wire*/ logic F; /* Instantiate Circuit Here */ first_verilog_IC uut(.A(A), .B(B), .C(C), .F(F)); /* Testbench Logic */ initial begin $monitor("(%t): A:%b B:%b C:%b F:%b",$time, A, B, C, F); /* here each 1000 unit timescale the value of A, B, C are chenged. It seems that we change the switches position*/ A = 0; B = 0; C = 0; #1000; A = 0; B = 0; C = 1; #1000; A = 0; B = 1; C = 0; #1000; A = 0; B = 1; C = 1; #1000; A = 1; B = 0; C = 0; #1000; A = 1; B = 0; C = 1; #1000; A = 1; B = 1; C = 0; #1000; A = 1; B = 1; C = 1; #1000; end endmodule // test_bench
To compile this test bench and make an output with the name of my_out, we would use the following:
iverilog -g2012 -o my_out cmpe212_ic.v first_verilog_IC.v test_bench.v
To run the output:
./my_out
After simulation you should see the result the same as the picture:
By default, the delays embedded in the IC modules are not simulated. To turn them on use the specify flag (the default is no-specify):
iverilog -g2012 -g specify -o my_out cmpe212_lab4.v first_verilog_IC.v test_bench.v
To run the output:
./my_out
The result is:
To use a waveform viewer, you must dump the waveforms to a waveform file.
Add the following code to the beginning of the initial begin…end block in your test bench code, on the line just after the begin
$dumpfile("my_out.vcd"); $dumpvars;
Make sure to compile, but then instead you might need use vvp to run the executable in order to produce the waverform dump.
iverilog -g specify -o my_out cmpe212_lab5.v first_verilog_IC.v test_bench.v vvp ./my_out
To run the waveform viewer, include the file name or simple use the GUI File menu to select the file.
gtkwave my_out.vcd
download MobaXterm from the below link and install:
https://mobaxterm.mobatek.net/download-home-edition.html
Open MobaXterm then click on Session and select SSH. Write ‘gl.umbc.edu’ in the remote host. Write your umbc user name then run and give your umbc password.
Discover which shell you are using using the following command
ps -p $$
PID TTY TIME CMD 536902 pts/12 00:00:00 bash
PID TTY TIME CMD
3886339 pts/43 00:00:00 tcsh
Edit script to setup shell environment
For tcsh: Open the .cshrc file in your favorite editor. Example: nano ~/.cshrc
For bash: Open the .bashrc file in your favorite editor. Example: nano ~/.bashrc
alias scripts
Typically bash aliases are placed in a separate file lke ~/.bash_aliases
, but this tutorial was not based on the assume that your account is set up to call this file. If you know better, place your aliases in the .bash_alias file
Add the aliases to your startup script
echo "Setting iverilog and gtkwave aliases for CMPE212 .cshrc" alias iverilog=/afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/iverilog alias vvp=/afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/vvp
echo "Setting iverilog and gtkwave aliases for CMPE212 from .bashrc" alias iverilog /afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/iverilog alias vvp /afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/vvp
Save the file and exit (you can use Ctrl+s and then Crtl+x)
Log out and log back in and verify that the script edits were successful
You should see a message like this:
Setting iverilog and gtkwave aliases for CMPE212 ...
Verify that Verilog is installed
Use the following command:
which iverilog
If installed correctly, the path to the program will be shown
/afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/iverilog
iverilog: aliased to /afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/iverilog
Typing the alias
commend will show both aliases
alias iverilog='/afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/iverilog' alias vvp='/afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/vvp'
alias iverilog /afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/iverilog alias vvp /afs/umbc.edu/users/r/o/robucci/pub/iverilog/bin/vvp
Finally display the syntax help
iverilog -help
Usage: iverilog [-EiSuvV] [-B base] [-c cmdfile|-f cmdfile]
[-g1995|-g2001|-g2005|-g2005-sv|-g2009|-g2012] [-g<feature>]
[-D macro[=defn]] [-I includedir]
[-M [mode=]depfile] [-m module]
[-N file] [-o filename] [-p flag=value]
[-s topmodule] [-t target] [-T min|typ|max]
[-W class] [-y dir] [-Y suf] [-l file] source_file(s)
See the man page for details.
Installing on Linux
If installing tools on Linux on personal computer, just install the package iverilog
. In this case the ages will also be available. This also works in the Windows Subsystem for Linux.
Download gtkwave-3.3.100-bin-win32 from the below link extract the zip file to any location:
https://sourceforge.net/projects/gtkwave/files/
Go to the bin folder of the gtkwave and then run the gtkwave.exe.
Now you can see the main window of the program the same as the picture:
To see the waveform of a simulated design:
Installing on Linux
If installing tools on Linux on personal computer, just install the package gtkwave
. If installing on Windows Subsystem for Linux, you’ll also need an x11 server such as https://sourceforge.net/projects/vcxsrv/ and you’ll need to set the DISPLAY variable correctly
For the following circuit, create an alternative implementation using DeMorgan’s Laws, in the same manor as the example. Fill the blanks area and finally depict the NAND-only version implemented of the circuit and complete the Truth Table for both implementations.
1. Function : |
---|
2. Complement both side: | = |
---|
3. Apply De Morgan rule: |
---|
4. Final NAND-only gate : |
---|
Finally, draw the schematic form of the NAND-only gate of the circuit:
Last, fill in the following truth table for both implementations.
Inputs | Output | Output | ||||||
---|---|---|---|---|---|---|---|---|
A | B | C | x | y | F | u | v | F |
Use Verilog to describe both circuits. Create a testbench to demonstrate functionality.
Test the circuit with and without delays. View the results in the waveform viewer.
Capture/save the waveform display as well as the simulation console outputs.