ECE111 Advanced Digital Design Project Winter 2009: Introduction To Verilog Hardware Description Language
ECE111 Advanced Digital Design Project Winter 2009: Introduction To Verilog Hardware Description Language
What Is It?
Hardware description language
a (sort of programming) language allows designer to describe behavior of a design in text rather than schematic
First created by Phil Moore in 1983 at Gateway Design Automation (acquired by Cadence in 1989) Advantages of Verilog (over VHDL):
Syntax based on C (VHDL based on ADA) Easier to learn & use, less stringent, loosely typed More compact code Switch-level modeling All signals are initialized to unknow that mimics the real hardware well.
Logic synthesis
Translate synthesizable RTL code to a netlist of predefined circuit elements that is
functionally equivalent to RTL Meeting design constraints (timing, area, power)
Synthesizable code: a subset of verilog language that can be understood by synthesis tools Standard cell library: collection of pre-defined circuit elements (mostly logic gates), technology& process-specific
input a_one, a_two; // by default a signal's number of bits is 1 input c_in; // declaration of module ports output s; output c_out; wire s; // declare wires
assign s = a_one ^ a_two ^ c_in; // continuous signal assignment wire c_out = (a_one & a_two) | (a_one & c_in) | (a_two & c_in); endmodule
Structural description
Structural description
Basic Stuff
Comments:
single-line: // multi-line: /**/
Flow controls
if/else, case, wait, repeat, for, while
Assignments
Continuous:
assign a = b + c;
Can not use both on the same target Combinational vs. sequential Sensitivity list of an always block
an event timing control that controls when all statements in the procedural block will start to be evaluated.
Data Types
Register:
reg, integer, time, real, realtime. A register data type must be used when the signal is on the left-hand side of a procedural assignment does not necessarily mean a register
Net:
Sequential Logics
Described using an always block: wire clk, rst_n; reg [3:0] q; wire [3:0] d; // A DFF with negative edge triggered asynchronous reset always @ (posedge clk or negedge rst_n) begin if (~rst_n) q<= 3b000; // The first if will be translated to a reset pin. else d[3:0] q[3:0] begin q <= d; DFF // more code here clk end end rst_n Tip: Use blocking assignment (=) in non-sequential always block and non-blocking assignment (<=) in sequential always block
Think hardware!
Concurrency always @ (posedge clk or negedge rst_n) if (~rst_n) begin a <= 1b1; b <= 1b0; end else begin b <= a; c <= b; end
Testbench
Verification
Behavioral verilog code written to verify design Will not be part of your chip Does not to be synthesizable
Simulation in ModelSim
Running ModelSim
Command lines Using do files
Debugging in ModelSim
A Few Tips
Think of hardware when writing RTL Understand concurrency Write proper combinational procedural assignments to avoid latches Sensitivity list: all signals (wires, regs) on the RHS of =; Fully describe the behaviors of all signals: if/else: always have an else; case: always use default clause; Properly use sequential process always reset a FF: async reset vs. sync reset signals can not appear in multiple sequential process Assignments Use blocking assignments (=) in combinational procedural assignments Use non-blocking assignments (<=) in sequential procedural assignments Only use wire/reg data type wire: signals assigned using continuous assignment; port connections; reg: signals assigned using procedural assignments (either comb. or seq.) Be careful when using for loops (actually, avoid using for loops) One module in one file, module name same as file name Use lower-case for signals, upper-case ONLY for parameters
Resources
Books
The Verilog Hardware Description Language by Donald E. Thomas, Philip R. Moorby
Kluwer Academic, June 1996, ISBN: 0792397231
Links
On-line manual: http://www.see.ed.ac.uk/~gerard/Teach/Verilog/manual/index.html Quick reference guide: http://www.sutherland-hdl.com/online_ref_guide/vlog_ref_top.html An introductory article: http://www.see.ed.ac.uk/~gerard/VLSI/verilog.ps Google it!