Verilog HDL
Verilog HDL
Verilog HDL
EE461 Lab
6
General View of Typical CAD Flow for Design a Circuit
• Synthesis
is the process of transforming a logic design specification into
an implementation. the entered design is synthesized into a circuit that
consists of the logic elements (LEs) provided in the FPGA chip
•
Functional Simulation
the synthesized circuit is tested to verify its functional correctness; this
simulation does not take into account any timing issues
• Fitting
The CAD Fitter tool determines the placement of the LEs defined in the
netlist into the LEs in an actual FPGA chip; it also chooses routing wires in the
chip to make the required connections between specific LEs
Verilog HDL Language 8
• Timing Analysis
Propagation delays along the various paths in the fitted circuit are
analyzed to provide an indication of the expected performance of the
circuit
• Timing Simulation
The fitted circuit is tested to verify both its functional correctness and timing
Interface Body
Interface Body
- Ex :
- module CPU (<port_name> , <port-name> , ..…) ;
- …………………………….
- …………………………… Body part
- endmodule
Port_direction :
is declared as:
- input : for scalar or vector input ports.
- output : for scalar or vector output ports.
- inout : for scalar or vector bi_directional ports.
A X_Gate B
Input ( 4 bits ) Output ( 1 bits )
module X_Gate ( A , B ) ;
input [ 3 : 0 ] A ;
output B ;
……………..
……………..
endmodule
Examples Notes
adder Correct identifier name.
Beginning with a alphabetic.
xor Wrong identifier name.
Because (xor) is keyword.
1adder Wrong identifier name.
Because starting with a number
\reset* Correct identifier name.
Starting with (\) because it’s escapes identifier (
must be followed by white space )
2) Block_comments: ( /* ……………. */ ).
start with slash and asterisk ( /* ) and terminate with
asterisk followed by slash ( */ ). They can extend to
multiple lines.
Structure Description :
Explains the physical makeup of the circuit , detailing gates and the
connection between them , ( Lower level components ) .
Behavioral Description :
Is most advanced and most flexible. It’s also closest to programming
languages because uses sequential statements and allows compound
statement like conditional statement ( if ) , multiple choice ( case ) and
loops.Behavioral style describes a circuit in term of it’s behavior , and
behavioral style supports functions , ( always ) and ( initial ) blocks.
Behavioral Description also referred to an RTL ( Register
Transfer Level ) description.
Gates Commands :
and , or , not , nand , nor , xor , xnor , buf
Internal Signals :
1) Nets : are physical connections between devices There
are many types of nets , but we use wire .
module X_GATE ( A , B , Y ) ;
input A , B ;
output Y ;
Syntax :
Note :
Range is specified as [ msb : lsb ] . Default is one bit wide.
Base Character
Binary b or B
Octal o or O
Decimal d or D
Hexadecimal h or H
Default <base_form> is Decimal.
1) Arithmetic Operators :
+ : Addition.
- : Subtract.
* : Multiply.
/ : Divide.
%: Modulus.
! : Logical Negation.
&& : Logical AND.
|| : Logical OR.
if ( <expression> ) if ( X == 1’ b1 )
begin begin
……< statements > ....... Y=1‘ b0 ;
end end
else else
begin begin
……< statements > ....... Y=X+1;
end end
If (S1 == 0 && S0 == 0)
D =A0;
else if (S1 == 0 && S0 == 1)
D = A1;
else if (S1 == 1 && S0 == 0)
D =A2;
else if (S1 == 1 && S0 == 1)
D =A3;
endmodule
module
mux_4_to_1(A0,A1,A2,A3,S0,S1,D);
input A0,A1,A2,A3,S0,S1;
output D;
case ({S1,S0})
00 : D = A0;
01 : D = A1;
10 : D = A2;
11 : D = A3;
default : D = A0;
endcase
endmodule
module
mux_4_to_1(A0,A1,A2,A3,S,D);
input A0,A1,A2,A3;
Input [1:0]S;
output D;
case (S)
0 : D = A0;
1 : D = A1;
2 : D = A2;
3 : D = A3;
default : D = A0;
endcase
endmodule
Initial Initial
begin fork
#1 A = 0; #1 A = 0;
#3 B = 0; #3 B = 0;
#5 C = 0; #5 C = 0;
end join
Initial Initial
begin fork
#1 A = 0; #1 A = 0;
#3 B = 0; #3 B = 0;
#5 C = 0; #5 C = 0;
end join
always statement can not drive a wire data type, but can
drive reg and integer data type
Verilog HDL Language 55
Examples module dec_2to4(a,e,f);
input [1:0] a ;
Input e ;
module dec_2to4( a,f ); output [3:0] f ;
input [1:0] a ; reg [3:0] f ;
output [3:0] f ; always @ ( a or e )
reg [3:0] f ; begin
If (e==1) begin
always @ ( a ) case(a)
begin 2'b00: f=4'b0001;
case ( a ) 2'b01: f=4'b0010;
2'b00: f=4'b0001; 2'b10: f=4'b0100;
2'b01: f=4'b0010; 2'b11: f=4'b1000;
2'b10: f=4'b0100; endcase
2'b11: f=4'b1000; else
endcase f =4’b1111;
end end
endmodule end
endmodule
Verilog HDL Language 56
Example
endmodule
endmodule
endmodule
THE END