Introduction To Verilog: What Is A Hardware Schematic ?
Introduction To Verilog: What Is A Hardware Schematic ?
Introduction to Verilog
A digital element such as a flip-flop can be represented with combinational gates like NAND and NOR. The
functionality of a flip-flop is achieved by the connection of a certain set of gates in a particular manner. How
the gates have to be connected is usually figured out by solving K-map from the truth table. The truth table
is nothing but a table that tells us what inputs combine together to give what values of output. Shown in the
image below is an electronic circuit that represents a D-flip flop and the corresponding truth table. The
output q becomes 1 only when rstn and d are both having a value of 1.
A hardware schematic is a diagram that shows how the combinational gates should be connected to achieve
a particular hardware functionality. In this case, it is the set of NAND gates connected like shown towards
the left in the image above. However, if we know what values of inputs contribute to make the output have a
value of 1, then we can essentially hide the internal details of the connections and encapsulate it into a
black-box. This block provides us with certain inputs and outputs that is similar to the hardware schematic
made up of combinational gates.
https://www.chipverify.com/verilog/verilog-introduction 1/5
9/3/2020 Introduction to Verilog
It will be easier if we can describe how this block should behave and then let software tools convert that
behavior into actual hardware schematic. The language that describes hardware functionality is called
Verilog, and is classified as a Hardware Description Language.
An important question comes to mind : how do we know whether the behavior described in Verilog
accurately reflects the intended behavior of the design ?
What is verification ?
This is checked by different methods and is collectively called as verification. The most common and widely
practiced method of verification is circuit simulation. There are software tools to understand how a hardware
described in Verilog should behave and provide various input stimuli to the design model. The output of the
design is then checked against expected values to see if the design is functionally correct.
All simulations are performed by EDA (Electronic Design Automation) software tools and the Verilog design
RTL is placed inside an entity called as testbench. Within the testbench, various tests provide different
stimuli to the design. Such a testbench is shown in the image below.
https://www.chipverify.com/verilog/verilog-introduction 2/5
9/3/2020 Introduction to Verilog
All behavior code should be described within the keywords module and endmodule . Rest of the design
code would mostly follow the given template.
[list_of_input_ports]
[list_of_output_ports]
[declaration_of_other_signals]
[other_module_instantiations_if_required]
[behavioral_code_for_this_module]
endmodule
Example
The code shown below describes the behavior of a D type flip-flop. The first few lines declare a
new module called dff and define the input and output ports. The only other signal used in this design
is q and is declared next. Since this is a simple design, it does not depend on any other module and hence
there are no module instantiations. The always block describes how the hardware should behave during
certain events and hence is behavioral code.
https://www.chipverify.com/verilog/verilog-introduction 3/5
9/3/2020 Introduction to Verilog
module dff ( input d, // Inputs to the design should start with "inp
rstn,
clk,
output q); // Outputs of the design should start with "out
always @ (posedge clk) begin // This block is executed at the positive edge
if (!rstn) // At the posedge, if rstn is 0 then q should g
q <= 0;
else
q <= d; // At the posedge, if rstn is 1 then q should g
end
endmodule // End of module
Testbench code
The testbench is the Verilog container module that allows us to drive the design with different inputs and
monitor its outputs for expected behavior. In the example shown below, we have instantiated the flop design
illustrated above and connected it with testbench signals denoted by tb_* . These testbench signals are then
assigned certain values and are eventually driven as inputs to the design.
https://www.chipverify.com/verilog/verilog-introduction 4/5
9/3/2020 Introduction to Verilog
module tb;
https://www.chipverify.com/verilog/verilog-introduction 5/5