Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania 18042 ECE 491 - Senior Design I Lecture 5 - Coding Guidelines;

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 HDL -Introduction
CS 3850 Lecture 6 Tasks and Functions. 6.1 Tasks and Functions Tasks are like procedures in other programming languages. e. g., tasks may have zero or.
Simulation executable (simv)
Synchronous Sequential Logic
Combinational Logic.
Chapter 11 Verilog HDL Application-Specific Integrated Circuits Michael John Sebastian Smith Addison Wesley, 1997.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
16/04/20151 Hardware Descriptive Languages these notes are taken from Mano’s book It can represent: Truth Table Boolean Expression Diagrams of gates and.
ECE 551 Digital System Design & Synthesis Lecture 08 The Synthesis Process Constraints and Design Rules High-Level Synthesis Options.
2/9/20031 ECE 551: Digital System Design & Synthesis Lecture Set 4 4.1: Verilog – Procedural Assignments &Scheduling Semantics 4.2: Verilog – More Behavioral.
1 COMP541 Sequential Circuits Montek Singh Sep 17, 2014.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI System Design Lecture 3 - Verilog Delay.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI System Design Lecture 7 - Synchronizers.
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 11 - Timing and Metastability.
ENEE 408C Lab Capstone Project: Digital System Design Verilog Tutorial Class Web Site:
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 12 - Metastability.
VHDL Intro What does VHDL stand for? VHSIC Hardware Description Language VHSIC = Very High Speed Integrated Circuit Developed in 1982 by Govt. to standardize.
Silicon Programming--Intro. to HDLs1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Verilog 2 (Sequential.
ECEN ECEN475 Introduction to VLSI System Design Verilog HDL.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI System Design Lecture 4 - Advanced Verilog.
ELEN 468 Advanced Logic Design
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 2 FPGAs & Verilog.
Digital System Design Verilog ® HDL Tasks and Functions Maziar Goudarzi.
2/3/03ΗΥ220 - Μαυροειδής Ιάκωβος1 Delays in Behavioral Verilog - Interassignment Delay  Key idea: unlike blocking delay, RHS is evaluated before delay.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 6 - Behavioral Modeling.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Overview Logistics Last lecture Today HW5 due today
Tasks and Functions Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar Gudarzi.
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
Introduction to FPGA AVI SINGH. Prerequisites Digital Circuit Design - Logic Gates, FlipFlops, Counters, Mux-Demux Familiarity with a procedural programming.
ECE 2372 Modern Digital System Design
Verilog Language Concepts
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 9 - Coding Guidelines.
1 An Update on Verilog Ξ – Computer Architecture Lab 28/06/2005 Kypros Constantinides.
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.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHSIC Hardware Description Language  Required Reading: –These Slides –VHDL Tutorial  Very High Speed.
1 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Slide 1 2. Verilog Elements. Slide 2 Why (V)HDL? (VHDL, Verilog etc.), Karen Parnell, Nick Mehta, “Programmable Logic Design Quick Start Handbook”, Xilinx.
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,
Modern VLSI Design 4e: Chapter 8 Copyright  2008 Wayne Wolf Topics Modeling with hardware description languages (HDLs).
Modern VLSI Design 3e: Chapter 8 Copyright  1998, 2002 Prentice Hall PTR Topics n Modeling with hardware description languages (HDLs).
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
1 Verilog Digital System Design Z. Navabi, 2006 Verilog Language Concepts.
The Verilog Hardware Description Language. GUIDELINES How to write HDL code: How to write HDL code:
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
04/26/20031 ECE 551: Digital System Design & Synthesis Lecture Set : Introduction to VHDL 12.2: VHDL versus Verilog (Separate File)
COMP541 Sequential Circuits
03/31/031 ECE 551: Digital System Design & Synthesis Lecture Set 8 8.1: Miscellaneous Synthesis (In separate file) 8.2: Sequential Synthesis.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 12 - Introduction.
FPGA-Based System Design Copyright  2004 Prentice Hall PTR Topics n Modeling with hardware description languages (HDLs).
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Chapter1: Introduction Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 1-1 Chapter 1: Introduction Prof. Ming-Bo.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
Verification Presentation to SystemVerilog Basic Committee Peter Flake Nov 15, 2002.
Structural Description
Overview Logistics Last lecture Today HW5 due today
‘if-else’ & ‘case’ Statements
The Verilog Hardware Description Language
ECE 551: Digital System Design & Synthesis
COE 202 Introduction to Verilog
Presentation transcript:

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 5 - Coding Guidelines; Simulation & Delay Fall 2007 Read Verilog Handout Section 7

ECE 491 Fall 2007Lecture 5 - Verilog Simulation2 Today’s Outline  Verilog Coding Guidelines  A brief aside: timing and clocks  Verilog Part 3  Simulation Basics of Event-Driven Simulation Delay Modeling  initial blocks  Functions  Tasks  System Tasks  Recent developments in Verilog

ECE 491 Fall 2007Lecture 5 - Verilog Simulation3 Verilog Coding Guidelines  Why bother with coding guidelines?  Try to avoid common errors and pitfalls Latch inferences Simulation/Synthesis mismatch Timing problems  Try to make designer’s intent clear To others who use your design s When you use or re-use your own designs

ECE 491 Fall 2007Lecture 5 - Verilog Simulation4 Verilog Coding Guidelines - 1  Use one file for each module.  Include a header block in each file that includes:  Your names  Brief description of module  History  Usage guidelines  Use “template” from ISE “Edit” menu  Use comments liberally.  Use meaningful signal names.  Be consistent using capitalization and underscores.  Properly indent your code, as shown in examples.

ECE 491 Fall 2007Lecture 5 - Verilog Simulation5 Verilog Coding Guidelines - 2  Partition your design into leaf cells and non-leaf cells.  Leaf cells contain assign statements or always blocks but do not instantiate other cells.  Non-leaf cells instantiate other cells but contain no logic. (Minor exceptions OK to keep the code readable.)  Use assign statements for comb. logic when practical.  Use only nonblocking (<=) assignments in always blocks that model sequential logic.  Use only blocking (=) assignments in always blocks that model combinational logic.  Avoid latch inferences in combinational always blocks!

ECE 491 Fall 2007Lecture 5 - Verilog Simulation6 Verilog Coding Guidelines - 3  Use only positive edge-triggered flip-flops for storage  Use symbolic constants (parameters) to define state names and constants  Use synchronizer flip-flops for asynchronous inputs  Keep number of separate clock signals to a minimum  When multiple clocks are used:  Don’t mix clocks - partition design into clock domains  Use synchronizer flip-flops when passing from one clock domain to another

ECE 491 Fall 2007Lecture 5 - Verilog Simulation7 Review - Flip-Flop Timing Characteristics  Propagation Delay t CQ  Setup time t setup  Hold time t h D Q clk D t setup thth CLK Q t CQ

ECE 491 Fall 2007Lecture 5 - Verilog Simulation8 What Limits Clock Frequency?  Propagation delay - t prop Logic (including register outputs) Interconnect  Register setup time - t setup Adder Mux Combinational Logic Register Output Register Input Clock t prop t setup t clock > t prop + t setup t clock = t prop + t setup + t slack

ECE 491 Fall 2007Lecture 5 - Verilog Simulation9 Timing in FPGA Design - Constraints  The constraints file specifies timing using the TIMESPEC directive #TIMESPEC = FROM : : TO : : ;  In the “s3board.v” file - using predefined groups # Time specifications for 50MHz clock # #TIMESPEC TS01 = FROM : FFS : TO : FFS : 20 ns; #TIMESPEC TS02 = FROM : RAMS : TO : FFS : 20 ns; #TIMESPEC TS03 = FROM : FFS : TO : RAMS : 20 ns; #TIMESPEC TS04 = FROM : RAMS : TO : RAMS : 20 ns; #TIMESPEC TS05 = FROM : FFS : TO : PADS : 20 ns; #TIMESPEC TS06 = FROM : PADS : TO : FFS : 20 ns; #TIMESPEC TS07 = FROM : PADS : TO : RAMS : 20 ns; #TIMESPEC TS08 = FROM : RAMS : TO : PADS : 20 ns;

ECE 491 Fall 2007Lecture 5 - Verilog Simulation10 Synchronizers  Key idea: make sure inputs don’t change at a “bad time” in sequential circuits in1 in2 in in1’ in clk in1 NS 11 transient

ECE 491 Fall 2007Lecture 5 - Verilog Simulation11 Adding Synchronizers  Add a D Flip-Flop on each asynchronous input  Synchronize each input only once DQ clk in2_a in2_s DQ in1_a in1_s

ECE 491 Fall 2007Lecture 5 - Verilog Simulation12 Single-Clock Sequential Logic  Clock arrives at all flip-flops simultaneously  Timing analysis verifies clock period constraints  But, not all systems use a single clock! a b c q clock) DQ clk

ECE 491 Fall 2007Lecture 5 - Verilog Simulation13 Dealing Multiple Clocks  Multiple clocks are not synchronized!  Must synchronize connecting signals a b c q clk1) DQ clk1 d e f r clk2) DQ clk2 clk1 clk2 DQ Synchronizer

ECE 491 Fall 2007Lecture 5 - Verilog Simulation14

ECE 491 Fall 2007Lecture 5 - Verilog Simulation15 Verilog and Event-Driven Simulation  Key idea: model circuit operation as sequence of events that take place at specific times  Input events - when input changes  Output events - response to input events (only generated when output changes) A B C A B C delay=4 input event output event

ECE 491 Fall 2007Lecture 5 - Verilog Simulation16 Event-Driven Simulation  Example: Modeling and AND Gate  Input events: changes on A, B input net  Output events: changes on C output net after delay A B C A B C t=5 A=1 t=17 B=1 t=33 B=0 t=29 C=1 delay=12 t=45 C=0 Input Events Output Events

ECE 491 Fall 2007Lecture 5 - Verilog Simulation17 Event-Driven Simulation  Output events from AND = input events for OR  Simulation time “jumps” from event to event A B C A B C delay=3 D E delay=4 D E

ECE 491 Fall 2007Lecture 5 - Verilog Simulation18 Notes about Event-Driven Simulation  Why use event-driven simulation? Because it's fast  Only model when signals change  Loss of accuracy: assumes ideal logical behavior  What are the alternatives?  Circuit simulation (e.g. PSpice) Numerical model of continuous behavior More accurate, but slower  Cycle-Level Compiled code simulation Model behavior in each clock cycle Faster, but doesn’t model delay

ECE 491 Fall 2007Lecture 5 - Verilog Simulation19 Event-Driven Simulation (cont'd)  Processing Events - Data Structures  Event - specifies time event will occur net where signal will change new value of net  Event Queue - data structure that sorts events by time front of queue - earliest event back of queue - latest event also called a timing wheel

ECE 491 Fall 2007Lecture 5 - Verilog Simulation20 Event-Driven Simulation - Algorithm  Processing Events - Simulation Algorithm initialization: set all nets & regs to ‘x’ while (event queue not empty) { current_event = "earliest" event in queue; current_time = current_event.time; current_event.net.value = current_event.value; for (each module input connected to net) { evaluate(module) if output of module changes { create new event to represent output change add new event to queue } } }

ECE 491 Fall 2007Lecture 5 - Verilog Simulation21 Verilog Simulation Model  assign statement  executes when event changes any input  produces output event when output values changes  always block  executes when event changes variable in sensitivity list  produces output events when outputs change assign y = ~a; or b) x = a ^ b;

ECE 491 Fall 2007Lecture 5 - Verilog Simulation22 Delays in Event-Driven Simulation  Two kinds of delays supported:  Inertial delays - reflects limited response time in real gates  Transport delays - try to model delay through a wire

ECE 491 Fall 2007Lecture 5 - Verilog Simulation23 Inertial Delays  What happens here? A B C A B C delay=t d t1t1 t2t2 tdtd t 2 - t 1 > t d A B C A B C delay=t d t1t1 t2t2 tdtd t 2 - t 1 < t d Event-driven model: Narrow Pulse Real gate: No change (why?)

ECE 491 Fall 2007Lecture 5 - Verilog Simulation24 Inertial Delays in Event-Driven Simulators  Each signal change is scheduled in event queue  When scheduling, compare to most recent change to calculate “pulse width”  If (pulse_width < prop_delay) deschedule both events 3 Delay = De-scheduled Events

ECE 491 Fall 2007Lecture 5 - Verilog Simulation25 Transport Delays  What happens here? A C delay=t d Long Wire B A B tdtd Change propagated independent of pulse width

ECE 491 Fall 2007Lecture 5 - Verilog Simulation26 Modeling Delays in Verilog  Delays in Structural Verilog  Gate primitives: inertial delays and #5 g1(o1, a, b);  Net delays (transport) wire #5 w1;  More complex modules: specify  Delays in Behavioral Verilog  assign statements assign #10 a = x & y;  always & initial blocks blocking delay #10 a = x +y; interassignment delay a = #10 x + y;

ECE 491 Fall 2007Lecture 5 - Verilog Simulation27 Structural Delay - Gate Primitives and G1 (y1, a, b); and #5 G2 (y2, a, b); and #(7,5) G3 (y3, a, b); and #(6:7:8,4:5:6) G4 (y4, a, b); buf_if1 #(6,5,2) B1 (y5, a, enb); // 3-state buf rising delayfalling delaysingle delay value rising delay min : typ : max falling delay min : typ : max no delay value (delay = 0)rising delayturnoff delay falling delay

ECE 491 Fall 2007Lecture 5 - Verilog Simulation28 Delay in assign statements  Delay specified as in structural specifications assign #5 y1 = a & b; assign (#4,#5,$6) y2 = a & b;  Specifies inertial delay

ECE 491 Fall 2007Lecture 5 - Verilog Simulation29 Delays in Behavioral Verilog - Blocking Delay  Delay control operator - #n  Simulation effect: suspends simulation for n time units  Example: clock generator always begin clk = 0; #50 clk = 1; #50 ; end null statement (suspends simulation 50 time units)

ECE 491 Fall 2007Lecture 5 - Verilog Simulation30 Delays in Behavioral Verilog - Interassignment Delay  Key idea: unlike blocking delay, RHS is evaluated before delay  With blocking assignments: a = #5 b + c; d = a;  With nonblocking assignments: a <= #5 b + c; d = a; b + c evaluated; change in a scheduled delayed until 5 time units elapse b + c evaluated; change in a scheduled executes immediately; gets OLD value of a!

ECE 491 Fall 2007Lecture 5 - Verilog Simulation31 Representing Time in Verilog  Verilog uses “dimensionless” time units  Mapping time units to “real” time: `timescale `timescale /  Examples `timescale 1ns / 1ps `timescale 10ns / 100ps  Each module can have a different timescale (but this is not necessarily a good idea!) Time Units of # Delay Values Minimum step time used by simulator

ECE 491 Fall 2007Lecture 5 - Verilog Simulation32 Simulation Time in Verilog: # and `timescale  `timescale controls simulation time `timescale time_unit time_precision `timescale 1ns 100ps  # operator specifies delay in terms of time units `timescale 1ns 100ps #5 // delays 5*1ns = 5ns; // rounds times to 100ps `timescale 4ns 1ns #3 // delays 3*4ns = 12ns // rounds times to 1ns

ECE 491 Fall 2007Lecture 5 - Verilog Simulation33 What happens when no delays are specified?  Each output event has a “delta” delay  Events processed in order of scheduling

ECE 491 Fall 2007Lecture 5 - Verilog Simulation34 initial statements  Specify code to be executed on simulation startup initial sequential_statement  Not supported in synthesis - tell synthesis to ignore using synthesis directives (“pragmas”)  Very useful in testbenches! // synthesis translate_off initial begin … code to generate input stimulus & check outputs end // synthesis translate_on Synthesis Directive

ECE 491 Fall 2007Lecture 5 - Verilog Simulation35 Verilog functions  Function Declaration: function [ range_or_type ] fname; input_declarations statement endfunction  Return value: function body must assign: fname = expression;  Function call: fname ( expression,… )

ECE 491 Fall 2007Lecture 5 - Verilog Simulation36 Verilog Functions (cont'd)  Function characteristics:  returns a single value (default: 1 bit)  can have multiple input arguments (must have at least one)  can access signals in enclosing module  can call other functions, but not tasks  cannot call itself (no recursion)  executes in zero simulation time (no timing ops allowed)  Synthesized as combinational logic (if proper subset is used)

ECE 491 Fall 2007Lecture 5 - Verilog Simulation37 Verilog Functions (cont'd)  Function examples: function calc_parity; input [31:0] val; begin calc_parity = ^val; end endfunction function [15:0] average; input [15:0] a, b, c, d; begin average = (a + b + c + d) >> 2; end endfunction;

ECE 491 Fall 2007Lecture 5 - Verilog Simulation38 Verilog Tasks  Similar to procedures in VHDL, Pascal  Multiple input, output, and inout arguments  No explicit return value (use output arguments instead)  No recursion allowed  Can "enable" (call) other tasks and functions  May contain delay, event, and timing control statements (but not in synthesis)

ECE 491 Fall 2007Lecture 5 - Verilog Simulation39 Verilog Tasks (cont'd)  Task example: task ReverseByte; input [7:0] a; output [7:0] ra; integer j; begin for (j = 7; j >=0; j=j-1) ra[j] = a[7-j]; end endtask // Adapted from "Verilog HDL Synthesis: A Practical // Primer", by J. Bhasker

ECE 491 Fall 2007Lecture 5 - Verilog Simulation40 System Tasks and Functions  Tasks and functions defined for simulator control  All named starting with " $ " (e.g., $monitor )  Standard - same for every simulator (almost)  See Verilog Quick Reference Card, Section 8 for full list of system tasks  Example system task: $display $display("format-string", expr1, …, exprn); format-string - regular ASCII mixed with formatting characters %d - decimal, %b - binary, %h - hex, %t - time, etc. other arguments: any expression, including wire s and reg s $display("Error at time %t: value is %h, expected %h", $time, actual_value, expected_value);

ECE 491 Fall 2007Lecture 5 - Verilog Simulation41 Some useful System Tasks  $time - return current simulation time  $monitor - print message when values change $monitor("cs=%b, ns=%b", cs, ns)  Simulation control tasks  $stop - interrupt simulation  $finish - terminate simulation  Extensive file I/O also available

ECE 491 Fall 2007Lecture 5 - Verilog Simulation42 Verilog Stuff we Won’t Talk About  Parallel Blocks - fork / join  Procedural continuous assignment  assign / deassign as procedural statements  Not synthesizeable  User-Defined Primitives (UDPs) - low-level gate models  Programming Language Interface (PLI) - for linking to programming code in C/C++

ECE 491 Fall 2007Lecture 5 - Verilog Simulation43 Verilog - Recent Developments  Verilog 2001(IEEE Standard) - Adds several new features  Cleaner module specifications  Lots of “syntatic sugar” - features that make language “nicer” to use  System Verilog  Meant to allow verification and HW/SW codesign  Integrates many features of C: C primitive types Structures Enumerated Types Recursion

ECE 491 Fall 2007Lecture 5 - Verilog Simulation44 Verilog 2001 Port Declarations  Combines port list and declarations module counter( input clk, input enb, output reg [3:0] Q, output carry); clk) if (enb) Q <= Q + 1; endmodule

ECE 491 Fall 2007Lecture 5 - Verilog Simulation45 HDLs - What Else is Out There?  VHDL  More general; more verbose  Continued extension - VHDL 2001 is current standard  SystemC  C++ class library of synthesizeable constructs  Meant for large system hardware/software codesign  Reference:  Verification Languages  e - Cadence  Vera - Synopsys Focus on constrained random verification

ECE 491 Fall 2007Lecture 5 - Verilog Simulation46 Coming Up  Verification and Testbenches  Serial Data Communication