CSE 460 Experiment 2 (Verilog 1)
CSE 460 Experiment 2 (Verilog 1)
Example 1: Construct the following circuit using Verilog HDL and verify the output through
timing diagram.
Truth Table
x3 x2 x1 f
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1
Structural Behavioral Behavioral
Representation: Representation1: Representation2:
module module module expt1 (f, x1,
expt1(f,x1,x2,x3); expt1(f,x1,x2,x3); x2, x3);
input x1,x2,x3; input x1,x2,x3; input x1, x2, x3;
output f; output f; output f;
and (g,x1,x2); assign f=(x1 & x2) | reg f;
not (y,x2); (~x2 & x3); always @(x1 or x2 or
and (h,y,x3); endmodule x3)
or (f,g,h); if (x2 == 1)
endmodule f = x1;
else
f = x3;
endmodule
Example 2: Construct the following circuit using Verilog HDL and verify the output through
timing diagram.
Truth Table:
x4 x3 x2 x1 f
0 0 0 0 1
0 0 0 1 1
0 0 1 0 0
0 0 1 1 0
0 1 0 0 0
0 1 0 1 1
0 1 1 0 0
0 1 1 1 1
1 0 0 0 1
1 0 0 1 1
1 0 1 0 1
1 0 1 1 1
1 1 0 0 0
1 1 0 1 1
1 1 1 0 1
1 1 1 1 1
Class Work: Design a 1-bit full adder and using the 1-bit full adder modules, design a 4-bit full
adder using Verilog HDL.
module fulladd(S,Cout,A,B,Cin);
input A, B, Cin;
output S, Cout;
assign S = A ^ B ^ Cin;
assign Cout = (A & B) | (Cin & (A ^ B));
endmodule
Another approach:
1. Open Quartus.
2. Click File->New Project Wizard->Next
3. Fill out the following:
What is the working directory for this project? – Browse->Create a folder in desktop->Select the
folder
What is the name of the project->Type a name and remember it(Say “expt1”). Same name is
going to be copied to the next box automatically.
Press next.
4. Press next
5. Select Device Family: FLEX10KE and press next.
6. Fill out the following in all three pair of boxes:
Tool name: Custom
Format: Verilog HDL
Press Next->Finish
7. File->New->Verilog HDL File->OK
8. Write the code and save it with the same name as that given in expt1 3 with extension of .v
(Example: expt1.v)
9. File->New->Vector Waveform File
10. Right click on Name->Insert->Insert Node or BUS
11. Click Node Finder.
Filter: Pins: all
Look in: Filename (Example expt1.v)
Click list->Click “>>” -> OK -> OK
12. Right click on each input->Value->Clock and set up the clocks.
13. Save with the same filename as the .v file (Example: expt1.vwf)
14. Assignment->Settings->Simulator Settings
Simulation Mode: Functional
Click OK.
15. Processing-> Generate Functional Simulation Netlist
16. Processing-> Start Simulation
Home Work:
1. Design a 4 to 1 MUX using Verilog HDL and verify using timing diagram.
2. Design a priority encoder (3>1>0>2) using Verilog HDL and verify using timing diagram.
3. Design a 4 to 2 Decoder using Verilog HDL and verify using timing diagram.
4. Design a 4 bit adder-subtractor using Verilog HDL and verify using timing diagram.