Overview Logistics Last lecture Today HW5 due today

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

Recap : Always block module and_gate (out, in1, in2); inputin1, in2; outputout; regout; or in2) begin out = in1 & in2; end endmodule zAlways.
Simulation executable (simv)
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
CSCI 660 EEGN-CSCI 660 Introduction to VLSI Design Lecture 7 Khurram Kazi.
Synchronous Sequential Logic
EE 361 Fall 2003University of Hawaii1 Hardware Design Tips EE 361 University of Hawaii.
Combinational Logic.
Table 7.1 Verilog Operators.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
HDL Programming Fundamentals UNIT 3: Behavioral Descriptions OBJECTIVES  Understand the concept of sequential statements in VHDL and how they are different.
2/9/20031 ECE 551: Digital System Design & Synthesis Lecture Set 4 4.1: Verilog – Procedural Assignments &Scheduling Semantics 4.2: Verilog – More Behavioral.
Slide 1 7. Verilog: Combinational always statements. VHDL: Combinational Processes: To avoid (I.E. DO NOT What in your HDL code?) Cases that generate Synthesis.
1 COMP541 Sequential Circuits Montek Singh Sep 17, 2014.
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.
CSE Spring Verilog for Sequential Systems - 1 Today: Verilog and Sequential Logic zFlip-flops yrepresentation of clocks - timing of state.
ENEE 408C Lab Capstone Project: Digital System Design Spring 2006 Class Web Site:
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
Digital System Design by Verilog University of Maryland ENEE408C.
ELEN 468 Lecture 91 ELEN 468 Advanced Logic Design Lecture 9 Behavioral Descriptions III.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Verilog 2 (Sequential.
ELEN 468 Advanced Logic Design
Advanced Verilog EECS 270 v10/23/06.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Lecture 7 Verilog Additional references Structural constructs
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.
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.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
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.
Module 1.2 Introduction to Verilog
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.
1 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Verilog for Synthesis Ing. Pullini Antonio
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
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.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
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.
COMP541 Sequential Circuits
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 6: Procedural Modeling Spring 2009 W. Rhett.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Structural Description
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
Hardware Description Languages: Verilog
COE 202 Introduction to Verilog
Chapter 4: Behavioral Modeling
The Verilog Hardware Description Language
ECE 551: Digital System Design & Synthesis
Introduction to Verilog – Part-2 Procedural Statements
Presentation transcript:

Overview Logistics Last lecture Today HW5 due today HW6 due next Friday Last lecture Finish basic latches and Flip-flops Registers Shift registers Counters Basic state machine design Today Sequential Verilog

Variables wire reg The rule Connects components together Saves a value Part of a behavioral description Does NOT necessarily become a register when you synthesize May become a wire The rule Declare a variable as reg if it is a target of an assignment statement inside an always block Continuous assign doesn’t count

Sequential Verilog Sequential circuits: Registers & combinational logic Use positive edge-triggered registers Avoid latches and negative edge-triggered registers Register is triggered by “posedge clk” Example: A D flip-flop module register(Q, D, clock); input D, clock; output Q; reg Q; always @(posedge clock) begin Q <= D; end endmodule A real register. Holds Q between clock edges

always block A construct that describes a circuit’s behavior Can contain multiple statements Can contain if, for, while, case Triggers at the specified conditions begin/end groups statements within always block module register(Q, D, clock); input D, clock; output Q; reg Q; always @(posedge clock) begin Q <= D; end endmodule

always example module and_gate(out, in1, in2); input in1, in2; output out; reg out; always @(in1 or in2) begin out = in1 & in2; end endmodule Not a real register!! Holds assignment in always block The compiler will not synthesize this code to a register, because out changes whenever in1 or in2 change. Can instead simply write wire out, in1, in2; and (out, in1, in2); specifies when block is executed i.e. triggered by changes in in1 or in2

Incomplete sensitivity list or incomplete assignment What if you omit an input trigger (e.g. in2) Compiler will insert a latch to hold the state Becomes a sequential circuit — NOT what you want module and_gate (out, in1, in2); input in1, in2; output out; reg out; always @(in1) begin out = in1 & in2; end endmodule Real state!! Holds out because in2 isn’t specified in always sensitivity list 2 rules: 1) Include all inputs in the trigger list 2) Use complete assignments  Every path must lead to an assignment for out  Otherwise out needs a state element

Incomplete sensitivity lists • always @(a or b) // it’s or, not || f = a & b; • always @(a) • always • Just use always@(*) for combinational logic

Assignments Be careful with always assignments Which of these statements generate state? always @(c or x) begin if (c) begin value = x; end y = value; always @(c or x) begin value = x; if (c) begin value = 0; end y = value; always @(c or x) begin if (c) value = 0; else if (x) value = 1; end always @(a or b) f = a & b & c; end 2 rules: 1) Include all inputs in the sensitivity list 2) Use complete assignments  Every path must lead to an assignment for out  Otherwise out needs a state element

Another way: Use functions Functions for combinational logic Functions can’t have state module and_gate (out, in1, in2); input in1, in2; output out; assign out = myfunction(in1, in2); function myfunction; input in1, in2; begin myfunction = in1 & in2; end endfunction endmodule Benefits: Functions force a result  Compiler will fail if function does not generate a result  If you build a function wrong the circuit will not synthesize. If you build an always block wrong you get a register

if Same as C if statement // Simple 4-1 mux module mux4 (sel, A, B, C, D, Y); input [1:0] sel; // 2-bit control signal input A, B, C, D; output Y; reg Y; // target of assignment always @(sel or A or B or C or D) if (sel == 2’b00) Y = A; else if (sel == 2’b01) Y = B; else if (sel == 2’b10) Y = C; else if (sel == 2’b11) Y = D; endmodule  Single if statements synthesize to multiplexers  Nested if /else statements usually synthesize to logic

if (another way) // Simple 4-1 mux module mux4 (sel, A, B, C, D, Y); input [1:0] sel; // 2-bit control signal input A, B, C, D; output Y; reg Y; // target of assignment always @(sel or A or B or C or D) if (sel[0] == 0) if (sel[1] == 0) Y = A; else Y = B; else if (sel[1] == 0) Y = C; else Y = D; endmodule

case // Simple 4-1 mux module mux4 (sel, A, B, C, D, Y); input [1:0] sel; // 2-bit control signal input A, B, C, D; output Y; reg Y; // target of assignment always @(sel or A or B or C or D) case (sel) 2’b00: Y = A; 2’b01: Y = B; 2’b10: Y = C; 2’b11: Y = D; endcase endmodule case executes sequentially  First match executes  Don’t need to break out of case case statements synthesize to muxes

case (another way) Note: You can define a function in a file // Simple 4-1 mux module mux4 (sel, A, B, C, D, Y); input [1:0] sel; // 2-bit control signal input A, B, C, D; output Y; assign out = mymux(sel, A, B, C, D); function mymux; input [1:0] sel, A, B, C, D; begin case (sel) 2’b00: mymux = A; 2’b01: mymux = B; 2’b10: mymux = C; 2’b11: mymux = D; endcase end endfunction endmodule Note: You can define a function in a file Then include it into your Verilog module

default case // Simple binary encoder (input is 1-hot) module encode (A, Y); input [7:0] A; // 8-bit input vector output [2:0] Y; // 3-bit encoded output reg [2:0] Y; // target of assignment always @(A) case (A) 8’b00000001: Y = 0; 8’b00000010: Y = 1; 8’b00000100: Y = 2; 8’b00001000: Y = 3; 8’b00010000: Y = 4; 8’b00100000: Y = 5; 8’b01000000: Y = 6; 8’b10000000: Y = 7; default: Y = 3’bx; // Don’t care about other cases endcase endmodule If you omit the default, the compiler will create a latch for Y  Either list all 256 cases  Or use a function (compiler will warn you of missing cases)

case executes sequentially // Priority encoder module encode (A, Y); input [7:0] A; // 8-bit input vector output [2:0] Y; // 3-bit encoded output reg [2:0] Y; // target of assignment always @(A) case (1’b1) A[0]: Y = 0; A[1]: Y = 1; A[2]: Y = 2; A[3]: Y = 3; A[4]: Y = 4; A[5]: Y = 5; A[6]: Y = 6; A[7]: Y = 7; default: Y = 3’bx; // Don’t care when input is all 0’s endcase endmodule Case statements execute sequentially  Take the first alternative that matches

for for statements synthesize as cascaded combinational logic // simple encoder module encode (A, Y); input [7:0] A; // 8-bit input vector output [2:0] Y; // 3-bit encoded output reg [2:0] Y; // target of assignment integer i; // Temporary variables for program reg [7:0] test; always @(A) begin test = 8b’00000001; Y = 3’bx; for (i = 0; i < 8; i = i + 1) begin if (A == test) Y = i; test = test << 1; // Shift left, pad with 0s end endmodule Note the “integer” for statements synthesize as cascaded combinational logic  Verilog unrolls the loop

Verilog while/repeat/forever while (expression) statement execute statement while expression is true repeat (expression) statement execute statement a fixed number of times forever statement execute statement forever

Blocking and non-blocking assignments Blocking assignments (Q = A) Variable is assigned immediately New value is used by subsequent statements Non-blocking assignments (Q <= A) Variable is assigned after all scheduled statements are executed Value to be assigned is computed but saved for later Example: Swap always @(posedge CLK) begin temp = B; B = A; A = temp; end always @(posedge CLK) begin A <= B; B <= A; end

Blocking and non-blocking assignments reg B, C, D; always @(posedge clk) begin B = A; C = B; D = C; end reg B, C, D; always @(posedge clk) begin B <= A; C <= B; D <= C; end

Swap The following code executes incorrectly One block executes first Loses previous value of variable Non-blocking assignment fixes this Both blocks are scheduled by posedge CLK always @(posedge CLK) begin A = B; end always @(posedge CLK) begin B = A; end always @(posedge CLK) begin A <= B; end always @(posedge CLK) begin B <= A; end

A simple stateful example module stateful_and (out, in, clk); input in, clk; output out; reg out; always @(posedge clk) begin out <= in & out; end endmodule

Parallel versus serial execution assign statements are implicitly parallel “=” means continuous assignment Example assign E = A & D; assign A = B & C; A and E change if B changes always blocks execute in parallel always @(posedge clock) Procedural block internals not necessarily parallel “=” is a blocking assignment (sequential) “<=” is a nonblocking assignment (parallel) Examples of procedures: always, function, etc.

Synthesis examples wire [3:0] x, y, a, b, c, d; assign apr = ^a; assign y = a & ~b; assign x = (a == b) ? a + c : d + a; x + == a b c d x + == a b c d

Verilog tips and traps

Constants: 32 bits, decimal • wire [7:0] foo = 127; // synthesis warning! • wire [7:0] foo = 8’d127; • wire [7:0] foo = 8’b11111111; • wire [7:0] foo = 8’hff; • wire [7:0] foo = 8’hFF; • watch out: 1010 looks like 4’b1010!

Truncation wire [7:0] a = 8’hAB; wire b; // oops! forgot width wire [7:0] c; assign b = a; // synthesis warning if lucky. assign c = a;

TIP: (blocking) = vs. <= (non-blocking) • Simple rule: • If you want sequential logic, use always @(posedge clk) with <= (non-blocking) • If you want combinational logic, use always @(*) with = (blocking)

Verilog Stratified Event Queue [1] Region 1: Active Events Most events except those explicitly in other regions Includes $display system tasks Region 2: Inactive Events Processed after all active events #0 delay events (bad!) Region 3: Non-blocking Assign Update Events Evaluation previously performed Update is after all active and inactive events complete Region 4: Monitor Events Caused by $monitor and $strobe system tasks Region 5: Future Events Occurs at some future simulation time Includes future events of other regions Other regions only contain events for CURRENT simulation time

Verilog Stratified Event Queue [2] within a block, blocking assignments, are in order