EECS150 - Digital Design Lecture 6 - Logic Simulation

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

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

EECS150 - Digital Design Lecture 8 - Hardware Description Languages

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

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

EEL 4783: HDL in Digital System 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

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

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

Verilog for Synthesis Ing. Pullini Antonio

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

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

Sequential Logic Design

Synthesizable Verilog

Verilog Synthesis and FSMs. UCB EECS150 Fall 2010 Lab Lecture #3

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

Control in Digital Systems

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

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

Problem Set 3 Solutions

Quick Introduction to SystemVerilog: Sequental Logic

FSM and Efficient Synthesizable FSM Design using Verilog

EECS 270 Verilog Reference: Sequential Logic

VHDL for Synthesis. Course Description. Course Duration. Goals

Programming with HDLs

EECS Components and Design Techniques for Digital Systems. Lec 07 PLAs and FSMs 9/ Big Idea: boolean functions <> gates.

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

CS 250 VLSI Design Lecture 11 Design Verification

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

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

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

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

Department of Computer Science and Electrical Engineering. CMPE 415 Verilog Events Timing and Testbenches Prof. Ryan Robucci

ECE 551: Digital System *

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Digital Design with SystemVerilog

Lab 7 (All Sections) Prelab: Introduction to Verilog

Lecture 32: SystemVerilog

Digital design laboratory 5

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

Verilog for High Performance

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

Hardware Description Languages: Verilog

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 Verilog Finite State Machines

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

Digital Design and Computer Architecture

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

Lab 2 Designing with Verilog

ECE 353 Lab 3 (Verilog Design Approach)

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

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

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

Last Lecture: Divide by 3 FSM

N-input EX-NOR gate. N-output inverter. N-input NOR gate

Course Topics - Outline

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

Lecture 15: System Modeling and Verilog

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

VERILOG. Deepjyoti Borah, Diwahar Jawahar

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

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

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

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

Designing Safe Verilog State Machines with Synplify

Digital Integrated Circuits

Finite State Machines

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

Lab 6 Debugging. Objective. Introduction. Prelab

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

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

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

Advanced Synthesis Techniques

Image Courtesy CS250 Section 2. Yunsup Lee 9/4/09

EITF35: Introduction to Structured VLSI Design

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

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

EEL 4783: HDL in Digital System Design

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

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

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

Introduction to Verilog/System Verilog

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

Verilog introduction. Embedded and Ambient Systems Lab

Behavioral Modeling and Timing Constraints

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

101-1 Under-Graduate Project Digital IC Design Flow

ECE331: Hardware Organization and Design

Verilog Nonblocking Assignments with Delays - Myths & Mysteries

Hardware Description Language (HDL)

Transcription:

EECS150 - Digital Design Lecture 6 - Logic Simulation Sep. 17, 013 Prof. Ronald Fearing Electrical Engineering and Computer Sciences University of California, Berkeley (slides courtesy of Prof. John Wawrzynek) http://www-inst.eecs.berkeley.edu/~cs150 1 Outline Recap: FSM in verilog always @(*) blocking for CL always @(posedge clock) non-blocking for state update logic synthesis More synthesis: case vs if else More on Verilog Logic Synthesis 1

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. 3 FSM CL block rewritten always @(state or in) case (state) IDLE : out = 1 b0; if (in == 1 b1) next_state = S0; always @* * for sensitivity list else next_state = IDLE; next_state S0 : = IDLE; Normal values: used unless out = 1 b0; specified below. out = 1 b0; case (state) if (in == 1 b1) next_state = S1; IDLE : else if (in next_state == 1 b1) = next_state IDLE; = S0; Within case only need to S0 : if (in == 1 b1) next_state = S1; specify exceptions to the S1 S1 : normal values. out out = = 1 b1; 1 b1; if if (in (in == == 1 b1) 1 b1) next_state next_state = = S1; S1; else next_state = IDLE; default: ; case Note: The use of blocking assignments allow signal default: values to be rewritten, simplifying the specification. module next_state = IDLE; out = 1 b0; case module 4

Encoder Example Nested IF-ELSE might lead to priority logic Example: 4-to- encoder always @(x) : encode if (x == 4'b0001) y = 'b00; else if (x == 4'b0010) y = 'b01; else if (x == 4'b0100) y = 'b10; else if (x == 4'b1000) y = 'b11; else y = 'bxx; This style of cascaded logic may adversely affect the performance of the circuit. 0001 11 xx or 00 1 0 S 1000 5 Encoder Example (cont.) To avoid priority logic use the case construct: always @(x) : encode case (x) 4 b0001: y = 'b00; 4 b0010: y = 'b01; 4'b0100: y = 'b10; 4'b1000: y = 'b11; default: y = 'bxx; case All cases are matched in parallel. 6 3

Encoder Example (cont.) This circuit would be simplified during synthesis to take advantage of constant values as follows and other Boolean equalities: check default: 4 b0000 A similar simplification would be applied to the if-else version also. 7 Verilog in EECS150 We use behavior modeling along with instantiation to 1) 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 clarity of code & possibly circuit efficiency : ex: case vs, large nested if else 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. 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! 8 4

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. 9 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. 10 5

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. 11 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... Slide from Thomas. The Verilog Hardware Description Language, By Thomas and Moorby, Kluwer Academic Publishers 1 6

Simulation Testing Strategies Unit Testing: Large systems are often too complex to test all at once, so instead a 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. (e.g. 16 state variable FSM using one hot encoding and 8 inputs: 4 tests) 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: HDL behavior model running along side the design under test precomputed inputs and outputs (vectors) Fall co-simulation. 013 Ex: C-language EECS150 model - Lec06-sim runs along side ModelSim Page 13 Testbench Top-level modules written specifically to test other modules. module testmux; reg a, b, s; wire f; reg expected; mux mymux (.select(s),.in0(a),.in1(b),.out(f)); initial 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. b a 1 S 0 f Assignments used to set inputs. 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 ning 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. "select=%b in0=%b in1=%b out=%b, expected out=%b time=%d", $monitor triggers whenever s, a, b, f, expected, $time); any of its inputs change. module // testmux A variety of other system functions exist for Ss output to console. displaying output and controlling the simulation. Most simulators also include a Fall 013 EECS150 - Lec06-sim way to view waveforms of a set Page 14 of signals. 7

Mux4 Testbench module testmux4; Declaration and initialization all at once. Generally reg [5:0] count = 6 b000000; not available in synthesis. reg a, b, c, d, expected; reg [1:0] S; wire f; DUT instantiation mux4 mymux (.select(s),.in0(a),.in1(b),.in(c),.in3(d),.out(f)); initial repeat(64) {S, d, c, b, a} = count[5:0]; case (S) b00: expected = a; b01: expected = b; b10: expected = c; b11: expected = d; case // case(s) #8 $strobe( "select=%b in0=%b in1=%b in=%b in3=%b out=%b, expected=%b time=%d", S, a, b, c, d, f, expected, $time); # count = count + 1 b1; $stop; module Enumerate all possible input patterns. 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 < ns. Alternative to $strobe in this case, #8 if (f!= expected) $display( Mismatch:...); 15 0 8 10 FSM Testbench Example Test all arcs. 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; 100MHz clk signal initial 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; always start in IDLE self-loop transition to S0 transition to IDLE transition to S0 transition to S1 self-loop transition to IDLE Strobe output occurs 1ns before rising edge of clock. Note: Input changes are forced to occur on negative edge of clock. #4 $strobe($time," in=%b, rst=%b, expect=%b out=%b", in, rst, expect, out); #6 ; module Fall 013 Debug is easier if you have access to state value also. Either 1) bring out to EECS150 ports, or - Lec06-sim ) use waveform viewer. Page 16 8

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. Verilog terms: initial, #, strobe, monitor, repeat 17 9