Quick Introduction to SystemVerilog: Sequental Logic

Similar documents
Testbenches for Sequential Circuits... also, Components

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

Last Lecture: Divide by 3 FSM

Last Lecture. Talked about combinational logic always statements. e.g., module ex2(input logic a, b, c, output logic f); logic t; // internal signal

ECE 2300 Digital Logic & Computer Organization. More Finite State Machines

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

FSM and Efficient Synthesizable FSM Design using Verilog

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

Building Bigger Systems: Hardware Threads

Sequential Logic Design

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

Lecture 32: SystemVerilog

Synthesizable Verilog

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

Digital Design with SystemVerilog

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Building Bigger Systems: Interfacing

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

Verilog for Synthesis Ing. Pullini Antonio

ECE 551: Digital System *

CSE 502: Computer Architecture

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Mealy and Moore examples

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

ECEN 468 Advanced Logic Design

Outline. EECS Components and Design Techniques for Digital Systems. Lec 11 Putting it all together Where are we now?

EECS 270 Verilog Reference: Sequential Logic

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

Modeling of Finite State Machines. Debdeep Mukhopadhyay

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Writing Circuit Descriptions 8

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

Digital Integrated Circuits

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

SystemVerilog HDL - a programming language

Modeling Sequential Circuits in Verilog

Lecture 15: System Modeling and Verilog

EEL 4783: HDL in Digital System Design

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

CSE140L: Components and Design Techniques for Digital Systems Lab

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

Verilog Coding Guideline

271/469 Verilog Tutorial

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

Registers and finite state machines

ECE 4514 Digital Design II. Spring Lecture 13: Logic Synthesis

CSE140L: Components and Design

Finite State Machines

A short introduction to SystemVerilog. For those who know VHDL We aim for synthesis

General FSM design procedure

Logic Circuits II ECE 2411 Thursday 4:45pm-7:20pm. Lecture 3

HDLs and SystemVerilog. Digital Computer Design

EECS 470 Lab 3. SystemVerilog Style Guide. Department of Electrical Engineering and Computer Science College of Engineering University of Michigan

VHDL: RTL Synthesis Basics. 1 of 59

Synthesis of Combinational and Sequential Circuits with Verilog

Sequential Circuits. inputs Comb FFs. Outputs. Comb CLK. Sequential logic examples. ! Another way to understand setup/hold/propagation time

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

Lecture 3. Behavioral Modeling Sequential Circuits. Registers Counters Finite State Machines

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

Bulletproofing FSM Verification Automated Approach to Detect Corner Case Issues in an FSM Design

TSEA44: Computer hardware a system on a chip

ECE 574: Modeling and Synthesis of Digital Systems using Verilog and VHDL. Fall 2017 Final Exam (6.00 to 8.30pm) Verilog SOLUTIONS

Control in Digital Systems

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Techniques for Digital Systems Lab. Verilog HDL. Tajana Simunic Rosing. Source: Eric Crabill, Xilinx

Abstraction of State Elements. Sequential Logic Implementation. Forms of Sequential Logic. Finite State Machine Representations

HDL Design Cube. Synthesis and VHDL

DIGITAL SYSTEM DESIGN

EN164: Design of Computing Systems Lecture 07: Lab Foundations / Verilog 3

General FSM design procedure

Why Should I Learn This Language? VLSI HDL. Verilog-2

L5: Simple Sequential Circuits and Verilog

Finite-State Machine (FSM) Design

L5: Simple Sequential Circuits and Verilog

What, If Anything, In SystemVerilog Will Help Me With FPGA-based Design. Stuart Sutherland, Consultant and Trainer, Sutherland HDL, Inc.

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

Parallel versus serial execution

General FSM design procedure

B.10 Finite State Machines B.10

CSE140L: Components and Design Techniques for Digital Systems Lab. FSMs. Instructor: Mohsen Imani. Slides from Tajana Simunic Rosing

CMPE 415 Verilog Case-Statement Based State Machines II

RTL Design (Using ASM/SM Chart)

Verilog Execution Semantics

FSM Components. FSM Description. HDL Coding Methods. Chapter 7: HDL Coding Techniques

EECS150 - Digital Design Lecture 10 Logic Synthesis

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

Verilog Sequential Logic. Verilog for Synthesis Rev C (module 3 and 4)

(System)Verilog Tutorial Aleksandar Milenković

ECE 4514 Digital Design II. Spring Lecture 2: Hierarchical Design

Course Topics - Outline

Lab 7 (All Sections) Prelab: Introduction to Verilog

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Sequential Logic Implementation. Mealy vs. Moore Machines. Specifying Outputs for a Mealy Machine. Specifying Outputs for a Moore Machine

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb With material by Professor Moritz and Kundu UMass Amherst Fall 2016

The University of Alabama in Huntsville ECE Department CPE Midterm Exam February 26, 2003

Transcription:

! Quick Introduction to SystemVerilog: Sequental Logic Lecture L3 8-545 Advanced Digital Design ECE Department Many elements Don Thomas, 24, used with permission with credit to G. Larson

Today Quick synopsis of Finite State Machines (FSM) Moore, Mealy Design process SystemVerilog for a Flip flop SystemVerilog for a FSM Exercise: Design, implement and synthesize a FSM 2

Designing FSMs: Step State Transition Diagrams represent FSMs at a high level of abstraction. Each state is represented by a circle A/, C/ 2. Each state is labeled with a symbolic name. An output value is specified for each state Reset B/ 3. A directed edge from state Sx to Sy indicates a potential transition 5. Whenever reset is asserted, the FSM transitions to a special initial state Each transition is labeled with input values that, should they be present, would cause the state to change from Sx to Sy 4. One of the state transitions occurs for each clock event 8-24 L9 3

What does it mean? E.g. -bit input, -bit output, 3-state FSM - trace the execution for input sequence after Reset - What will the output be? The next state? Reset A/, B/ C/ clock event State A A B B B C Output Input X Reset 8-24 L9 4

State Transition Diagram Example Things to note - Output is a function of state not input out = (state == B)? : ; - Next state is a function of current state and input Reset if (state == B && input == ) then next state is B else next state is C A/, B/ C/ An FSM is a 5-tuple - A set of states here {A, B, C} - A set of allowable inputs ( alphabet ) here {, } - A set of allowable outputs ( alphabet ) {, } - A next state function here a combinational fn of (state, input) - An output function here a combinational fn of (state) 8-24 L9 5

Reset Putting it in context A/, C/ inputs Next State Generator (comb logic) Current State Register Output Generator (comb logic) outputs B/ clock Let CS be current state and NS be next state if (Reset) NS=A else if (CS==A) if (Input==) NS=A else NS=B else if (CS==B) if (Input==) NS=C else NS=B else if (CS==C) NS=A 2-bit state register for example means A means B means C don t care Hmm, can you imagine describing these as always_comb blocks? Let CS be current state out = (CS == B)? : ; 8-24 L9 6

Moore vs. Mealy Machines At the start of this lecture - We said a machine s output was a function of the state Actually Two different types of FSMs - Moore machines: output = a fn of only state (We just did this) - Mealy machines: output = a fn of the state and the inputs Mealy machines = Moore + wire the only difference inputs Next State Generator (comb logic) Current State Register Output Generator (comb logic) outputs clock 8-24 L9 7

Mealy State Diagram and Table The state transition arcs must show the inputs/outputs Output is now a function of both state & input - If you re in state A the output is if the input is, and if the input is - If you re in state B, the output is different from above Reset A / / /,/ / C input/output / B Present state Next State X = X = Output X = X = A B C A C A B B A 8-24 L9 8

Mealy Output Notation Mealy outputs are a function of state and inputs Reset A In Out X Placing a truth table in each state is a bit clumsy - Though less confusing for new students As the transitions already have input specifications, we reuse them to describe outputs B In X Out C In Out X BE CAREFUL: Mealy notation is confusing! You don t have to actually take the transition for the output to occur 8-24 L9 9

Example: Series Recognizer Let s do one example in both Moore and Mealy - Want a series recognizer FSM that outputs a every time it detects sequence in input stream INPUT OUTPUT Moore State Transition Diagram Mealy State Transition Diagram R s? / s / s / R / s? / / s / 8-24 L9

Example: The Timing Is Different! INPUT OUTPUT INPUT OUTPUT Moore State Transition Diagram Mealy State Transition Diagram R s? / s / s / R / s? / / s / 8-24 L9

Example: Essential differences Moore - Need a state for reset that is also the last wasn t - Need a state for the last input was - Need a state for I just saw a after a I recognized a pattern Mealy - Need a state for reset which is also the last wasn t - Need a state for the last input was - Transitions get labeled with correct outputs, not the states - Notice that the start state is target of 2 transitions with different output values this is how we save that extra state - Outputs appear at different times wrt Moore machines The example is small - But you see the Mealy approach is different, results in one less state 8-24 L9 2

To infer a flip-flop Flip-flops are edge-triggered need to use @ with posedge or negedge side effect every variable on the left-hand side assigned with a <= will be an edge triggered flip-flop (or vector of flip-flops) Some combinational logic can be specified in certain places module Dff (output logic Q, input clk, d, resetn); always_ff @(posedge clk, negedge resetn) if (~resetn) Q <= ; else Q <= d; endmodule What happens on the clock edge is inferred it s the last (default) action. The assignment is made to a logic (or bit ) variable, not a reg as in old Verilog. Synthesis infers an FF Q, d, clk, and resetn are not keywords <= needed for synthesis and simulation SVbook 3. 3

New SystemVerilog Constructs A new flavor of always statement - always_ff @(posedge clk) ; - this statement models a flip-flop or register - this statement will synthesize to a flip-flop or register - @(posedge clk) the @ means to wait for the specified change on the listed signal posedge -to- negedge -to- module DFF (input logic d, clk, output logic q); always_ff @(posedge clk) q <= d; endmodule: DFF Current state (Now) Next State (after clk) Clk D Q Q + X X X X X X 8-24 L2 4

Big Idea: Concurrent assignment What about that <=??? - Called non-blocking assignment Sometimes called concurrent, buffered or delayed assignment Use it to assign to a state value, like a flip-flop or register output module DFF (input logic d, clk, output logic q); always_ff @(posedge clk) q <= d; endmodule: DFF <= is not less than or equal!! Why a new assignment type? - This models how an edge triggered flip-flop works All clock-triggered state updates in the design happen instantaneously, at the same time, indivisibly, you can t tell one happened before any other If your design has K flip-flops, then all K assignments happen instantaneously in simulation After all, in the physical hardware, the same clock triggers all K flip-flops and they change concurrently (and instantaneously)! 8-24 L2 5

What about reset? Asynchronous reset - happens anytime rstn becomes Trace behavior - anytime reset changes to, set q to - while reset remains, if the clock edge occurs, q still remains - when reset changes to, q remains until the next clock event module DFF_rst (input logic d, clk, rstn output logic q); always_ff @(posedge clk, negedge rstn) if (~rstn) q <= ; else q <= d; endmodule: DFF_rst If reset asserted This is a list of what the always_ff block is sensitive to This is how to describe a flip-flop. Just do it this way! Copy it!!

How reset works reset is generally asynchronous... module Dff (output logic Q, input logic clk, d, resetn); always_ff @(posedge clk, negedge resetn) if (~resetn) Q <= ; else Q <= d; endmodule : Dff... but could be rising edge module Dff (output logic Q, input logic clk, d, reset); always_ff @(posedge clk, posedge reset) if (reset) Q <= ; else Q <= d; endmodule : Dff 8-24 L2 7

Finite State Machines Defined formally by - Set of states, including reset - set of input combinations not necessarily all 2 n are possible due to don t-cares - set of output combinations not necessarily all 2 n are possible - next state (δ) and output (λ) combinational functions - clock event (or clock domain) - reset signal R / A B / Legend s s i/a,b inputs next state logic / / C D Q D Q output logic x/ outputs MOC: starting in the reset state, the clock event causes the system to change to another (or same) state as defined by the δ function 8-24 L2 8

FSM in SystemVerilog Next State Logic Output Logic X Q D D Q Q Z Clk Q Q Q' D D Clk Q Q Q clock reset_l Two always_comb blocks (or continuous assigns) - one for the combinational next state logic - one for the output logic We ll have another always_ff block for the D flipflops 8-24 L2 9

Explicit FSM Style module myfsm2 (input logic clk, rstn, x, output logic z); logic [:] ns, cs; always_ff @(posedge clk, negedge rstn) if (~rstn) cs <= ; else cs <= ns; always_comb begin ns[] = cs[] & x cs[] & x; ns[] = cs[] & x ~cs[] & x; end assign z = cs[] & cs[]; endmodule: myfsm2 Called explicit FSM style because everything is explicitly defined: state register, output logic, next state logic, and state assignment Done here as 3 blocks - The sequential part: generates current state (cs) from the next state (ns) synchronously - The next state generator: combinational logic to create the next state inputs (D, D) from the current state and input (x) - The output generator: combinational logic to create the output (z) from the current state

Where does clock come from? module clock (output logic clk); initial begin clk = ; forever # clk = ~clk; end endmodule: clock clk time = clk has value one time = clk = zero time = 2 clk = one In HW, the clock is driven from outside of the design A clock module - Used in simulation - Initialization to one (or zero) It will have this value when simulation starts (not x!) - Execution forever loop just keeps executing the statement # says to wait time units Every units clk gets ~clk Someplace else in the design must have a $finish!! 8-24 L2 2

enum enumerate for state encoding enum enumerate statement, similar to what is found in programming languages Below, 2-bit logic variables state and nextstate are defined A set of symbols are defined: ZERO, ONE, TWO, and THREE The bit patterns that represent these symbols are defined shown below These are strongly typed Can leave out type and size (integers with values starting at assumed) enum can also be typedef ed keyword labels and values enum logic [:] {ZERO = 2'd, ONE = 2'd, TWO = 2'd2, THREE = 2'd3} state, nextstate; type and size SVbook 3.4. declared variables 22

Style Points What are the logic components? module explicitfsm (output logic a, b, input ck, r_l, i); enum logic [:] {A=2'b, B=2'b, C=2'b} state, nextstate; One way to do state assignment Why set a to and later back to? but don t do that with b? Why ~r_l instead of switching the sense of the if-else? always_comb begin a = 'b; b = nextstate == A; if ((state == C) && i) a = 'b; end always_comb case (state) A: nextstate = (i)? B : A; B: nextstate = C; C: nextstate = (~i): A : C; default: nextstate = A; endcase always_ff @(posedge ck, negedge r_l) if (~r_l) state <= A; else state <= nextstate; endmodule: explicitfsm Why have a default? 23

Other organizations module explicitfsm (output logic a, b, input ck, r_l, i); enum logic [:] {A=2'b, B=2'b, C=2'b} state, nextstate; always_comb begin a = 'b; b = nextstate == A; if ((state == C) && i) a = 'b; end always_comb case (state) A: nextstate = (i)? B : A; B: nextstate = C; C: nextstate = (~i): A : C; default: nextstate = A; endcase always_ff @(posedge ck, negedge r_l) if (~r_l) state <= A; else state <= nextstate; endmodule: explicitfsm module explicitfsm (output logic a, b, input ck, r_l, i); enum logic [:] {A=2'b, B=2'b, C=2'b} state, nextstate; always_comb begin a = 'b; b = nextstate == A; if ((state == C) && i) a = 'b; end always_ff @(posedge ck, negedge r_l) if (~r_l) state <= A; else case (state) A: state <= (i)? B : A; B: state <= C; C: state <= (~i): A : C; default: state <= A; endcase endmodule: explicitfsm This combines state and nextstate together. OKAY?? hmm, needs to change too. Why? 24

Combining parts of an explicit fsm Potential problem combining the output logic with the state update OK with a Mealy machine? OK with a Moore machine? module explicitfsm (output logic a, b, input ck, r_l, i); enum logic [:] {A=2'b, B=2'b, C=2'b} state, nextstate; always_comb begin a = 'b; b = nextstate == A; if ((state == C) && i) a = 'b; end always_comb case (state) A: nextstate = (i)? B : A; B: nextstate = C; C: nextstate = (~i): A : C; default: nextstate = A; endcase always_ff @(posedge ck, negedge r_l) if (~r_l) state <= A; else state <= nextstate; endmodule: explicitfsm 25

Models of Computation R / A B A B C F / Legend s s i/a,b / x/ C / inputs next state logic D Q output logic outputs D Q Combinational Logic Where we ve been What are the assumptions about how new values are generated in each of these? specifically combinational logic and STDs Can think of this as the beginnings of a behavioral hierarchy What s next up? 26