0% found this document useful (0 votes)
60 views27 pages

Introduction To Verilog: Sistla Srikanth 15104416, EE

This document provides an introduction to Verilog, including an overview of its modeling styles (structural, dataflow, behavioral), procedural blocks (initial, always), data types, memories, compiler directives, and system tasks. Verilog allows modeling of digital designs at different levels of abstraction through its various modeling styles and supports both combinational and sequential logic.

Uploaded by

Sunil Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views27 pages

Introduction To Verilog: Sistla Srikanth 15104416, EE

This document provides an introduction to Verilog, including an overview of its modeling styles (structural, dataflow, behavioral), procedural blocks (initial, always), data types, memories, compiler directives, and system tasks. Verilog allows modeling of digital designs at different levels of abstraction through its various modeling styles and supports both combinational and sequential logic.

Uploaded by

Sunil Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

INTRODUCTION TO

VERILOG

By
Sistla Srikanth
15104416,EE
Contents
 Introduction
 Verilog modeling styles
 Procedural blocks
 Data types
 Memory introduction
 Compiler directives
 System tasks

2
1. Introduction
 A high-level computer language can model, represent and
simulate digital design
• Hardware concurrency
• Parallel Activity Flow
• Semantics for Signal Value and Time

 Design examples using Verilog HDL


• Intel Pentium, AMD K5, K6, Atheon, ARM7, etc
• Thousands of ASIC designs using Verilog HDL

 Start by creating functional blocks in higher end blocks


 C like syntax

3
Modern Project Methodology

Always
inst1 Synthesis
inst2
inst3

Place and
Route
clb 1
clb 2
Module
 General definition  Example

module module_name ( port_list ); module HalfAdder (A, B, Sum Carry);


port declarations; input A, B;
… output Sum, Carry;
variable declaration; assign Sum = A ^ B;
… //^ denotes XOR
description of behavior assign Carry = A & B;
endmodule // & denotes AND
endmodule

5
2. Verilog modeling Styles
 Structural: Logic is described in terms of Verilog gate
primitives
 Example:
not n1(sel_n, sel);
and a1(sel_b, b, sel_b);
and a2(sel_a, a, sel);
or o1(out, sel_b, sel_a);

b sel_b
sel n1
sel_n
a1

o1 out
a
a2 sel_a

6
Description Styles (cont.)

 Dataflow: Specify output signals in terms of input signals

 Example:
assign out = (sel & a) | (~sel & b);

sel_b
sel sel_n

out
sel_a

7
Description Styles (cont.)

 Behavioral: Algorithmically specify the behavior of the


design

 Example:
if (select == 0) begin
out = b;
end
else if (select == 1) begin
out = a; a Black Box
out
end b 2x1 MUX

sel

8
Dataflow Modeling

 Uses continuous assignment statement


 Format: assign [ delay ] net = expression;
 Example: assign sum = a ^ b;

 Delay: Time duration between assignment from RHS to


LHS

 All continuous assignment statements execute


concurrently

 Order of the statement does not impact the design

9
Dataflow Modeling (cont.)

 Delay can be introduced


 Example: assign #2 sum = a ^ b;
 “#2” indicates 2 time-units
 No delay specified : 0 (default)

 Associate time-unit with physical time


 `timescale time-unit/time-precision
 Example: `timescale 1ns/100 ps

 Timescale
`timescale 1ns/100ps
 1 Time unit = 1 ns
 Time precision is 100ps (0.1 ns)
 10.512ns is interpreted as 10.5ns
10
Dataflow Modeling (cont.)

 Example:

`timescale 1ns/100ps
module HalfAdder (A, B, Sum, Carry);
input A, B;
output Sum, Carry;
assign #3 Sum = A ^ B;
assign #6 Carry = A & B;
endmodule

11
Dataflow Modeling (cont.)

12
Behavioral Modeling

 Example:
module mux_2x1(a, b, sel, out);
input a, a, sel;
output out;
always @(a or b or sel)
begin Sensitivity List
if (sel == 1)
out = a;
else out = b;
end
endmodule

13
Behavioral Modeling (cont.)

 always statement : Sequential Block

 Sequential Block: All statements within the block are


executed sequentially

 When is it executed?
 Occurrence of an event in the sensitivity list
 Event: Change in the logical value

 Statements with a Sequential Block: Procedural


Assignments

 Delay in Procedural Assignments


 Inter-Statement Delay
 Intra-Statement Delay
14
Behavioral Modeling (cont.)

 Inter-Assignment Delay
 Example:
Sum = A ^ B;
#2 Carry = A & B;
 Delayed execution

 Intra-Assignment Delay
 Example:
Sum = A ^ B;
Carry = #2 A & B;
 Delayed assignment

15
3. Procedural Blocks
 Two Procedural Constructs
 initial Statement
 always Statement
 initial Statement : Executes only once
 always Statement : Executes in a loop
 Example:
… …
initial begin always @(A or B) begin
Sum = 0; Sum = A ^ B;
Carry = 0; Carry = A & B;
end end
… …

16
Event Control
 Event Control
 Edge Triggered Event Control
 Level Triggered Event Control

 Edge Triggered Event Control


@ (posedge CLK) //Positive Edge of CLK
Curr_State = Next_state;

 Level Triggered Event Control


@ (A or B) //change in values of A or B
Out = A & B;

17
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

18
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

19
Conditional Statements

 if Statement
 Format:
if (condition)
procedural_statement
else if (condition)
procedural_statement
else
procedural_statement
 Example:
if (Clk)
Q = 0;
else
Q = D;

20
Conditional Statements (cont.)

 Case Statement
 Example 1:
case (X)
2’b00: Y = A + B;
2’b01: Y = A – B;
2’b10: Y = A / B;
endcase
 Example 2:
case (3’b101 << 2)
3’b100: A = B + C;
4’b0100: A = B – C;
5’b10100: A = B / C; //This statement is executed
endcase
21
4. Data Types
 Net Types: Physical Connection between structural
elements

 Register Type: Represents an abstract storage element.

 Default Values
 Net Types : z
 Register Type : x

 Net Types: wire, tri, wor, trior, wand, triand, supply0,


supply1

 Register Types : reg, integer, time, real, realtime

22
Data Types

 Net Type: Wire


wire [ msb : lsb ] wire1, wire2, …

 Example
wire Reset; // A 1-bit wire
wire [6:0] Clear; // A 7-bit wire

 Register Type: Reg


reg [ msb : lsb ] reg1, reg2, …

 Example
reg [ 3: 0 ] cla; // A 4-bit register
reg cla; // A 1-bit register

23
Restrictions on Data Types

 Data Flow and Structural Modeling


 Can use only wire data type
 Cannot use reg data type

 Behavioral Modeling
 Can use only reg data type (within initial and always
constructs)
 Cannot use wire data type

24
5. 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

25
6. Compiler Directives
 `define – (Similar to #define in C) used to define global
parameter
 Example:
`define BUS_WIDTH 16
reg [ `BUS_WIDTH - 1 : 0 ] System_Bus;

 `undef – Removes the previously defined directive


 Example:
`define BUS_WIDTH 16

reg [ `BUS_WIDTH - 1 : 0 ] System_Bus;

`undef BUS_WIDTH

26
7. 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

27

You might also like