Presentation is loading. Please wait.

Presentation is loading. Please wait.

ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Basic Concept of HDL Lecturer: Huai-Yi Hsu ( 許槐益 ) Date: 2004.03.05.

Similar presentations


Presentation on theme: "ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Basic Concept of HDL Lecturer: Huai-Yi Hsu ( 許槐益 ) Date: 2004.03.05."— Presentation transcript:

1 ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Basic Concept of HDL Lecturer: Huai-Yi Hsu ( 許槐益 ) Date: 2004.03.05

2 Graduate Institute of Electronics Engineering, NTU pp. 2 Huai-Yi HsuBasic Concept 2004.03.05 Outline  Hierarchical Design Methodology  Basic Concept of Verilog HDL  Switch Level Modeling  Gate Level Modeling  Simulation & Verification Tools

3 Graduate Institute of Electronics Engineering, NTU pp. 3 Huai-Yi HsuBasic Concept 2004.03.05 What is Verilog HDL ?  Hardware Description Language  Mixed level modeling  Behavioral  Algorithmic ( like high level language)  Register transfer (Synthesizable)  Structural  Gate (AND, OR ……)  Switch (PMOS, NOMS, JFET ……)  Single language for design and simulation  Built-in primitives and logic functions  User-defined primitives  Built-in data types  High-level programming constructs

4 Graduate Institute of Electronics Engineering, NTU pp. 4 Huai-Yi HsuBasic Concept 2004.03.05 Hierarchical Modeling Concept  Understand top-down and bottom-up design methodologies  Explain differences between modules and module instances in Verilog  Describe four levels of abstraction

5 Graduate Institute of Electronics Engineering, NTU pp. 5 Huai-Yi HsuBasic Concept 2004.03.05 Top-down Design Methodology  We define the top-level block and identify the sub-blocks necessary to build the top-level block.  We further subdivide the sub-blocks until we come to leaf cells, which are the cells that cannot further be divided. Top level block sub block 2 sub block 3 sub block 4 sub block 1 leaf cell leaf cell leaf cell leaf cell leaf cell leaf cell leaf cell leaf cell

6 Graduate Institute of Electronics Engineering, NTU pp. 6 Huai-Yi HsuBasic Concept 2004.03.05 Bottom-up Design Methodology  We first identify the building block that are available to us.  We build bigger cells, using these building blocks.  These cells are then used for higher-level blocks until we build the top-level block in the design. Top level block macro cell 2 macro cell 3 macro cell 4 macro cell 1 leaf cell leaf cell leaf cell leaf cell leaf cell leaf cell leaf cell leaf cell

7 Graduate Institute of Electronics Engineering, NTU pp. 7 Huai-Yi HsuBasic Concept 2004.03.05 Example: 16-bit Adder [HW]

8 Graduate Institute of Electronics Engineering, NTU pp. 8 Huai-Yi HsuBasic Concept 2004.03.05 Design Encapsulation  Encapsulate structural and functional details in a module  Encapsulation makes the model available for instantiation in other modules module ( ); // Structural part // Behavior part endmodule

9 Graduate Institute of Electronics Engineering, NTU pp. 9 Huai-Yi HsuBasic Concept 2004.03.05 Instances  A module provides a template from which you can create actual objects.  When a module is invoked, Verilog creates a unique object from the template.  Each object has its own name, variables, parameters and I/O interface.

10 Graduate Institute of Electronics Engineering, NTU pp. 10 Huai-Yi HsuBasic Concept 2004.03.05 Hierarchical Design Example  Model complex structural detail by instantiating modules within modules

11 Graduate Institute of Electronics Engineering, NTU pp. 11 Huai-Yi HsuBasic Concept 2004.03.05 Verilog Language Rules  Verilog is a case sensitive language (with a few exceptions)  Identifiers (space-free sequence of symbols)  upper and lower case letters from the alphabet  digits (0, 1,..., 9)  underscore ( _ )  $ symbol (only for system tasks and functions)  Max length of 1024 symbols  Terminate lines with semicolon ;  Single line comments:  // A single-line comment goes here  Multi-line comments:  /* Do not /* nest multi-line comments*/ like this */

12 Graduate Institute of Electronics Engineering, NTU pp. 12 Huai-Yi HsuBasic Concept 2004.03.05 Language Conventions  Case-sensitivity  Verilog is case-sensitive.  Some simulators are case-insensitive  Advice: - Don ’ t use case-sensitive feature!  Keywords are lower case  Different names must be used for different items within the same scope  Identifier alphabet:  Upper and lower case alphabeticals  decimal digits  underscore

13 Graduate Institute of Electronics Engineering, NTU pp. 13 Huai-Yi HsuBasic Concept 2004.03.05 Language Conventions (cont’d)  Maximum of 1024 characters in identifier  First character not a digit  Statement terminated by ;  Free format within statement except for within quotes  Comments:  All characters after // in a line are treated as a comment  Multi-line comments begin with /* and end with */  Compiler directives begin with // synopsys  Built-in system tasks or functions begin with $  Strings enclosed in double quotes and must be on a single line

14 Graduate Institute of Electronics Engineering, NTU pp. 14 Huai-Yi HsuBasic Concept 2004.03.05 Verilog Basis Cell  Verilog Basis Components  parameter declarations  nets or reg declarations  port declarations  Continuous assignments  Module instantiations  Gate instantiations  Function definitions  always blocks  task statements

15 Graduate Institute of Electronics Engineering, NTU pp. 15 Huai-Yi HsuBasic Concept 2004.03.05 Port Declaration  Three port types  Input port  input a;  Output port  output b;  Bi-direction port  inout c; net inputoutput inout reg or net module

16 Graduate Institute of Electronics Engineering, NTU pp. 16 Huai-Yi HsuBasic Concept 2004.03.05 Data Types  nets are further divided into several net types  wire, wand, wor, tri, triand, trior, supply0, supply1  registers - stores a logic value - reg  integer - supports computation 32-bits signed  time - stores time 64-bit unsigned  real - stores values as real numbers  realtime - stores time values as real numbers  event – an event data type  Wires and registers can be bits, vectors, and arrays

17 Graduate Institute of Electronics Engineering, NTU pp. 17 Huai-Yi HsuBasic Concept 2004.03.05 Integer, Real, & Time  integer counter;  initial counter = -1;  real delta;  initial delta = 4e10;  time sim_time;  initial sim_time = $time;

18 Graduate Institute of Electronics Engineering, NTU pp. 18 Huai-Yi HsuBasic Concept 2004.03.05 Data Types  Nets ( wire or reg (in combinational always block)  Connects between structural elements  Must be continuously driven by  Continuous assignment (assign)  Module or gate instantiation (output ports)  Default initial value for a wire is “Z”  Registers ( reg (in sequential always block) )  Represent abstract data storage elements  Updated at an edge trigger event and holds its value until another edge trigger event happens  Default initial value for a wire is “X”

19 Graduate Institute of Electronics Engineering, NTU pp. 19 Huai-Yi HsuBasic Concept 2004.03.05 Net Types  The most common and important net types  wire and tri  for standard interconnection wires  supply 1 and supply 0  Other wire types  wand, wor, triand, and trior  for multiple drivers that are wired-anded and wired-ored  tri0 and tri1  pull down and pull up  trireg  for net with capacitive storage  If all drivers at z, previous value is retained

20 Graduate Institute of Electronics Engineering, NTU pp. 20 Huai-Yi HsuBasic Concept 2004.03.05 Register Types  reg  any size, unsigned  integer (not synthesizable)  integet a,b; // declaration  32-bit signed (2’s complement)  time (not synthesizable)  64-bit unsigned, behaves like a 64-bit reg  $display(“At %t, value=%d”,$time,val_now)  real, realtime (not synthesizable)  real c,d; //declaration  64-bit real number  Defaults to an initial value of 0

21 Graduate Institute of Electronics Engineering, NTU pp. 21 Huai-Yi HsuBasic Concept 2004.03.05 Wire & Reg  wire(wand, wor, tri)  Physical wires in a circuit  Cannot assign a value to a wire within a function or a begin…..end block  A wire does not store its value, it must be driven by  by connecting the wire to the output of a gate or module  by assigning a value to the wire in a continuous assignment  An un-driven wire defaults to a value of Z (high impedance).  Input, output, inout port declaration -- wire data type (default)

22 Graduate Institute of Electronics Engineering, NTU pp. 22 Huai-Yi HsuBasic Concept 2004.03.05 Wire & Reg  reg  A variable in Verilog  Use of “ reg ” data type is not exactly synthesized to a really register.  Use of wire & reg  When use “ wire ”  usually use “ assign ” and “ assign ” does not appear in “ always ” block  When use “ reg ”  only use “ a=b ”, always appear in “ always ” block module test(a,b,c,d); input a,b; output c,d; reg d; assign c=a; always @(b) d=b; endmodule module test(a,b,c,d); input a,b; output c,d; reg d; assign c=a; always @(b) d=b; endmodule

23 Graduate Institute of Electronics Engineering, NTU pp. 23 Huai-Yi HsuBasic Concept 2004.03.05 Wired Logic  The family of nets includes the types wand and wor  A wand net type resolves multiple driver as wired-and logic  A wor net type resolves multiple drivers as wired-or logic  The family of nets includes supply0 and supply1  supply0 has a fixed logic value of 0 to model a ground connection  supply1 has a fixed logic value of 1 to model a power connection

24 Graduate Institute of Electronics Engineering, NTU pp. 24 Huai-Yi HsuBasic Concept 2004.03.05 Data Type - Examples rega;// scalar register wandb;// scalar net of type “wand” reg[3:0]c;// 4-bit register tri[7:0]bus;// tri-state 8-bit bus reg[1:4]d;// 4-bit trireg (small)store;// specify logical strength (rare used) 01XZ 00XX0 1X1X1 XXXXX Z01XZ 01XZ 00000 101X1 X0XXX Z01XZ 01XZ 001X0 11111 XX1XX Z01XZ wire/tri truth tablewand/triandwor/trior

25 Graduate Institute of Electronics Engineering, NTU pp. 25 Huai-Yi HsuBasic Concept 2004.03.05 Vector  wire and reg can be defined vector, default is 1bit  vector is multi-bits element  Format: [High#:Low#] or [Low#:High#]  Using range specify part signals wire a;// scalar net variable, default wire [7:0]bus;// 8-bit bus reg clock;// scalar register, default reg [0:23] addr;// Vector register, virtual address 24 bits wide bus[7]// bit #7 of vector bus bus[2:0]// Three least significant bits of vector bus // using bus[0:2] is illegal because the significant bit should // always be on the left of a range specification addr[0:1]// Two most significant bits of vector addr

26 Graduate Institute of Electronics Engineering, NTU pp. 26 Huai-Yi HsuBasic Concept 2004.03.05 Array  Arrays are allowed in Verilog for reg, integer, time, and vector register data types.  Multidimensional array are not permitted in Verilog. integercount[0:7];// An array of 8 count variables regbool[31:0];// Array of 32 one-bit Boolean register variables timechk_ptr[1:100];// Array of 100 time checkpoint variables reg [4:0]port_id[0:7];// Array of 8 port_id, each port_id is 5 bits wide integermatrix[4:0][4:0]// Illegal declaration count[5]// 5 th element of array of count variables chk_ptr[100]// 100 th time check point value port_id[3]// 3 rd element of port_id array. This is a 5-bit value

27 Graduate Institute of Electronics Engineering, NTU pp. 27 Huai-Yi HsuBasic Concept 2004.03.05 Memories  In digital simulation, one often needs to model register files, RAMs, and ROMs.  Memories are modeled in Verilog simply as an array of registers.  Each element of the array is known as a word, each word can be one or more bits.  It is important to differentiate between  n 1-bit registers  One n-bit register reg mem1bit[0:1023];// Memory mem1bit with 1K 1-bit words reg [7:0] mem1byte[0:1023];// Memory mem1byte with 1K 8-bit words mem1bit[255]// Fetches 1 bit word whose address is 255 Mem1byte[511]// Fetches 1 byte word whose address is 511

28 Graduate Institute of Electronics Engineering, NTU pp. 28 Huai-Yi HsuBasic Concept 2004.03.05 Strings  String: a sequence of 8-bits ASCII values  Special characters \n  newline\t  tab character \\  \ character\”  “ character %  % character\abc  ASCII code module string; reg [8*14:1] strvar; initial begin strvar = “Hello World”;// stored as 000000486561…726c64 strvar = “Hello World!!”;// stored as 00486561…726c642121 end endmodule

29 Graduate Institute of Electronics Engineering, NTU pp. 29 Huai-Yi HsuBasic Concept 2004.03.05 Four-valued Logic  Verilog ’ s nets and registers hold four-valued data  0 represent a logic zero or false condition  1 represent a logic zero or false condition  z  Output of an undriven tri-state driver – high-impedance value  Models case where nothing is setting a wire ’ s value  x  Models when the simulator can ’ t decide the value – uninitialized or unknown logic value Initial state of registers When a wire is being driven to 0 and 1 simultaneously Output of a gate with z inputs

30 Graduate Institute of Electronics Engineering, NTU pp. 30 Huai-Yi HsuBasic Concept 2004.03.05 Logic System  Four values: 0, 1, x or X, z or Z // Not case sensitive here  The logic value x denotes an unknown (ambiguous) value  The logic value z denotes a high impedance  Primitives have built-in logic  Simulators describe 4-value logic (see Appendix A in text) 01XZ00000101XXX0XXXZ0XXX01XZ00000101XXX0XXXZ0XXX

31 Graduate Institute of Electronics Engineering, NTU pp. 31 Huai-Yi HsuBasic Concept 2004.03.05 Resolution of Contention Between Drivers  The value on a wire with multiple drivers in contention may be x

32 Graduate Institute of Electronics Engineering, NTU pp. 32 Huai-Yi HsuBasic Concept 2004.03.05 Logic Strength Levels  Types of strengths  Charge strength: trireg (large>medium>small)  Drive strength: (supply>strong>pull>weak)  Syntax  Strength level ; trireg(large)[1:4]#5c1; weakeststrongest highz small medium weak large pull strong supply

33 Graduate Institute of Electronics Engineering, NTU pp. 33 Huai-Yi HsuBasic Concept 2004.03.05 Number Representation  Format: ’  - decimal specification of number of bits  default is unsized and machine-dependent but at least 32 bits  - ' followed by arithmetic base of number  - decimal - default base if no given  - hexadecimal  - octal  - binary  - value given in base of  _ can be used for reading clarity  If first character of sized, binary number 0, 1, x or z, will extend 0, 1, x or z (defined later!)

34 Graduate Institute of Electronics Engineering, NTU pp. 34 Huai-Yi HsuBasic Concept 2004.03.05 Number Representation  Examples:  6 ’ b010_111gives 010111  8 ’ b0110 gives 00000110  4 ’ bx01gives xx01  16 ’ H3ABgives 0000001110101011  24gives 0 … 0011000  5 ’ O36gives 11100  16 ’ Hxgives xxxxxxxxxxxxxxxx  8 ’ hzgives zzzzzzzz

35 Graduate Institute of Electronics Engineering, NTU pp. 35 Huai-Yi HsuBasic Concept 2004.03.05 Net Concatenations  A easy way to group nets RepresentationMeanings {cout, sum} {b[7:4],c[3:0]}{b[7], b[6], b[5], b[4], c[3], c[2], c[1], c[0]} {a,b[3:1],c,2’b10}{a, b[3], b[2], b[1], c, 1’b1, 1’b0} {4{2‘b01}}8‘b01010101 {{8{byte[7]}},byte}Sign extension

36 Graduate Institute of Electronics Engineering, NTU pp. 36 Huai-Yi HsuBasic Concept 2004.03.05 Parameter Declaration  Parameters are not variables, they are constants.  Typically parameters are used to specify delays and width of variables  Examples module var_mux(out, i0, i1, sel); parameter width = 2, delay = 1; output [width-1:0] out; input [width-1:0] i0, i1; input sel; assign #delay out = sel ? I1 : i0; endmodule If sel = 1, then i1 will be assigned to out; If sel = 0, then i0 will be assigned to out;

37 Graduate Institute of Electronics Engineering, NTU pp. 37 Huai-Yi HsuBasic Concept 2004.03.05 Overriding the Values of Parameters  Module instance parameter value assignment.  Cannot skip any parameter assignment even you do not want to reassign it. module top; …… wire [1:0] a_out, a0, a1; wire [3:0] b_out, b0, b1; wire [2:0] c_out, c0, c1; var_mux U0(a_out, a0, a1, sel); var_mux #(4,2)U1(b_out, b0, b1, sel); var_mux #(3, )U2(c_out, c0, c1, sel); …… endmodule The order of assign of parameters follows the order of declaration of Parameters in the module. You cannot skip the delay parameter assignment.

38 Graduate Institute of Electronics Engineering, NTU pp. 38 Huai-Yi HsuBasic Concept 2004.03.05 Overriding the Values of Parameters  You can use defparam to group all parameter value override assignment in one module. module top; …… wire [1:0] a_out, a0, a1; wire [3:0] b_out, b0, b1; wire [2:0] c_out, c0, c1; var_mux U0(a_out, a0, a1, sel); var_mux U1(b_out, b0, b1, sel); var_mux U2(c_out, c0, c1, sel); …… endmodule module annotate; defparam top.U0.width = 2; top.U0.delay = 1; top.U1.width = 4; top.U1.delay = 2; top.U2.width = 3; top.U2.delay = 1; endmodule

39 Graduate Institute of Electronics Engineering, NTU pp. 39 Huai-Yi HsuBasic Concept 2004.03.05 Gate and Switch Level Modeling  Primitives: bottom level of the hierarchy  Verilog Gate Level Primitives  User-defined Primitives (UDP): described by truth table  Conventional modules  Behavior statements  Structural statements  Switch Level Modeling (using transistors)  Delay Specification  Specify gate delay  Specify module path delay

40 Graduate Institute of Electronics Engineering, NTU pp. 40 Huai-Yi HsuBasic Concept 2004.03.05 Verilog Built-in Primitives and nand or nor xor xnor buf not bufif0 bufif1 notif0 notif1 nmos pmos cmos tran tranif0 tranif1 rnmos rpmos rcmos rtran rtranif0 rtranif1 pullup pulldown Ideal MOS switch Resistive gates

41 Graduate Institute of Electronics Engineering, NTU pp. 41 Huai-Yi HsuBasic Concept 2004.03.05 MOS Switches  Two types of MOS switches can be defined with the keywords, nmos and pmos  nmos is used to model NMOS transistors  nmos n1(out, data, control);  pmos is used to model PMOS transistors  pmos p1(out, data, control); data out control NMOS transistorPMOS transistor C D 01XZ 0Z0LL 1Z1HH XZXXX ZZZZZ C D 01XZ 00ZLL 11ZHH XXZXX ZZZZZ H: stands for 1 or z L: stands for 0 or z

42 Graduate Institute of Electronics Engineering, NTU pp. 42 Huai-Yi HsuBasic Concept 2004.03.05 CMOS Switches  CMOS switches are declared with the keyword cmos.  A cmos device can be modeled with a nmos and a pmos device.  cmos c1(out, data, ncontrol, pcontrol);  The cmos gate is essentially a combination of two gates: one nmos and one pmos.  nmos n1(out, data, ncontrol);  pmos p1(out, data, pcontrol); data out ncontrol pcontrol CMOS

43 Graduate Institute of Electronics Engineering, NTU pp. 43 Huai-Yi HsuBasic Concept 2004.03.05 Bidirectional Switches  NMOS, PMOS, CMOS gates conduct from drain to source.  It is important to have devices that conduct in both directions.  In such cases, signals on either side of the device can be the driver signal.  Bidirectional switches are typically used to provide isolation between buses or signals.  tran t1(inout1, inout2);  tranif0t2(inout1, inout2, control);  tranif1 t3(inout1, inout2, control); trantranif1tranif0 inout1inout2inout1inout2 control inout1inout2 control

44 Graduate Institute of Electronics Engineering, NTU pp. 44 Huai-Yi HsuBasic Concept 2004.03.05 Power and Ground  The power (Vdd, logic 1) and Ground (Vss, logic 0) sources are needed when transistor-level circuits are designed.  Supply1 are equivalent to Vdd in circuits and place a logical 1 on a net.  Supply0 are equivalent to ground or Vss in circuits and place a logical 0 on a net. supply1vdd; supply0gnd; assign a = vdd;// connect a to vdd assign b = gnd;// connect b to gnd

45 Graduate Institute of Electronics Engineering, NTU pp. 45 Huai-Yi HsuBasic Concept 2004.03.05 Resistive Switches  Resistive switches have the same syntax as regular switches.  Resistive devices have a high source-to-drain impedance. Regular switches have a low source-to-drain impedance.  Resistive switches reduce signal strengths when signals pass through. Regular switches retain strength levels of signals from input to output. Input StrengthOutput Strength SupplyPull StrongPull Weak Medium LargeMedium Small High

46 Graduate Institute of Electronics Engineering, NTU pp. 46 Huai-Yi HsuBasic Concept 2004.03.05 Switches Example a b out ba gnd pwr // Define our own nor gate: nor_sw module nor_sw (out, a, b); output out; input a, b; // internal wires wire c; // set up power and ground lines supply1 pwr; supply0 gnd; //instantiate pmos switches pmos (c, pwr, b); pmos (out, c, a); //instantiate nmos switches nmos (out, gnd, a); nmos (out, gnd, b); endmodule

47 Graduate Institute of Electronics Engineering, NTU pp. 47 Huai-Yi HsuBasic Concept 2004.03.05 Primitives & UDP  Primitives are simple modules  Verilog build-in primitive gate  not, buf:  Variable outputs, single input (last port)  and, or, xor, nand, nor, xnor:  Single outputs (first port), variable inputs  User defined primitive (UDP)  Single output (first port), variable inputs  The function is specified by a truth table  Z state is not allowed

48 Graduate Institute of Electronics Engineering, NTU pp. 48 Huai-Yi HsuBasic Concept 2004.03.05 Truth-Tables Models and User- Defined Primitives  Built-in primitives are for simple combinational logic gates and CMOS transistors  Primitives are memory efficient and simulate fast (good for ASIC libraries)  User-defined primitives accommodate combinational and sequential logic  Scalar output and multiple scalar inputs  Arrange inputs columns of truth table in same order as ports  Put output in last column, separated by :  Use a UDP like a built-in primitive  Table is searched top to bottom until match is found  z may not be used in table (z in simulation is treated as x)  No match results in propagation of x  See web site for more details

49 Graduate Institute of Electronics Engineering, NTU pp. 49 Huai-Yi HsuBasic Concept 2004.03.05 Example UDP primitive mux_prim (mux_out, select, a, b); output mux_out; input select, a, b; table // select ab: mux_out 000:0 ; // Order of table columns = port order of inputs 001:0 ; // One output, multiple inputs, no inout 00x:0 ; // Only 0, 1, x on input and output 010:1 ; // A z input in simulation is treated as x 011:1 ; // by the simulator 01x:1 ; // Last column is the output // select ab: mux_out 100:0 ; 110:0 ; 1x0:0 ; 101:1 ; 111:1 ; 1x1:1 ; x 00:0 ; // Reduces pessimism x 11:1 ; endtable// Note: Combinations not explicitly specified will drive ‘ x ’ endprimitive// under simulation.

50 Graduate Institute of Electronics Engineering, NTU pp. 50 Huai-Yi HsuBasic Concept 2004.03.05 Alternative model table // Shorthand notation: // ? represents iteration of the table entry over the values 0,1,x. // i.e., don't care on the input select ab: mux_out 00?:0 ; // ? = 0, 1, x shorthand notation. 01?:1 ; 1?0:0 ; 1?1:1 ; ?00:0 ; ?11:1 ; endtable

51 Graduate Institute of Electronics Engineering, NTU pp. 51 Huai-Yi HsuBasic Concept 2004.03.05 UDPS FOR Sequential Logic  Output is viewed as next state  Insert a column for the present state truth  Declare output to have type reg

52 Graduate Institute of Electronics Engineering, NTU pp. 52 Huai-Yi HsuBasic Concept 2004.03.05 Example: Transparent Latch primitive latch_rp (q_out, enable, data); output q_out; input enable, data; reg q_out; table // enable data state q_out/next_state 11:?:1 ; 10:?:0 ; 0?:?:- ; // Above entries do not deal with enable = x. // Ignore event on enable when data = state: x0:0:- ; x1:1:- ; // Note: The table entry '-' denotes no change of the output. endtable endprimitive

53 Graduate Institute of Electronics Engineering, NTU pp. 53 Huai-Yi HsuBasic Concept 2004.03.05 Example: D-Type Flip-Flop  Notation for rising edge transition: (01), (0x), (x1)  Notation for falling edge transition: (10), 1x), (x0) primitive d_prim1 (q_out, clock, data); output q_out; input clock, data; reg q_out; table // clk data : state : q_out/next_state (01)0 : ? :0 ; // Rising clock edge (01)1 : ? :1 ; (0?)1 : 1 :1 ; (?0)? : ? : - ; // Falling or steady clock edge ? (??) : ? :- ; // Steady clock, ignore data transitions endtable endprimitive

54 Graduate Institute of Electronics Engineering, NTU pp. 54 Huai-Yi HsuBasic Concept 2004.03.05 Example: JK-Type Flip-Flop  Level-sensitive and edge-sensitive behavior can be mixed in a UDP  Place level-sensitive behavior a the top of the table J-K functionality: - preset and clear override clock - no change if j=0, k=0 - drive to 1 if j=1, k=0 - drive to 0 if j=0, k=1 - toggle if j=1, k=1

55 Graduate Institute of Electronics Engineering, NTU pp. 55 Huai-Yi HsuBasic Concept 2004.03.05 primitive jk_prim (q_out, clk, j, k, preset, clear); output q_out; input clk, j, k, preset, clear; reg q_out; table // clkj k pre clr stateq_out/next_state // Preset Logic ???01:?:1 ; ?? ? * 1 : 1 : 1 ; // Clear Logic ? ? ? 1 0 : ?:0 ; ? ? ? 1 * :0:0 ; // Normal Clocking // clk j k pre clr stateq_out/next_state r00 00 : 0:1 ; r 0 0 1 1 :?:- ; r 0 1 1 1 : ?:0 ; r 1 0 1 1 : ? :1 ; r 1 1 1 1 : 0: 1 ; r 1 1 1 1 :1:0 ; f????:?:- ; // j and k cases // clk j k pre clr stateq_out/next_state b*???:? : - ; b?*??:? : - ; // Reduced pessimism p0011:?: - ; p 0?1?: 0 : - ; p?0?1: 1 : - ; (?0)????: ? : - ; (1x)0011: ? : - ; (1x)0? 1 ? : 0 : - ; (1x)?0 ? 1 : 1 : - ; x *0 ? 1 : 1 : - ; x0 * 1 ? : 0 : - ; endtable endprimitive Note: * denotes any transition, and is equivalent to (??)

56 ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Timing and Delays

57 Graduate Institute of Electronics Engineering, NTU pp. 57 Huai-Yi HsuBasic Concept 2004.03.05 Timing and Delay  Functional verification of hardware is used to verify functionality of the designed circuit.  However, blocks in real hardware have delays associated with the logic elements and paths in them.  Therefore, we must also check whether the circuit meets the timing requirements, given delay specifications for the blocks.

58 Graduate Institute of Electronics Engineering, NTU pp. 58 Huai-Yi HsuBasic Concept 2004.03.05 Delay Specification in Primitives  Delay specification defines the propagation delay of that primitive gate. not #10 (out,in);

59 Graduate Institute of Electronics Engineering, NTU pp. 59 Huai-Yi HsuBasic Concept 2004.03.05 Delay Specification in Primitives  Verilog supports (rise, fall, turn-off) delay specification.

60 Graduate Institute of Electronics Engineering, NTU pp. 60 Huai-Yi HsuBasic Concept 2004.03.05 Delay Specification in Primitives  All delay specification in Verilog can be specified as (minimum : typical : maximum) delay  Examples  (min:typ:max) delay specification of all transition  or #(3.2:4.0:6.3) U0(out, in1, in2);  (min:typ:max) delay specification of RISE transition and FALL transition  nand #(1.0:1.2:1.5,2.3:3.5:4.7) U1(out, in1, in2);  (min:typ:max) delay specification of RISE transition, FALL transition, and turn-off transition  bufif1 #(2.5:3:3.4,2:3:3.5,5:7:8) U2(out,in,ctrl);

61 Graduate Institute of Electronics Engineering, NTU pp. 61 Huai-Yi HsuBasic Concept 2004.03.05 Types of Delay Models  Distributed Delay  Specified on a per element basic  Delay value are assigned to individual in the circuit a b c d e f out #5 #7 #4 module and4(out, a, b, c, d); … … and #5 a1(e, a, b); and #7 a2(f, c, d); and #4 a3(out, e, f); endmodule

62 Graduate Institute of Electronics Engineering, NTU pp. 62 Huai-Yi HsuBasic Concept 2004.03.05 Types of Delay Models  Lumped Delay  Specified on a per module basic  They can be specified as a single delay on the output gate of the module  The cumulative delay of all paths is lumped at one location a b c d e f out #11 module and4(out, a, b, c, d); … … and a1(e, a, b); and a2(f, c, d); and #11a3(out, e, f); endmodule

63 Graduate Institute of Electronics Engineering, NTU pp. 63 Huai-Yi HsuBasic Concept 2004.03.05 Types of Delay Models  Pin-to-Pin Delay  Delays are assigned individually to paths from each input to each output.  Delays can be separately specified for each input/output path. a b c d e f out Path a-e-out, delay = 9 Path b-e-out, delay =9 Path c-f-out, delay = 11 Path d-f-out, delay = 11

64 Graduate Institute of Electronics Engineering, NTU pp. 64 Huai-Yi HsuBasic Concept 2004.03.05 Path Delay Modeling  Specify blocks  Assign pin-to-pin timing delay across module path  Set up timing checks in the circuits  Define specparam constanys module and4(out, a, b, c, d); … … // specify block with path delay statements specify (a => out) = 9; (b => out) = 9; (c => out) = 11; (d => out) = 11; endspecify // gate instantiations and a1(e, a, b); and a2(f, c, d); and a3(out, e, f); endmodule

65 Graduate Institute of Electronics Engineering, NTU pp. 65 Huai-Yi HsuBasic Concept 2004.03.05 Parallel/Full Connection (a[0] => out[0]) = 9; (a[1] => out[1]) = 9; (a[2] => out[2]) = 9; (a[3] => out[3]) = 9; (a => out) = 9; (b => out) = 9; (c => out) = 11; (d => out) = 11; (a,b *> out) = 9; (c,d *> out) = 11;

66 Graduate Institute of Electronics Engineering, NTU pp. 66 Huai-Yi HsuBasic Concept 2004.03.05 Specparam Statement  Special parameters can be declared for use inside a specify block.  Instead of using hardcoded delay numbers to specify pin-tp-pin delays module and4(out, a, b, c, d); … … // specify block with path delay statements specify specparam delay1 = 9; specparam delay2 = 11; (a,b *> out) = delay1; (c,d *> out) = delay2; endspecify … … endmodule

67 Graduate Institute of Electronics Engineering, NTU pp. 67 Huai-Yi HsuBasic Concept 2004.03.05 Rise, Fall, and Turn-off Delays  Pin-to-pin timing can also be expressed in more detail by specifying rise, fall, and turn-off delay values // specify one delay statements specparam t_delay = 9; (clk => q) = t_delay; // specify two delay statements specparam t_rise = 9; specparam t_fall = 13; (clk => q) = (t_rise, t_fall); // specify three delay statements specparam t_rise = 9; specparam t_fall = 13; specparam t_turnoff = 11; (clk => q) = (t_rise, t_fall, t_turnoff); // specify six delay statements specparam t_01= 9, t_10 = 13; specparam t_0z = 11, t_z1 = 9; specparam t_1z = 11, t_z0 = 13; (clk => q) = (t_01, t_10, t_0z, t_z1, t_1z, t_z0); // specify twelve delay statements specparam t_01= 9, t_10 = 13; specparam t_0z = 11, t_z1 = 9; specparam t_1z = 11, t_z0 = 13; specparam t_0x= 9, t_x1 = 13; specparam t_1x = 11, t_x0 = 9; specparam t_xz = 11, t_zx = 13; (clk => q) = (t_01, t_10, t_0z, t_z1, t_1z, t_z0, t_0x, t_x1, t_1x, t_x0, t_xz, t_zx);

68 Graduate Institute of Electronics Engineering, NTU pp. 68 Huai-Yi HsuBasic Concept 2004.03.05 Min, Max, and Typical Delays  Min, max, and typical delay value were discussed earlier for gates  Can also be specified for pin-to-pin delays. // specify two delay statements specparam t_rise = 8:9:10; specparam t_fall = 12:13:14; specparam t_turnoff = 10:11:12 (clk => q) = (t_rise, t_fall, t_turnoff);

69 Graduate Institute of Electronics Engineering, NTU pp. 69 Huai-Yi HsuBasic Concept 2004.03.05 Timing Checks  setup and hold checks setup time hold time clock data specify $setup(data, posedge clock, 3); endspecify specify $hold(posedge clock, data, 5); endspecify

70 Graduate Institute of Electronics Engineering, NTU pp. 70 Huai-Yi HsuBasic Concept 2004.03.05 Timing Checks  Width check width of the pulse clock specify $width(posedge clock, 6); endspecify

71 Graduate Institute of Electronics Engineering, NTU pp. 71 Huai-Yi HsuBasic Concept 2004.03.05 Structural Models  Verilog primitives encapsulate pre-defined functionality of common logic gates  The counterpart of a schematic is a structural model composed of Verilog primitives  Model structural detail by instantiating and connecting primitives

72 Graduate Institute of Electronics Engineering, NTU pp. 72 Huai-Yi HsuBasic Concept 2004.03.05 Structural Connectivity  Wires in Verilog establish connectivity between primitives and/or modules  Data type: nets (Example: wire)  The logic value of a wire (net) is determined dynamically during simulation by what is connected to the wire.  An undeclared identifier is treated by default as a wire  Use nets to establish structural connectivity  Port connection by name  Add_half_0_delay M1(.b(b),.c_out(w2),.a(a),.sum(w1));  Port connection by place  Add_half_0_delay M1(w1, w2, a, b);

73 ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Simulation & Verification

74 Graduate Institute of Electronics Engineering, NTU pp. 74 Huai-Yi HsuBasic Concept 2004.03.05 Test Methodology  Task: systematically verify the functionality of a model.  Approaches: Simulation and/or formal verification  Simulation: (1) detect syntax violations in source code (2) simulate behavior (3) monitor results

75 Graduate Institute of Electronics Engineering, NTU pp. 75 Huai-Yi HsuBasic Concept 2004.03.05 Components of a Simulation Stimulus Block Design Block Output Results Input Patterns Dummy Top Block Design Block Stimulus Block Output Results Input Patterns

76 Graduate Institute of Electronics Engineering, NTU pp. 76 Huai-Yi HsuBasic Concept 2004.03.05 Event-Driven Simulation  A change in the value of a signal (variable) during simulation is referred to as an event  Spice-like analog simulation is impractical for VLSI circuits  Event-driven simulators update logic values only when signals change

77 Graduate Institute of Electronics Engineering, NTU pp. 77 Huai-Yi HsuBasic Concept 2004.03.05 Inertial Delay Note: The falling edge of x_in1 occurs before the response to the rising edge occurs.

78 Graduate Institute of Electronics Engineering, NTU pp. 78 Huai-Yi HsuBasic Concept 2004.03.05 Testbench Template  Consider the following template as a guide for simple testbenches: module t_DUTB_name ();// substitute the name of the UUT reg … ;// Declaration of register variables for primary inputs of the UUT wire … ;// Declaration of primary outputs of the UUT parametertime_out = // Provide a value UUT_name M1_instance_name ( UUT ports go here); initial $monitor ( ); // Specification of signals to be monitored and displayed as text initial #time_out $stop;// (Also $finish) Stopwatch to assure termination of simulation initial // Develop one or more behaviors for pattern generation and/or // error detection begin // Behavioral statements generating waveforms // to the input ports, and comments documenting // the test. Use the full repertoire of behavioral // constructs for loops and conditionals. end endmodule

79 Graduate Institute of Electronics Engineering, NTU pp. 79 Huai-Yi HsuBasic Concept 2004.03.05 Example: Testbench module t_Add_half(); wire sum, c_out; reg a, b; // Storage containers for stimulus waveforms Add_half_0_delay M1 (sum, c_out, a, b);//UUT initial begin// Time Out #100 $finish;// Stopwatch end initial begin// Stimulus patterns #10 a = 0; b = 0;// Statements execute in sequence #10 b = 1; #10 a = 1; #10 b = 0; end endmodule

80 Graduate Institute of Electronics Engineering, NTU pp. 80 Huai-Yi HsuBasic Concept 2004.03.05 Behaviors for Abstract Models  Verilog has three types of behaviors for composing abstract models of functionality  Continuous assignment (Keyword: assign) -- later  Single pass behavior (Keyword: initial) -- Note: only use in testbenches  Cyclic behavior (Keyword: always) -- later  Single pass and cyclic behaviors execute procedural statements like a programming language  The procedural statements execute sequentially  A single pass behavior expires after the last statement executes  A cyclic behavior begins executing again after the last statement executes

81 Graduate Institute of Electronics Engineering, NTU pp. 81 Huai-Yi HsuBasic Concept 2004.03.05 Signal Generators  Use cyclic behaviors to describe stimulus generators  Statements in a behavior may be grouped in begin … end blocks  Execution begins at t sim = 0  # delay control operator temporarily suspends execution of a behavior  The operator = denotes procedural assignment (also called blocking assignment)

82 Graduate Institute of Electronics Engineering, NTU pp. 82 Huai-Yi HsuBasic Concept 2004.03.05 Simulation Results

83 Graduate Institute of Electronics Engineering, NTU pp. 83 Huai-Yi HsuBasic Concept 2004.03.05 Propagation Delay  Gate propagation delay specifies the time between an input change and the resulting output change  Transport delay describes the time-of-flight of a signal transition  Verilog uses an inertial delay model for gates and transport delay for nets  Inertial delay suppresses short pulses (width less than the propdelay value)

84 Graduate Institute of Electronics Engineering, NTU pp. 84 Huai-Yi HsuBasic Concept 2004.03.05 Example: Propagation Delay  Unit-delay simulation reveals the chain of events module Add_full (sum, c_out, a, b, c_in); output sum, c_out; input a, b, c_in; wire w1, w2, w3; Add_half M1 (w1, w2, a, b); Add_half M2 (sum, w3, w1, c_in); or #1 M3 (c_out, w2, w3); endmodule module Add_half (sum, c_out, a, b); output sum, c_out; input a, b; xor #1 M1 (sum, a, b); // single delay value format and #1 M2 (c_out, a, b);// others are possible endmodule

85 Graduate Institute of Electronics Engineering, NTU pp. 85 Huai-Yi HsuBasic Concept 2004.03.05 Simulation with delay

86 Graduate Institute of Electronics Engineering, NTU pp. 86 Huai-Yi HsuBasic Concept 2004.03.05 Simulation with Standard Cells `timescale 1ns / 1 ps // time scale directive for units and resolution module Add_full_ASIC (sum, c_out, a, b, c_in); output sum, c_out; input a, b, c_in; wire w1, w2, w3; wire c_out_bar; Add_half_ASIC M1 (w1, w2, a, b); Add_half_ASIC M2 (sum, w3, w1, c_in); norf201 M3 (c_out_bar, w2, w3); invf101 M4 (c_out, c_out_bar); endmodule module Add_half_ASIC (sum, c_out, a, b); output sum, c_out; input a, b; wire c_out_bar; xorf201 M1 (sum, a, b); // Standard cells - down load from web page nanf201 M2 (c_out_bar, a, b); invf101 M3 (c_out, c_out_bar); endmodule

87 Graduate Institute of Electronics Engineering, NTU pp. 87 Huai-Yi HsuBasic Concept 2004.03.05 System Tasks  Displaying information  $display(“ID of the port is %b”, port_id);  ID of the port is 00101  Monitoring information  $monitor($time, “Value of signals clk = %b rst = %b”, clk, rst);  0 Value of signals clk = 0 rst = 1  5 Value of signals clk = 1 rst = 1  10 Value of signals clk = 0 rst = 0  Stopping and finishing in a simulation  $stop;// provided to stop during a simulation  $finish;// terminates the simulator

88 Graduate Institute of Electronics Engineering, NTU pp. 88 Huai-Yi HsuBasic Concept 2004.03.05 Compiler Directives  The `define directive is used to define text macros  The `include directive allows you to include entire contents of a Verilog source file  `timescale / `define WORD_SIZE 32// Used as `WORD_SIZE in the code `define STOP $stop;// define an alias `define WORD_REG reg[31:0]// define a 32-bit register `include header.v `include submodule.v `timescale 1 ns / 10 ps `timescale 100 ns / 1ns

89 Graduate Institute of Electronics Engineering, NTU pp. 89 Huai-Yi HsuBasic Concept 2004.03.05 Summary  Understand switch level modeling  Understand gate level modeling  Specify timing delay  Function simulation  Timing simulation

90 Graduate Institute of Electronics Engineering, NTU pp. 90 Huai-Yi HsuBasic Concept 2004.03.05 Homework #1  Try to build your design by using gate-level  Check your syntax!! And record your miss errors!!  Writing your testbench to verify your design  Simulate and Verify your design  Optional:  Simulation with delay information on gate-level  Design example:  16-bits Adder, 4-bits multiplier (booth)  Counter, Clock generator (OSC)


Download ppt "ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Basic Concept of HDL Lecturer: Huai-Yi Hsu ( 許槐益 ) Date: 2004.03.05."

Similar presentations


Ads by Google