EECS150 - Digital Design Lecture 7 - Computer Aided Design (CAD) - Part II (Logic Simulation) Finite State Machine Review

Similar documents
EECS150 - Digital Design Lecture 6 - Logic Simulation

EECS150 - Digital Design Lecture 6 - Logic Simulation. Encoder Example

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

CS61C: Verilog Tutorial

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

EECS150 - Digital Design Lecture 8 - Hardware Description Languages

Outline. EECS150 - Digital Design Lecture 5 - Verilog 2. Structural Model: 2-to1 mux. Structural Model - XOR. Verilog Basics Lots of Examples

CSE140L: Components and Design Techniques for Digital Systems Lab

CSE140L: Components and Design

EEL 4783: HDL in Digital System Design

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

VHDL. VHDL History. Why VHDL? Introduction to Structured VLSI Design. Very High Speed Integrated Circuit (VHSIC) Hardware Description Language

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

Synthesizable Verilog

Two HDLs used today VHDL. Why VHDL? Introduction to Structured VLSI Design

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

EECS150 - Digital Design Lecture 23 - High-Level Design (Part 1)

VHDL for Synthesis. Course Description. Course Duration. Goals

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

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

Verilog for Synthesis Ing. Pullini Antonio

A Brief Introduction to Verilog Hardware Definition Language (HDL)

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Programming with HDLs

Problem Set 3 Solutions

Digital design laboratory 5

Lecture 32: SystemVerilog

Sequential Logic Design

HDLs and SystemVerilog. Digital Computer Design

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

Quick Introduction to SystemVerilog: Sequental Logic

ECE 551: Digital System *

Control in Digital Systems

Verilog for High Performance

I 3 I 2. ! Language of logic design " Logic optimization, state, timing, CAD tools

Intro to Digital Logic, Lab 5 Sequential Logic. Lab Objectives. Assigned Task Mapping sequential logic to the FPGA

Introduction to Verilog and ModelSim. (Part 6 State Machines)

Lab 7 (All Sections) Prelab: Introduction to Verilog

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay How it started!

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

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

Digital Integrated Circuits

EITF35: Introduction to Structured VLSI Design

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

Digital Design with SystemVerilog

EECS 270 Verilog Reference: Sequential Logic

VHDL: RTL Synthesis Basics. 1 of 59

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

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

! ISP (circa 1977) - research project at CMU " Simulation, but no synthesis

Writing Circuit Descriptions 8

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

Course Topics - Outline

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Lab 6 Debugging. Objective. Introduction. Prelab

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

What is Verilog HDL? Lecture 1: Verilog HDL Introduction. Basic Design Methodology. What is VHDL? Requirements

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

Verilog introduction. Embedded and Ambient Systems Lab

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

Midterm Exam Thursday, October 24, :00--2:15PM (75 minutes)

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

Digital Design and Computer Architecture

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

Verilog Nonblocking Assignments with Delays - Myths & Mysteries

Hardware Description Languages: Verilog. Quick History of HDLs. Verilog/VHDL. Design Methodology. Verilog Introduction. Verilog.

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Hardware Description Languages: Verilog

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>

EECS150 - Digital Design Lecture 09 - Parallelism

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

OUTLINE SYSTEM-ON-CHIP DESIGN. GETTING STARTED WITH VHDL September 3, 2018 GAJSKI S Y-CHART (1983) TOP-DOWN DESIGN (1)

Digital Design with FPGAs. By Neeraj Kulkarni

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

EE 4755 Digital Design Using Hardware Description Languages

CAD for VLSI Design - I. Lecture 21 V. Kamakoti and Shankar Balachandran

Design of Digital Circuits ( L) ETH Zürich, Spring 2017

Topics. Midterm Finish Chapter 7

Last Lecture: Divide by 3 FSM

Hardware Description Languages (HDLs) Verilog

Advanced Synthesis Techniques

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

CS 250 VLSI Design Lecture 11 Design Verification

ECE 587 Hardware/Software Co-Design Lecture 11 Verification I

Homework deadline extended to next friday

Verilog Overview. Verilog Overview. Simple Example. Simple Example. Simple Example. Simple Example

Hardware Description Language (HDL)

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

EEL 4783: HDL in Digital System Design

Lab #1. Topics. 3. Introduction to Verilog 2/8/ Programmable logic. 2. Design Flow. 3. Verilog --- A Hardware Description Language

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

Announcements. Midterm 2 next Thursday, 6-7:30pm, 277 Cory Review session on Tuesday, 6-7:30pm, 277 Cory Homework 8 due next Tuesday Labs: project

Transcription:

EECS150 - Digital Design Lecture 7 - Computer Aided Design (CAD) - Part II (Logic Simulation) Feb 9, 2010 John Wawrzynek Spring 2010 EECS150 - Lec7-CAD2 Page 1 Finite State Machine Review State Transition Diagram Implementation Circuit Diagram What does this one do? Holds a symbol to keep track of which bubble the FSM is in. Spring 2010 EECS150 - Lec7-CAD2 Page 2 Every Synchronous Digital System is a FSM. CL functions to determine output value and next state based on input and current state. out = f(in, current state) next state = f(in, current state)

Procedural Assignments The sequential semantics of the blocking assignment allows variables to be multiply assigned within a single always block. Unexpected behavior can result from mixing these assignments in a single block. Standard rules: i. Use blocking assignments to model combinational logic within an always block ( = ). ii. Use non-blocking assignments to implement sequential logic ( <= ). iii. Do not mix blocking and non-blocking assignments in the same always block. iv. Do not make assignments to the same variable from more than one always block. Spring 2010 EECS150 - Lec7-CAD2 Page 3 Finite State Machines module FSM1(clk, rst, in, out); input clk, rst; input in; Must use reset to force to initial state. output out; reset not always shown in STD // Defined state encoding: parameter IDLE = 2'b00; parameter S0 = 2'b01; Constants local to this module. parameter S1 = 2'b10; reg out; out not a register, but assigned in always block reg [1:0] state, next_state; THE register to hold the state of the FSM. // always block for state register always @(posedge clk) if (rst) state <= IDLE; else state <= next_state; Combinational logic signals for transition. A separate always block should be used for combination logic part of FSM. Next state and output generation. (Always blocks in a design work in parallel.) Spring 2010 EECS150 - Lec7-CAD2 Page 4

FSM CL block rewritten always @(state or in) case (state) IDLE : begin out = 1 b0; if (in == 1 b1) next_state = S0; always @* else next_state * for sensitivity = IDLE; list begin next_state S0 : begin = IDLE; Normal values: used out = 1 b0; out = 1 b0; unless specified below. case (state) if (in == 1 b1) next_state = S1; IDLE : else if (in next_state == 1 b1) = next_state IDLE; = S0; S0 : if (in == 1 b1) next_state = S1; Within case only need to S1 S1 : begin specify exceptions to the out out = = 1 b1; 1 b1; normal values. if if (in (in == == 1 b1) 1 b1) next_state next_state = = S1; S1; else next_state = IDLE; default: ; case default: begin Note: The use of blocking assignments allow signal module next_state values = IDLE; to be rewritten, simplifying the specification. out = 1 b0; case module Spring 2010 EECS150 - Lec7-CAD2 Page 5 Encoder Example Nested IF-ELSE might lead to priority logic Example: 4-to-2 encoder always @(x) begin : encode if (x == 4'b0001) y = 2'b00; else if (x == 4'b0010) y = 2'b01; else if (x == 4'b0100) y = 2'b10; else if (x == 4'b1000) y = 2'b11; else y = 2'bxx; This style of cascaded logic may adversely affect the performance of the circuit. Spring 2010 EECS150 - Lec7-CAD2 Page 6

Encoder Example (cont.) To avoid priority logic use the case construct: always @(x) begin : encode case (x) 4 b0001: y = 2'b00; 4 b0010: y = 2'b01; 4'b0100: y = 2'b10; 4'b1000: y = 2'b11; default: y = 2'bxx; case All cases are matched in parallel. Spring 2010 EECS150 - Lec7-CAD2 Page 7 Encoder Example (cont.) This circuit would be simplified during synthesis to take advantage of constant values and other Boolean equalities as follows: A similar simplification would be applied to the if-else version also. Spring 2010 EECS150 - Lec7-CAD2 Page 8

Encoder Example (cont.) If you can guarantee that only one 1 appears in the input, then simpler logic can be generated: always @(x) begin : encode if (x[0]) y = 2'b00; else if (x[1]) y = 2'b01; else if (x[2]) y = 2'b10; else if (x[3]) y = 2'b11; else y = 2'bxx; If the input applied has more than one 1, then this version functions as a priority encoder. The least significant 1 gets priority (the more significant 1 s are ignored). Again the circuit will be simplified when possible. Spring 2010 EECS150 - Lec7-CAD2 Page 9 Verilog in EECS150 Primarily use behavior modeling. With instantiation to build hierarchy and map to FPGA resources not supported by synthesis. Primary Style Guidelines: Favor continuous assign and avoid always blocks unless: no other alternative: ex: state elements, case they help readability and clarity of code: ex: large nested if-else-if Use named ports. Separate CL logic specification from state elements. Follow our rules for procedural assignments. Verilog is a big language. This is only an introduction. Our text book is a good source. Read and use chapter 4. When needed look at online IEEE Std 1364-2001 document. Be careful of what you read on the web! Many bad examples out there. We will be introducing more useful constructs throughout the semester. Stay tuned! Spring 2010 EECS150 - Lec7-CAD2 Page 10

Final thoughts on Verilog Examples Verilog may look like C, but it describes hardware! (Except in simulation test-benches - which actually behave like programs.) Multiple physical elements with parallel activities and temporal relationships. A large part of digital design is knowing how to write Verilog that gets you the desired circuit. First understand the circuit you want, then figure out how to code it in Verilog. If you do one of these activities without the other, you will struggle. These two activities will merge at some point for you. Be suspicious of the synthesis tools! Check the output of the tools to make sure you get what you want. Spring 2010 EECS150 - Lec7-CAD2 Page 11 EECS150 Design Methodology Hierarchically define structure and/or behavior of circuit. HDL Specification Simulation Functional verification. Synthesis Maps specification to resources of implementation platform (FPGA for us). Let s look at the other branch. Spring 2010 EECS150 - Lec7-CAD2 Page 12

Design Verification Industrial design teams sp a large percentage of the design time on design verification: Removing functional bugs, messaging the design to meet performance, cost, and power constraints. Particularly important for IC design, less so for FPGAs. A variety of tools and strategies are employed. Simulation: software that interprets the design description and mimics signal behavior and timing (and power consumption). Simulation provides better controllability and observability over real hardware. Saves on wasted development time and money. Emulation: hardware platform (usually FPGAs) are used to mimic behavior of another system. Fast simulation. Static Analysis: tools examines circuit structure and reports on expected performance, power, or compares alternative design representations looking for differences. Spring 2010 EECS150 - Lec7-CAD2 Page 13 Simulation Verilog/VHDL simulators use 4 signals values: 0, 1, X (unknown), Z (undriven) Simulation engine algorithm typically discrete event simulation ModelSim: waveform viewer, GUI. Spring 2010 EECS150 - Lec7-CAD2 Page 14

Discrete Event Simulation Engine A time-ordered list of events is maintained Event: a value-change scheduled to occur at a given time All events for a given time are kept together The scheduler removes events for a given time...... propagates values, executes models, and creates new events... all the events for time tj! time-ordered event list!! ti! tj! tk! tn! remove current events! Gate Outputs! updates! Scheduler! looks! at! Network Connections (fanouts)! schedules new event! executes! Gate Models! Slide from Thomas. The Verilog Hardware Description Language, By Thomas and Moorby, Kluwer Academic Publishers Spring 2010 EECS150 - Lec7-CAD2 Page 15 Simulation Testing Strategies Unit Testing: Large systems are often too complex to test all at once, so an bottom-up hierarchical approach. Sub-modules are tested in isolation. Combinational Logic blocks: when practical, exhaustive testing. Otherwise a combination of random and directed tests. Finite state machines: test every possible transition and output. Processors: use software to expose bugs. In all cases, the simulated output values are checked against the expected values. Expected values are derived through a variety of means: behavior model running along side the design under test precomputed inputs and outputs (vectors) co-simulation. Ex: C-language model runs along side ModelSim Spring 2010 EECS150 - Lec7-CAD2 Page 16

module testmux; reg a, b, s; wire f; reg expected; Testbench Top-level modules written specifically to test other modules. mux2 mymux (.select(s),.in0(a),.in1(b),.out(f)); initial begin s=0; a=0; b=1; expected=0; #10 a=1; b=0; expected=1; #10 s=1; a=0; b=1; expected=1; initial $monitor( Generally no ports. Note use of blocking assignments. "select=%b in0=%b in1=%b out=%b, expected out=%b time=%d", s, a, b, f, expected, $time); module // testmux Usually never synthesized to circuits. Therefore free to use simulation only language constructs. Instantiation of DUT (device under test). Initial block similar to always block without a trigger. It triggers once automatically at the beginning of simulation. (Also supported on FPGAs). #n used to advance time in simulation. Delays some action by a number of simulation time units. Note multiple initial blocks. $monitor triggers whenever any of its inputs change. Ss output to console. A variety of other system functions exist for displaying output and controlling the simulation. Most simulators also include a Spring 2010 EECS150 - Lec7-CAD2 way to view waveforms of a Page 17 set of signals. Mux4 Testbench module testmux4; Declaration and initialization all at once. reg [5:0] count = 6 b000000; Generally not available in synthesis. reg a, b, c, d, expected; reg [1:0] S; DUT instantiation wire f; mux4 mymux (.select(s),.in0(a),.in1(b),.in2(c),.in3(d),.out(f)); initial begin repeat(64) begin {S, d, c, b, a} = count[5:0]; $stop; module case (S) 2 b00: expected = a; 2 b01: expected = b; 2 b10: expected = c; 2 b11: expected = d; case // case(s) Enumerate all possible input patterns. #8 $strobe( "select=%b in0=%b in1=%b in2=%b in3=%b out=%b, expected=%b time=%d", S, a, b, c, d, f, expected, $time); #2 count = count + 1 b1; Wait a bit, then bump count. Apply pattern to DUT Behavioral model of mux4 $strobe displays data at a selected time. That time is just before simulation time is advanced (after all other events). Delay to allow mux outputs to stabilize. Here we assume mux delay < 8ns. Alternative to $strobe in this case, #8 if (f!= expected) $display( Mismatch:...); Spring 2010 EECS150 - Lec7-CAD2 Page 18

module testfsm; reg in; wire out; reg clk=0, rst; reg expect; DUT instantiation FSM1 myfsm (.out(out),.in(in),.clk(clk),.rst(rst)); always #5 clk = clk; initial begin rst=1; #10 in=0; rst=0; expect=0; #10 in=1; rst=0; expect=0; #10 in=0; rst=0; expect=0; #10 in=1; rst=0; expect=0; #10 in=1; rst=0; expect=1; #10 in=1; rst=0; expect=1; #10 in=0; rst=0; expect=0; #10 $stop; FSM Testbench Example Test all arcs. 100MHz clk signal start in IDLE self-loop transition to S0 transition to IDLE transition to S0 transition to S1 self-loop transition to IDLE Note: Input changes are forced to occur on negative edge of clock. always Strobe output occurs 1ns before rising edge of clock. begin #4 $strobe($time," in=%b, rst=%b, expect=%b out=%b", in, rst, expect, out); #6 ; Debug is easier if you have access to state value also. module Spring 2010 Either 1) bring out to EECS150 ports, - Lec7-CAD2 or 2) use waveform viewer. Page 19 Final Words (for now) on Simulation Testing is not always fun, but you should view it as part of the design process. Untested potentially buggy designs are a dime-a-dozen. Verified designs have real value. Devising a test strategy is an integral part of the the design process. It shows that you have your head around the design. It should not be an afterthought. Spring 2010 EECS150 - Lec7-CAD2 Page 20