Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 6: Procedural Modeling Spring 2009 W. Rhett.

Slides:



Advertisements
Similar presentations
VERILOG: Synthesis - Combinational Logic Combination logic function can be expressed as: logic_output(t) = f(logic_inputs(t)) Rules Avoid technology dependent.
Advertisements

Verilog.
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Combinational Logic.
Table 7.1 Verilog Operators.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part3: Verilog – Part 1.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 8: Sequential Design Spring 2009 W. Rhett.
 HDLs – Verilog and Very High Speed Integrated Circuit (VHSIC) HDL  „ Widely used in logic design  „ Describe hardware  „ Document logic functions.
Verilog - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
ECE 551 Digital System Design & Synthesis Lecture 09 Synthesis of Common Verilog Constructs.
Spring 20067W. Rhett Davis with minor modifications by Dean Brock ECE 406 at UNASlide 1 ECE 406 Design of Complex Digital Systems Lecture 10: 9: State.
ELEN 468 Lecture 151 ELEN 468 Advanced Logic Design Lecture 15 Synthesis of Language Construct I.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
CSE241 R1 Verilog.1Kahng & Cichy, UCSD ©2003 CSE241 VLSI Digital Circuits Winter 2003 Recitation 1: Verilog Introduction.
ECEN ECEN475 Introduction to VLSI System Design Verilog HDL.
ELEN 468 Advanced Logic Design
Advanced Verilog EECS 270 v10/23/06.
Digital System Design EEE344 Lecture 3 Introduction to Verilog HDL Prepared by: Engr. Qazi Zia, Assistant Professor EED, COMSATS Attock1.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 13: Regression Testing, MemAccess Block.
Overview Logistics Last lecture Today HW5 due today
Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 7: Design Example,
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
Programmable Logic Architecture Verilog HDL FPGA Design Jason Tseng Week 5.
ECE 2372 Modern Digital System Design
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction to Verilog Syntax Spring.
Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 2: Introduction.
Chapter 4: Behavioral Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 4-1 Ders – 4: Davranışsal Modelleme.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
CS 3850 Lecture 3 The Verilog Language. 3.1 Lexical Conventions The lexical conventions are close to the programming language C++. Comments are designated.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 3: Structural Modeling Spring 2009 W. Rhett.
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 7: Design Example, Modeling Flip-Flops Spring.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
3/4/20031 ECE 551: Digital System Design * & Synthesis Lecture Set 3 3.1: Verilog - User-Defined Primitives (UDPs) (In separate file) 3.2: Verilog – Operators,
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
ELEN 468 Lecture 131 ELEN 468 Advanced Logic Design Lecture 13 Synthesis of Combinational Logic II.
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
M.Mohajjel. Structured Procedures Two basic structured procedure statements always initial All behavioral statements appear only inside these blocks Each.
Introduction to ASIC flow and Verilog HDL
M.Mohajjel. Objectives Learn How to write synthesizable Verilog code Common mistakes and how to avoid them What is synthesized for what we code Digital.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 4: Testing, Dataflow Modeling Spring 2009.
Introduction to Verilog. Data Types A wire specifies a combinational signal. – Think of it as an actual wire. A reg (register) holds a value. – A reg.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 12: Intro to the LC-3 Micro-architecture.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 9: State Machines & Reset Behavior Spring.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 10: Data-Converter Example Spring 2009 W.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Verilog Tutorial Fall
TODAY’S OUTLINE Verilog Codings Concurrent and Sequential If-else
ELEN 468 Advanced Logic Design
Reg and Wire:.
Discussion 2: More to discuss
Verilog-HDL-3 by Dr. Amin Danial Asham.
Hardware Description Languages: Verilog
Introduction to Verilog
Behavioral Modeling in Verilog
COE 202 Introduction to Verilog
Chapter 4: Behavioral Modeling
The Verilog Hardware Description Language
Supplement on Verilog combinational circuit examples
ECE 551: Digital System Design & Synthesis
Presentation transcript:

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 6: Procedural Modeling Spring 2009 W. Rhett Davis NC State University with significant material from Paul Franzon, Bill Allen, & Xun Liu

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 2 Announcements l HW#2 Due Today l HW#3 Due in 1 week l Tip for Debugging: » Use workspace directories (we have read access) » Post to message board with the path to your code and the text of the error message(s)

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 3 Summary of Last Lecture l Does every numeric value have a corresponding logical value? l How do you tell the difference between a bitwise operator and a reduction operator? l How are vectors extended when operand lengths are mismatched? l What operator would you use to implement sign- extension?

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 4 Today’s Lecture l Sign-Extending Shifter Example l Intro to Procedural Modeling l Control Constructs l Inferred Latches

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 5 Sign-Extending Right Shifter l Design a Module that shifts a 4-bit input to the right 0 to 3 bits, depending on a shift input. l Use only replication and conditional operators: insout

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 6 Schematic for the Right-Shifter

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 7 Sign-Extending Right Shifter module rightshift(output [3:0] out,input [3:0] in, input [1:0] s); endmodule // rightshift

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 8 Today’s Lecture l Sign-Extending Shifter Example l Intro to Procedural Modeling l Control Constructs l Inferred Latches

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 9 Parts of a Verilog Module l Header: module ( ); l Parameter, Port, & Variable declarations l Functionality description » Structural –Instantiations of basic gates –Instantiations of lower-level modules » Behavioral –Data-Flow (continuous assignments) –Procedural (initial & always blocks) l Terminator: endmodule

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 10 Why Procedural Modeling? l Needed for test-benches l Can also use it to describe the hardware. Why would we want to? » Needed to describe sequential logic » What is sequential logic?

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 11 Modeling Combinational Logic l Generally, combinational logic is modeled with continuous assignments (Data-Flow modeling)… l …But it can also be modeled procedurally » More abstract than Data-Flow » Allows the use of “control constructs” like if-then-else, case

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 12 Initial Blocks l You’re familiar with procedural blocks… You used one to implement a test bench: l Procedural blocks are special because the statements are assumed to be executed sequentially l Unlike the Data-Flow (continuous assignment), for which the order doesn’t matter initial begin $monitor($time, “in0: %b in1: %b sel: %b out: %b”, in0, in1, sel, out); in0 = 0; in1 = 1; sel = 0;// vector #1 #10 in0 = 0; in1 = 1; sel = 1;// vector #2 #10 $finish; end

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 13 A Simple Procedural Example l Assuming that A,B,C, and X are all 1-bit variables, what logic is implied by the procedural behavior below? l If we had written this as a dataflow behavior, it would be illegal. Why? assign X=A&B; assign X=(X==C); X=A&B; X=(X==C);

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 14 The always Block l Use the following statement to define a procedural hardware block: ) or where is a sequence of assignments delimited by begin and end l The or “sensitivity list” gives the events that “trigger” the execution of the block

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 15 Event-Lists l Simply naming a variable in the event-list means that the block will be triggered whenever that variable changes l Use the or keyword to list multiple variables l In this example, what does the event-list need to be for the logic to behave as expected? ) begin X=A&B; X=(X==C); end

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 16 Verilog 2001 Event-Lists l Verilog 2001 allows the use of commas to separate events l The special case can be used to indicate “all signals referenced in any expression” ) begin X=A&B; X=(X==C); end ) begin X=A&B; X=(X==C); end

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 17 Incomplete Sensitivity Lists l If we had written the block like this, what would happen? l All combinational inputs MUST be in the event- list for the logic to be modeled properly! A ) begin X=A&B; X=(X==C); end

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 18 A Complete Procedural Module l Remember that assignments in proceudural block must be to reg variables! (not wire variables) l Otherwise, you’ll get an error. l Synthesis tools will recognize that combinational logic is being modeled, and there will be no registers in the final hardware. module and_xnor(X, A, B, C); input A, B, C; output X; reg X; A or B or C ) begin X=A&B; X=(X==C); end endmodule // and_xnor

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 19 A Complete 2001 Procedural Module l Note that the output X is declared as a reg inside the port-list l Note the use (This is always advised when modeling combinational logic, in order to avoid the incomplete sensitivity list problem) module and_xnor( output reg X, input A, B, C); begin X=A&B; X=(X==C); end endmodule // and_xnor

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 20 Today’s Lecture l Sign-Extending Shifter Example l Intro to Procedural Modeling l Control Constructs l Inferred Latches

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 21 Conditional Statements: if-else if - else if - else has the following syntax. if ( ) ; else if ( ) ; else ; If the logical value of is true, is executed. If the logical value of is false and the logical value of is true then is executed. If the logical values of both and are false, then is executed. Sutherland guide 10.3

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 22 ALU Example: if-else Code fragment of a 16-bit arithmetic logic unit (ALU) that performs one of 5 operations. if (alu_ctrl == 0) // alu_ctrl is 3 bits ALU_OUT = ALU_IN1 + ALU_IN2;// add else if (alu_ctrl == 1) ALU_OUT = ALU_IN1 - ALU_IN2;// subtract else if (alu_ctrl == 2) ALU_OUT = ALU_IN1 & ALU_IN2;// and else if (alu_ctrl == 3) ALU_OUT = ALU_IN1 | ALU_IN2;// or else if (alu_ctrl == 4) ALU_OUT = ALU_IN1 ^ ALU_IN2;// exor else ALU_OUT = 16’d0;// other 3 undefined

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 23 Conditional Statements: case The syntax of the case statement is: case ( ) : ; : ; default: ; endcase The value of is matched to in sequence, For the first that matches, the corresponding is executed. If no alternatives match, is executed. Sutherland guide 10.3

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 24 ALU Example: case Using the previous example of an ALU, the corresponding implementation using a case statement is: case (alu_ctrl) 3’d0: ALU_OUT = ALU_IN1 + ALU_IN2; 3’d1: ALU_OUT = ALU_IN1 - ALU_IN2; 3’d2: ALU_OUT = ALU_IN1 & ALU_IN2; 3’d3: ALU_OUT = ALU_IN1 | ALU_IN2; 3’d4: ALU_OUT = ALU_IN1 ^ ALU_IN2; default: ALU_OUT = 16’d0;

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 25 case: Comparison Details The case statement literally compares 0, 1, x and z values in the conditional expression bit-by-bit with the alternatives. Thus if the case expression is 4’b10xz, the comparison is looking for an alternative of 4’b10xz. In other words an exact match is required. Also, if the sizes of the evaluated expression and the alternative pattern are unequal, the shortest field is extended with zeros so the sizes are equal.

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 26 Alternatives: casex, casez There are two variants of the case statement defined by the keywords casex and casez. casex treats all x and z values in the case expression or alternatives as don’t cares. casez treats all z values in the case expression or alternatives as don’t care’s. The casex is useful when the state of certain bit positions is immaterial in some of the alternatives. By using casex in such situations, it is possible to reduce the number of alternatives needed. Sutherland guide 10.3

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 27 Procedural Examples l Muxes and Data Selectors reg [1:0] in1, in2, out; reg in3; or in2 or in3) if (in3) out = in1; else out = in2; in1[0] in2[0] in1[1] in2[1] in3 out[0] out[1] 1010 in1[0] in1[1] in1[2] in1[3] in out reg [3:0] in1; regout; reg [1:0] in2; or in2) case (in2) 2’b00 : out = in1[0]; 2’b01 : out = in1[1]; 2’b10 : out = in1[2]; 2’b11 : out = in1[3]; endcase

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 28 Procedural Examples l Priority Selector or Encoder or B or C) casex(A) 3’b1xx : out = B; 3’b01x : out = C; default : out = 2’b0; endcase l Decoder case (address) 2’b00 : line = 4’b0001; 2’b01 : line = 4’b0010; 2’b10 : line = 4’b0100; 2’b11 : line = 4’b1000; endcase A[2] has priority over other bits of A. If A[2]=1, out=B, no matter what CCBBBB00CCBBBB Out[1:0] 2 A[2:0] 2 address line[3] line[2] line[1] line[0]

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 29 Today’s Lecture l Sign-Extending Shifter Example l Intro to Procedural Modeling l Control Constructs l Inferred Latches

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 30 Latches l Complete the behavior below: or D) if (clock) Q = D; clock D Q l We will not intentionally build latches in this class l Instead, we’ll stick to one type of timing element (edge triggered flip-flops)

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 31 Inferred (Unintentional) Latches l What is happening here? or B or C) begin D = B & C; if (D) E = C; end

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 32 Procedural Examples l What about this? or B) casex (A) 2’b00 : C = B; 2’b01 : C = ~B; endcase

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 33 Procedural Examples l Will this simulate correctly? C = A | B;

Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 34 Summary l Does the order of procedural assignments matter? What about continuous assignments? l What does the event-list of an always block mean? l To model combinational logic procedurally, what variables must be in the event list? l Should variables assigned in a procedural block be declared as wire, reg, or either? l How do you prevent an unintentional latch?