Unit I - Verilog - New
Unit I - Verilog - New
Introduction
• Verilog HDL is a general purpose HDL that is easy
to learn and use.
• Syntax is similar to the C programming language.
• It allows different levels of abstraction to be
mixed in the same model.(switch, gates, RTL or
behavioral code)
• Most popular logic synthesis tools support
verilog HDL.
• This is a case sensitive language.
• It has built in gate level and switch level
primitives.
VHDL & VERILOG
module ha_df(sum,carry,a,b);
input a,b;
output sum,carry;
assign sum=a^b;
assign carry=a&b;
endmodule
Half Adder – Structural Modeling
Full Adder – Structural Modeling
Full Adder using Half Adder
module fa_ha(sum,carryout,p,q,carryin);
input p,q,carryin;
output sum,carryout;
wire s,co1,co2;
ha_df ha1(s,co1,p,q);
ha_df ha2(sum,co2,s,carryin);
or o1(carryout,co1,co2);
endmodule
4-bit Ripple Carry Adder using FA
Operator Types & Symbols
Operator Types & Symbols
Arithmetic Operators
• Binary Operators
- multiply(*),divide(/),add(+),subtract(-),
power(**)and modulus(%)
• Unary Operators
- + and – can also work as unary operators.
eg -4 –negative 4
+5 –positive 5
Logical Operators
53
System Tasks
• Display tasks
– $display : Displays the entire list at the time when
statement is encountered
– $monitor : Whenever there is a change in any argument,
displays the entire list at end of time step
• Simulation Control Task
– $finish : makes the simulator to exit
– $stop : suspends the simulation
• Time
– $time: gives the simulation
54
Loop Statements
• Loop Statements
– Repeat
– While
– For
• Repeat Loop
– Example:
repeat (Count)
sum = sum + 5;
– If condition is a x or z it is treated as 0
55
Loop Statements (cont.)
• While Loop
– Example:
while (Count < 10) begin
sum = sum + 5;
Count = Count +1;
end
– If condition is a x or z it is treated as 0
• For Loop
– Example:
for (Count = 0; Count < 10; Count = Count + 1) begin
sum = sum + 5;
end
56
Loop Statements (cont.)
Forever Loop:
57
Data Types
• Net Types: Physical Connection between structural
elements
• Register Type: Represents an abstract storage element.
• Default Values
– Net Types : z
– Register Type : x
• Behavioral Modeling
– Can use only reg data type (within initial and
always constructs)
– Cannot use wire data type
60
Memories
• An array of registers
reg [ msb : lsb ] memory1 [ upper : lower ];
• Example
reg [ 0 : 3 ] mem [ 0 : 63 ];
// An array of 64 4-bit registers
reg mem [ 0 : 4 ];
// An array of 5 1-bit registers
61
Switch Level Modeling
62
Switch Level Modeling
63
Switch Level Modeling
64
Switch Level Modeling
module my_nor(out,a,b);
output out;
Input a,b;
supply1 vdd;
supply0 gnd;
wire c;
pmos p1(c,vdd,b);
pmos p2(out,c,a);
nmos n1(out,gnd,a);
nmos n2(out,gnd,b);
endmodule
65
Switch Level Modeling
66
Switch Level Modeling
67