Expt 1
Expt 1
What is Verilog?
● Verilog is a Hardware Description Language and not a software programming language.
● Used to describe the working of digital circuits.
● In programming, execution starts from the main function and proceeds further.
● In HDL, concurrent execution of statements is possible.
● Verilogallowsthedesignofcircuitsatahighlevelofabstraction(behaviorallevel)aswellas
the lower implementation levels (gate level)
● Verilog was developed by Gateway Design Automation in 1986 and waslateracquiredby
Cadence in 1990.
● Designerscandevelopanexecutablefunctionalspecificationthatdescribesthecomponents'
exact behavior.
● Decisions about cost, performance, power, and area can be made earlier.
● Tools that automatically manipulate thedesignforverification,synthesis,optimization,and
bitstream generation are available.
● Verilog allows the designer to mix and match all levels of abstractions in a design.
● Itallowsdesignerstotalkaboutwhatthehardwareshoulddowithoutactuallydesigningthe
hardware itself.
● Building blocks in Verilog:
➔ Module:
Circuit functions are described inside a module.
It starts with a keywordmoduleand ends with a keywordendmodule.
Syntax:
module<module_name> (<inputs, outputs>) ;
……………
<internal_function>
………….
endmodule
➔ Testbench:
Used for testing the defined circuit function inside the module.
Provide random input data/stimulus for verifying the correctness of the circuit.
Define this block separately and do not include it along the module block.
Syntax:
module<testbench_name>;
…………..
endmodule
● Levels of abstraction:
➔ Behavioral/Procedural Level:
Highest level of abstraction.
The design at this level is similar to an algorithm and very similar to ‘C’
programming.
Modules are developed with little consideration of hardware.
Example: Out = (A.B) + (C.D)
moduleexp1(Out, A, B, C, D);
inputA, B, C, D;
outputOut;
regOut;
always@(A or B or C or D)
begin
if(A & B)
Out = 1;
else
Out = #10 (C & D);
end
endmodule
➔ Dataflow/Functional Level:
The design specifies how data flows between registers.
It is useful for designing complex functions that are not realized by gate-level
modeling.
Example: Out = (A.B) + (C.D)
moduleexp1(Out, A, B, C, D);
inputA, B, C,D;
outputOut;
assign#10 out= (A & B) | (C & D);
endmodule
➔ Gate/Structural Level:
Basic level of modeling.
The module is implemented in terms of logic gates(AND,OR,NOT)andtheir
interconnections.
Example: Out = (A.B) + (C.D)
moduleexp1(Out,A, B, C, D);
inputA, B, C,D;
outputOut;
wiretmp1,tmp2;
andu1 (tmp1,A, B);
andu2 (tmp2,C, D);
or#20 (Out, tmp1,tmp2);
endmodule
● Testbench example:
moduletest;
regr1, r2, r3, r4;
wireo;
exp1 e1 (.A(r1), .B(r2), .C(r3), .D(r4), .Out(o));
initial
begin
reg[3:0] i;
for( i = 0; i < 16; i = i + 1)
begin
{ r1, r2, r3, r4 } = i [3:0];
#30$display(“r1r2r3r4 = %b%b%b%b, o = %b”, r1, r2,r3, r4, o);
end
end
endmodule