Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction.

Similar presentations


Presentation on theme: "Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction."— Presentation transcript:

1 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction to Verilog Syntax Spring 2007 W. Rhett Davis NC State University with significant material from Paul Franzon, Bill Allen, & Xun Liu

2 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 2 Summary of Last Lecture l Explain the differences between the following terms: » Schematic vs. Block Diagram » Port vs. Net » Symbol vs. Instance » System vs. Module » HDL vs. RTL

3 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 3 Today’s Lecture l Verilog Introduction l Conventions, Identifiers, Numbers, & Operators l Data Types l Modules l Test Benches

4 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 4 History of Verilog l 1984 – Developed by Gateway Design Automation l 1995 – Became an IEEE Standard (IEEE 1364-1995) l 2001 – Revised (IEEE 1364-2001) l 2003 – Accelera released the System Verilog 3.1 specification l We’ll use both the IEEE 1364-1995 and IEEE 1364-2001 versions of the language. (Either will be accepted on your assignments).

5 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 5 Comparison of HDLs l Verilog » Most commonly used HDL in USA » Based on the C programming language » Least verbose » Fastest simulation l VHDL » Used by US Government, Europe, ASIA » Based on the ADA programming language » More general than Verilog l SystemC SystemC » Emerging Standard, used more for Electronic System Level (ESL) Descriptions » C++ class library that mimics VHDL, plus allows greater abstraction » Allows co-simulation of Hardware and Software

6 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 6 Today’s Lecture l Verilog Introduction l Conventions, Identifiers, Numbers, & Operators l Data Types l Modules l Test Benches

7 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 7 Example: Data Selector Route input data to one of two outputs. Specification: When a new data word arrives at the input, the module inspects the state of the most significant bit and routes the data to output A if the bit is true and to B if the bit is false. The last value sent to either output is retained until replaced. Data A-data B-data here new-A new-B A B

8 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 8 Example: Stimulus l How to describe the module? l How to describe the stimulus? Data A-data B-data here new-A new-B A B

9 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 9 Verilog Language Conventions l Case sensitive l Whitespace ignored (except in strings) l Comments (just like C++ and Java) » Single Line: a = b && c; // The rest of this line is a comment » Multi-Line (cannot be nested): /* This is a multiple line comment*/

10 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 10 Identifiers l Can contain » Letters (a-z,A-Z) » Digits (0-9) » Underscore (_) » Dollar-sign ($) l Must start with a letter » Except for weird things like \reset* l Cannot be a keyword (see Sutherland, section 3.0 for a full list)

11 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 11 Operators l Unary - single operand » ~in l Binary - two operands » in1 && in2 l Ternary - three operands » select ? in1 : in2 l Nearly all Verilog statements end with a semicolon (don’t forget it on your homework)

12 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 12 Values l Write the following: » Binary 100111, 6 bits » Hex 7FFE, 16 bits » Decimal 133, 8 bits l Omitting gives an “unsized” value (32 bits) Sized numbers: ’ : specifies number of bits in number (in decimal) : decimal (‘d, ‘D); hexadecimal (‘h, ‘H); binary (‘b, ‘B); octal (‘o, ‘O) : digits (in base format) of the numeric value

13 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 13 Special Values Language conventions: Numbers & Values In addition to normal numeric values, Verilog provides two special values, x and z. x denotes an unknown or undefined value. unknown by the simulator z denotes a “high impedance” value “isolated from from other regions of the circuit by open switches” l Write the following: » 16-bit hex, low order 4 bits unknown » 8-bit binary, high order 2 bits unknown » 8-bit value, all bits high impedance

14 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 14 Physical Meaning of Values Draw a circuit to represent the following values: 0 and 1 x

15 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 15 Physical Meaning of Values Draw a circuit to represent the following values: z

16 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 16 Values: Special Cases Zero fill / extension: If a numeric value does not contain enough digits to fill the specified number of bits, the high order bits are filled with zeros. If the most significant bit specified is an x or z, the x/z is left extended to fill the bit field. 16’h39  8’hz  Negative numbers: Specified by preceding the with a minus (negative) symbol. Values will be stored as the two’s complement of the given value.

17 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 17 Verilog 2001 Syntax l Signed Values: ’s l The “s” denotes that a value is signed (all other values are assumed unsigned) l This does not change the value, but it does change how certain operators deal with the value (namely, whether or not it will be sign-extended) l Examples: » 4’hF =1111 in binary » 4’shF = 1111 in binary (but will sometimes be interpreted as -1)

18 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 18 Example: Stimulus l How would you write the values for Data and here? (assume Data is 4 bits)

19 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 19 Today’s Lecture l Verilog Introduction l Conventions, Identifiers, Numbers, & Operators l Data Types l Modules l Test Benches

20 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 20 Net Variables Nets are usually declared by the keyword wire. Nets represent connections between hardware components. wire d;// declare output as net d. wire b, c;// declare two wires in same statement a, b, c, & d are nets. abab c d

21 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 21 Register Variables Registers are variables that can hold a value. not necessarily the same as a hardware register Registers can be assigned values multiple times during a simulation, but Nets can be assigned only at the beginning of a simulation. Would you use a Net or a Register variable for the Data and here signals in the Data Selector example? Registers are declared by the keyword reg. The default value for a reg data type is x. reg start; // declares register “start” reg reset, clock; // declares registers reset & clock

22 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 22 Bitvectors l Left bit is considered the most significant l By convention, use [ : ] Bitvectors can be specified by declaring the range of bit numbers with the variable name. The form of the declaration is: [ : ] ; or [ : ] ; // declare 8-bit data named BYTE // declare 16-bit register named INFO // declare 12-bit register named DATA

23 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 23 Specifying Parts of Vectors Given vector declarations, it is possible to reference parts of a register (down to a single bit). The format of the reference follows the pattern [ ]. // bit 5 of INFO // bits 11-8 of INFO (bits 11-8) // least significant byte of DATA

24 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 24 Other Types l Integer l Real l Time (accessed w/ system function $time) l Rarely used in the description of a hardware module but are frequently useful in the Test Bench. l See Sutherland, section 7.0 for details

25 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 25 Arrays Arrays can be declared for both scalar and vector data. An array is simply an ordered group of elements. All arrays are single dimensioned in Verilog. Arrays are declared with the syntax: [ ] or [ ] reg bool [31:0];// 32 1-bit boolean register values integer count [0:9];// array of 10 count variables reg [7:0] PID [0:5];// array of 6 bytes

26 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 26 Memories reg bitmem [0:1023]// 1K x 1 (bit) memory reg [7:0] MEM [0:16383]// 16K x 8 or 16K bytes Note that the addressing range is usually specified as [ : ] and for physical reasons, the address range starts at 0. Memories are defined by the syntax: [ ]

27 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 27 Symbolic Constants (Parameters) The parameter keyword allows definition of a symbolic label with a constant value. Anytime that label is used in the Verilog code, it is replaced with its constant value. parameter size = 16;// defines a constant called // size with a value of 16 For example, if size is defined with a value of 16, the memory declaration: reg [size-1 : 0] MEM [0 : 4095] gives the same result as writing: reg [15:0] MEM [0:4095]

28 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 28 Verilog 2001 Syntax l Signed Variables can be declared with the keyword signed l As with signed values, declaring a variable as signed does not change its value, but rather how certain operators deal with the value (namely, whether or not it will be sign-extended) reg signed [7:0] mybyte; wire signed [5:0] myvar;

29 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 29 Today’s Lecture l Verilog Introduction l Conventions, Identifiers, Numbers, & Operators l Data Types l Modules l Test Benches

30 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 30 Module Descriptions in Verilog The Verilog description of a digital module follows a prescribed structure as follows: Header Parameters Port declarations Variable declarations Instantiation of lower-level modules Functionality description - Gate-level - Data Flow - Behavioral Terminator Let’s write a module description for the Data Selector:

31 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 31 Header & Port Declarations Module header: names the module and lists ports. module ( ); Port declarations: specify the input and output port characteristics. (like variable declarations, but use the keywords input and output)

32 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 32 Variable Declarations Variable declarations: specify module’s nets & registers. reg [15:0] A, B;// A & B are 16-bit registers wire [15:0] Data, A_data, B_data; wire here, new_A, new_B; Note: The wire declarations could be omitted since port declarations imply the associated nets.

33 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 33 Verilog 2001 Syntax l Verilog 2001 allows port declarations within the port-list module data_selector (Data, here, A_data, new_A, B_data, new_B); input [15:0] Data; input here; output [15:0] A_data, B_data; output new_A, new_B; module data_selector ( input [15:0] Data, input here, output [15:0] A_data, B_data, output new_A, new_B ); 1995 Syntax 2001 Syntax

34 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 34 Instantiation, Functionality, Terminator Terminator marks the end of the Verilog module description. It is simply endmodule (without a trailing semicolon). Instantiation of lower-level modules: creates a unique named instance for each of the low-level modules. ( ); Functionality description: specifies the internal organization and operation of the module. There are three levels of abstraction that will be studied:

35 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 35 Data Selector’s Module Description module data_selector (Data, here, A_data, new_A, B_data, new_B); input [15:0] Data; input here; output [15:0] A_data, B_data; output new_A, new_B; reg [15:0] A, B; wire [15:0] DATA, A_data, B_data;// these 2 lines can wire here, new_A, new_B;// be omitted // No modules to instantiate for this design // Description of functionality would go here endmodule 1995 Syntax

36 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 36 Data Selector’s Module Description module data_selector (input [15:0] Data, input here, output [15:0] A_data, B_data, output new_A, new_B); reg [15:0] A, B; // No modules to instantiate for this design // Description of functionality would go here endmodule 2001 Syntax

37 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 37 Today’s Lecture l Verilog Introduction l Conventions, Identifiers, Numbers, & Operators l Data Types l Modules l Test Benches

38 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 38 Creating the Stimulus l We know how to describe the Data-Selector, but how do we describe its stimulus? l Need to specify a behavior that has a beginning and an end.

39 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 39 Initial Blocks l Use an initial block to specify a behavior for a module that executes once at the beginning of the simulation. initial begin myvar = 4’d9; myvar = 4’d7; … end l begin and end are needed only if there is more than one statement in the initial block (like “{“ and “}” in C) » Looks a bit like Pascal and Ada l Note that there is no semicolon after initial, begin, end l In the example above, is myvar declared as wire or reg?

40 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 40 Displaying Values l Use the system task $display to print out values l $display is like printf() in C (see Sutherland, section 18.0 for details) module hello; initial $display(“Hello World!\n”); endmodule //hello

41 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 41 Representation of Stimulus module test; reg [3:0] Data; initial begin Data = 4'h2; $display("Data = %h",Data); Data = 4'hA; $display("Data = %h",Data); Data = 4'h7; $display("Data = %h",Data); end endmodule //test

42 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 42 Summary l What characters are allowed in identifiers? l What kinds of circuits would generate the values 0, 1, x, and z? l What is the difference between wire and reg variables? l What parts of the module description do you need to create a test-bench?

43 Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 43 Homework #1 Tips l Problem 2 (a) and (b) » Please convert to binary manually l Problem 7 » See Sutherland, section 19.0 for an example of the `define compiler directive


Download ppt "Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction."

Similar presentations


Ads by Google