Seer Verilog
Seer Verilog
Seer Verilog
Page 1 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
The Verilog Language
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Level of Abstraction
Verilog supports a design at 4
different levels of abstraction.
Behavioral Highest
• Behavioral Level Abstraction
Level
• Dataflow Level
• Gate Level Dataflow
• Switch level
Register Transfer Level (RTL)
• A combination of both Gate level
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Levels of Abstraction (Cont..)
Behavioral Level :- Used to model the behavior of a design
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Structural Modeling
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Behavioral Modeling
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Modules
A module is the basic building block in Verilog.
Elements are grouped into modules to provide the common
functionality that is used at many places in the design.
A module provides the necessary functionality to the higher-level
block through its port interface (inputs and outputs).
In Verilog a module is declared by the keyword module.
A corresponding keyword endmodule must appear at the end of
the module definition.
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Modules (contd…)
Modules CANNOT be nested.
Rather, one module can instantiate another module.
Module instantiation is like creating actual objects (Instances)
from the common template (module definition).
Each instance of module has all the properties of that module.
Module instantiations are used for:
• connecting different parts of the designs, and
• connecting test bench to the design.
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Design Hierarchy
One top level module
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Structure of module
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Structure of module (contd…)
The <module name> is an identifier that uniquely names the
module.
The <port list> is a list of input, inout and output ports which are
used to connect to other modules.
The <declares> section specifies data objects as registers, memories
and wires as wells as procedural constructs such as functions and
tasks.
The <statements> may be initial constructs, always constructs,
continuous assignments or instances of modules.
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Basic Languages Concepts
Page 1 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Lexical Conventions
Keywords
• In lower case
• Case sensitive
• Delimit tokens, space
Numbers
• [<sign>] [<size>] <base> <num>
• e.g.- 549, „h8ff, „o765, 4‟b11,3‟b10x, -4‟b11
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Verilog Comments
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Verilog Number Specifications
Two representations: sized & unsized
Format:<number of bits><base><number>
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Verilog Number Specifications
(contd…)
Negative numbers: put minus sign before size.
• Format: -<size><base><number>
• <size> field is always +ve.
• Represented by 2‟s complement internally.
Often _ (Underscore) is used in between digits of the number
for readability.
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Verilog Number Specifications
(contd…)
Verilog numbers may have x or z as part of numbers.
x ? unknown value, z ? high impedance value
A question mark „?‟ can also be used as an alternative to „z‟.
reg [5:0] Num;
Reg [31:0] data;
..
Num = 6‟b_100x; // Num = 6‟b00100x
data = 32‟bx; // 32 bit no with all x bits
Num = „bz01; // Num = 6‟bzzzz01
Num = „b11??1; // Num = 6‟b011zz1
data = 32„h_x5f3_2693; // data = 32‟hX5f32693
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Data Types
reg: Register
wire: Wire/net
Possible Values: 0, 1, x, z
Default: 1-bit (Scalar)
reg A, B, C;
Vector:
reg[0:7] A;
reg[7:0] B;
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Data Types contd…
Integer & Real Data Types
• Declaration
integer i, k;
real r;
Use as registers (inside procedures)
i = 1;
r = 2.9;
k = r; // k is rounded to 3
Integers are not initialized in Verilog!!
Reals are initialized to 0.0
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Nets
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Registers
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Integers
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Real Numbers
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Time & Realtime Data types
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Four-valued Data
Verilog‟s nets and registers hold four-valued data
0, 1
Obvious
Z
Output of an undriven tri-state driver
Models case where nothing is setting a wire‟s value
X
Models when the simulator can‟t decide the value
Initial state of registers
When a wire is being driven to 0 and 1 simultaneously
Output of a gate with Z inputs
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Modules and Instances
Basic structure of a Verilog module:
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Instantiating a Module
Instances of
look like
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Initial and Always
Run until they encounter a delay
initial begin
#10 a = 1; b = 0;
#10 a = 0; b = 1;
end
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Blocking vs. Nonblocking
Fundamental problem:
• In a synchronous system, all flip-flops sample
simultaneously
• In Verilog, always @(posed clk) blocks run in some
undefined sequence
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
RTL Coding Guidelines
Page 1 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Basic Goal
Develop RTL code simple and regular
• Easier to design, code, verify and synthesize
Consistent coding style, naming conventions and
structure
Easy to understand
• Comments, meaningful names and constants or
parameters instead of hard coded numbers.
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Naming Convention
Lowercase letters for all signal, variable and port names
e.g. wire clk, rst;
Uppercase letters for names of constants and user-defined
types
e.g. `define MY_BUS_LENGTH 32
Meaningful names
• For a RAM address bus, ram_addr instead of ra
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Naming Convention (2)
Short but descriptive
• During elaboration, the synthesis tool
concatenates the names
clk for clock signal,
• More than one clock? Clk1, clk2 or
clk_interface…
Active low signals: postfix with „_n‟
rst for reset signals, if active low rst_n
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Naming Convention (3)
When describing multibit buses, use a consistent ordering
of bits
• For Verilog : use (x:0) or (0:x)
The same or similar names for ports and signals that are
connected
(e.g. a => a or a => a_int)
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Naming Convention (4)
Other naming conventions
*_r: output of a register
*_a: asynchronous signal
*_z: tristate internal signal
*_pn: signal used in the nth phase
*_nxt: data before being registered into a register
with the same name
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Include Header
// -----------------------------------------------------------
// Copyright Kacper Technologies Pvt.Ltd
// File Name : $RCSfile: DESIGN.v,v $
// Module Name : SHIFTER
// Project : UPF_TC
// Revision : $Revision: 1.3 $
// Date : $Date: 2010/1/27 12:44:52 $
// Module description : Shifter
// ----------------------------------------------------------
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Comment
Placed logically, near the code that describe
Brief, concise and explanatory
Separate line for each HDL statements
Keep the line length to 72 characters or less
• always @(a or b or c or d or e or f or g or h or i)
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Indentation
Improve the readability of continued code lines and nested loops, tab
of 4 is recommended
if(a)
if(b)
if(c)
…
Port ordering
module my_module(clk,rst, …);
{ // Inputs:
clk, // comment for each
rst, // …
…
// Outputs;
…
}
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Port Map
Use named association rather than
positional association
P_module my_module(
.clk(clk),
.rst(rst),
…
);
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Use Function
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Use Loop and Array
module my_module( … );
…
reg [31:0] reg_file[15:0];
integer tmp;
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Meaningful Label
Helpful for debug
• Label each process block
<name>_PROC
• Label each instance U_<name>
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Portability
Create code technology-independent, compatible with
various simulation tools and easily translatable between
Verilog and VHDL
Constants instead of hard-coded value
`define MY_BUS_SIZE 8
reg [ `MY_BUS_SIZE-1:0] my_out_bus;
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Technology Independent
Avoid embedding dc_shell scripts
exception : the synthesis directives to turn
synthesis on and off must be embedded in the code
in the appropriate places.
Use Design Ware Foundation Libraries
Avoid instantiating gates
If you must use technology-specific gates, then
isolate these gates in a separate module
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Clock and Reset
Simple clocking structure: a single global clock and
positive edge-triggered flops as the only sequential
devices
clk
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Mixed Clock Edges
Avoid!
• Duty cycle of the clock become a critical issue in
timing analysis
• Most scan-based testing methodologies require
separate of positive and negative-edge triggered
flops
If you must use both,
• Model the worst case duty cycle
• Document the assumed duty cycle
• If you must use many, separate them into different
modules
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Clock Buffer
Avoid hand instantiating clock buffers in RTL code.
They are normally inserted after synthesis as part of the
physical design.
Avoid internally generated clocks and reset, all the
registers in the macro should be reset at the same time
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Gated Clock
Avoid coding gated clocks in RTL
• Cannot be use part of a scan chain
• If you must use, keep the clock and/or reset
generation circuitry as a separate module at the
top level of the design or model it using
synchronous load registers
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Infer Register
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Sensitivity List
Specify complete sensitivity list avoid difference
between pre-synthesis and post-synthesis netlist in
combinational blocks
Include clock and reset in sequential blocks.
Avoid unnecessary signals in list.
always @(a)
c=a or b;
a a
a
c
b b b
c c
pre-synthesis Synthesized netlist post-synthesis
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Case Vs if-then-else
A case statement infers a single-level multiplexer, while an if-then-else
one infers a priority-encoder, cascaded combination of multiplexers.
Synopsis directive about case statement case (sel) //synopsis parallel_case
full_case
if-then-else can be useful if you have a late arriving signal
For large multiplexers, case is preferred because faster in cycle-based
simulator
Conditional assignment;
e.g.
assign z1=(sel_a) ? a : b;
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
State Machines
Separate state machine into two processes : combinational
and sequential.
• Poor coding style:
always @(posedge clk)
a<=b+c;
• Recommended coding style:
always @(b or c)
a_nst = b+c;
always @(posedge clk)
a <= a_nst;
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Partition for Synthesis
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Register Output
For each block of a hierarchical design, register all output
signals
• Output drive strengths equal to the drive
strength of the average flip-flop.
• Input delays predictable
Keep related combinational logic together in the same
module
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Different Design Goals
Keep critical path logic in a separate module, optimize the
critical path logic for speed while optimizing the noncritical
path logic for area.
Speed Critical
Optimization Path logic
clk
Area Noncritical
Optimization Path Logic
clk
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Asynchronous Logic
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Partition for Synthesis Runtime
Most important considerations in partition: logic
function, design goals and timing and area
requirements.
Grouping related functions together
Eliminate glue logic at the top level
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved
Conclusion
Page 2 of 2 Copyright 2010., Kacper Technologies Pvt Ltd. All Rights Reserved