Verilog

Contents

Verilog HDL Overview

Terminologies

  1. HDL: A text based programming language that is used to model a piece of hardware.
  1. Behavior Modeling: A component is described by its input/output response.
  1. Structural Modeling: A component is described by interconnecting lower-level components/primitives.
  1. Register Transfer Level (RTL) : A type of behavioral modeling, for the purpose of synthesis.
    1. Hardware is implied or inferred.
    1. Synthesizable
  1. Synthesis: Translating HDL to a circuit and then optimizing the represented circuit.
  1. RTL Synthesis: Translating a RTL model of hardware into an optimized technology specific gate level implementation.
RTL Synthesis

Behavior Modelling

Structural Modelling

Typical RTL Synthesis & RTL Simulation Flows

Typical RTL Synthesis & RTL Simulation Flows

Module Structure

Verilog - Basic Modeling Structure

module module_name(port_list);
	port_declaration;
	data_type_declarations;
	circuit_functionality;
	timing specifications;
endmodule

Verilog HDL: Demonstration Example

Verilog HDL: Demonstration Example

Module Declaration

Port types

<port_type> <port_name>;
module full_adder(a, b, cin, sum, cout);
	input a, b, cin;
	output sum, cout;
	
	...
	
endmodule
module adder(a, b, cin, sum, cout);
	input [3:0] a, b; // declares 4-bit input port a, b
	input cin;
	output [3:0] sum; // declares 4-bit output port sum
	output cout;
	wire c0, c1, c2;
	
	...
endmodule
module adder(
	input [3:0] a, b, // declares 4-bit input port a, b
	input cin,
	output [3:0] sum, // declares 4-bit output port sum
	output cout
	);
	wire c0, c1, c2;
	
	...
endmodule

Data Types

Net Data types

TypeDefinition
wireRepresents a node or a connection
triRepresents a tri-state node
supply0, supply1 logic 0; logic 1
<data_type> [MSB:LSB] <signal_name>;
<data_type> [LSB:MSB] <signal_name>;

Variable Data types

reg [MSB:LSB] <signal_name>;
integer count;

Parameters

parameter size = 8;
localparam outsize = 16;
reg [size-1:0] data_a, data_b;
reg [outsize-1:0] out;
module multi_acc
	#(parameter size = 8)
	(..);

Instantiation Formats

<component_name> #<delay> <instace_name> (port_list);

Connecting Module instantiation ports

module half_adder(a, b, sum, cout);
	input a, b;
	output sum, cout;
	
	...
	
endmodule
  1. Positional Association
    1. Port connections defined by the order of the port list in the lower-level module declaration.
    1. Order of the port connections does matter
  1. Explicit Association
    1. Port connections defined by name.
    1. Recommended method
    1. Order of the port connections does not matter.
    .<signal_name>(<port_name>)
module full_adder(a, b, cin, sum, cout);
	input a, b, cin;
	output adder_sum, adder_cout;
	wire c1, c2, s1;
	
	half_adder dut0(a, b, s1, c1); // Positional Association
	half_adder dut1(.a(s1), .b(cin), .sum(adder_sum), .cout(c2)); 
	// Explicit Association
	or dut2(adder_cout, c1, c2); 
	// <basic_gate> <instance_name>(output_ports, input_ports);
endmodule

Requirements for port connection when modules are instantiated

Requirements for port connection when modules are instantiated

Assigning values - Numbers

<size>'<base_format><number>
1. Decimal ('d or 'D) 16'd255 - 16-bit wide decimal number
2. Hexadecimal ('h or 'H) 8'h9a - 8-bit wide hexadecimal number
3. Binary ('b or 'B) 'b1010 - 32-bit wide binary number
4. Octal ('o or 'O) 'o21 - 32-bit wide octal number
5. Signed ('s or 'S) 16'shFA - signed 16-bit hex value 

Numbers

Operators

Arithmetic Operators

Bitwise Operators

Reduction Operators

Relational Operators

Equality Operators

Logical Operators

Shift Operators

Miscellaneous Operators

Operator Precedence