Beruflich Dokumente
Kultur Dokumente
NAME________________
REG# ________________
Verilog
• Describes complex designs (millions of gates)
• Synthesis is implementation of design into actual hardware. Synthesis is one of the foremost in
back end steps where by synthesizing is nothing but converting VHDL or VERILOG description
to a set of components(as in FPGA'S)to fit into the target technology. Basically the synthesis
tools convert the design description into equations or components.
• Synthesis tools take the Verilog as input and attempt to create the circuit described by the
Verilog.
Modules
The Module Concept:
Data Types
Nets
• Nets are physical connections between devices.
Registers
• Register type is denoted by reg
• Implicit storage-unless variable of this type is modified it retains previously assigned value.
Variable Declarations
Hardware description
• reg a;
• wire b;
• wire [3:0] c;
• Easiest to model and code and most difficult to design for complex circuits.
• Verilog has built in gate level primitives NAND. NOR, AND, OR, XOR, NOT and some others.
module andoperation(out,in1,in2);
output out;
input in1,in2;
endmodule
Data Flow Modeling in Verilog
Introduction
Dataflow modeling provides a powerful way to implement a design. Verilog allows a design processes
data rather than instantiation of individual gates. Dataflow modeling has become a popular design
approach as logic synthesis tools have become sophisticated.
Operands in Verilog
Operators in Verilog
Continuous Assignment
• Use keyword “assign”.
module and(out,in1,in2);
output out;
input in1,in2;
assign out=in1&in2;
end module
Procedural Blocks
Verilog behavioral code is inside procedure blocks, but there is an exception: some behavioral code also
exist outside procedure blocks.
There are two types of procedural blocks in Verilog:
• initial: initial blocks execute only once at time zero (start execution at time zero).
• always: always blocks loop to execute over and over again; in other words, as the name suggests,
it executes always.
Initial Block
• All statements inside an initial statement constitute and initial block.
• An initial block starts at time 0, executes exactly once during a simulation, and then does not
execute again.
• If there are multiple blocks, each block starts to execute concurrently at time 0.
• Multiple behavioral statements must be grouped; typically using the keywords begin and end.
module initial_example();
reg clk,reset,enable,data;
initial begin
clk = 0;
reset = 0;
enable = 0;
data = 0;
Always Block end
• All behavioral statementsendmodule
inside an always statement constitute an always block.
• The always statements starts at time 0 and executes the statements in the always block
continuously in a looping fashion.
• This statement is used to model a block of activity that is repeated continuously in a digital
circuit.
module always_example();
reg clk,reset,enable,q_in,data;
Non-Blocking statements
Non-blocking assignments are executed in parallel. Since the execution of next statement
is not blocked due to execution of current statement, they are called nonblocking
statement. Assignments are made with "<=" symbol. Example a <= b;
Creation of Project
Write the project name, directory and HDL and click next
Select the categories according to figure and click next then click on Finish
Creating Source file: right click on Project name __>select new source file
Select ‘Verilog module’ and give file name and click next new window will open just click next
and then finish
Now project and source file is created and it is ready to write Verilog code.
Select test bench file and double click on “simulate behavioral Model”
s1 S0 Y
0 0 A
0 1 B
1 0 C
1 1 D
Inputs 4 X1
Output
MUX
Select
Equation
y=As1s2+Bs1s2+Cs1s2+Ds1s2
a) Gate Level Modeling
Verilog code
module gatelevel_mux_4x1(y,a,b,c,d,s1,s2);
input a,b,c,d,s1,s2;
output y;
wire x2,x1,w1,w2,w3,w4,w5;
not n1(x2,s1);
not n2(x1,s2);
and a1(w1,a,x1,x2);
and a2(w2,b,s1,x1);
and a3(w3,c,s2,x2);
and a4(w4,d,s2,s1);
or o1(w5,w1,w2,w3);
or o2(y,w5,w4);
endmodule
Test bench
module gatelevel_mux_4x1_TB;
// Inputs
reg a;
reg b;
reg c;
reg d;
reg s1;
reg s2;
// Outputs
wire y;
initial begin
// Initialize Inputs
a = 1;
b = 1;
c = 1;
d = 1;
s1 = 0;
s2 = 0;
end
endmodule
Simulation
Test bench
module dataflow_mux_4x1_TB;
// Inputs
reg a;
reg b;
reg c;
reg d;
reg s1;
reg s2;
// Outputs
wire y;
initial begin
// Initialize Inputs
a = 1;
b = 1;
c = 1;
d = 1;
s1 = 0;
s2 = 0;
End
endmodule
Simulation
c) Behavioral Modeling
Verilog code
module bahavioural_mux_4x1(y,a,b,c,d,s1,s2);
input a,b,c,d,s1,s2;
output reg y;
always @ (a,b,c,d,s1,s2);
case({s1,s2})
2'b00 : y=a;
2'b01 : y=b;
2'b10 : y=c;
2'b11 : y=d;
default : y=z;
endcase
end
endmodule
Test bench
module dataflow_mux_4x1_TB;
// Inputs
reg a;
reg b;
reg c;
reg d;
reg s1;
reg s2;
// Outputs
wire y;
initial begin
// Initialize Inputs
a = 0;
b = 0;
// Wait 100 ns for global reset to finish
#100;
a = 0;
b = 1;
// Wait 100 ns for global reset to finish
#100;
a = 1;
b = 0;
Simulation