Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

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

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

One and a half hours. Section A is COMPULSORY

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

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

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

Quick Introduction to SystemVerilog: Sequental Logic

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

CSE140L: Components and Design Techniques for Digital Systems Lab

CSE140L: Components and Design

Verilog Coding Guideline

FSM and Efficient Synthesizable FSM Design using Verilog

Sequential Logic Design

ECE 551: Digital System *

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

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

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

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

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

Synthesizable Verilog

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

Laboratory Exercise 7

Digital Integrated Circuits

EEL 4783: HDL in Digital System Design

Lecture 15: System Modeling and Verilog

Verilog introduction. Embedded and Ambient Systems Lab

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

DIGITAL SYSTEM DESIGN

Course Topics - Outline

Finite State Machines

Synthesis of Combinational and Sequential Circuits with Verilog

Verilog for High Performance

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

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

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

Modeling Sequential Circuits in Verilog

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

Parallel versus serial execution

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

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

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

ECEN 468 Advanced Digital System Design

Digital Integrated Circuits

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

FPGA: FIELD PROGRAMMABLE GATE ARRAY Verilog: a hardware description language. Reference: [1]

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

RTL Design (Using ASM/SM Chart)

Control in Digital Systems

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

EECS 270 Verilog Reference: Sequential Logic

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

Verilog for Synthesis Ing. Pullini Antonio

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

Lecture 32: SystemVerilog

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

Digital Design Using Digilent FPGA Boards -- Verilog / Active-HDL Edition

Writing Circuit Descriptions 8

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

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

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

Mealy and Moore examples

Problem Set 2 Solutions

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

EN164: Design of Computing Systems Lecture 06: Lab Foundations / Verilog 2

Finite State Machines

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Course Topics - Outline

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

Hardware Description Language (HDL)

HANSABA COLLEGE OF ENGINEERING & TECHNOLOGY (098) SUBJECT: DIGITAL ELECTRONICS ( ) Assignment

EECS150 - Digital Design Lecture 10 Logic Synthesis

VHDL: RTL Synthesis Basics. 1 of 59

Injntu.com Injntu.com Injntu.com R16

Register Transfer Level in Verilog: Part I

One and a half hours. Section A is COMPULSORY UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Federal Urdu University of Arts, Science and Technology, Islamabad VLSI SYSTEM DESIGN. Prepared By: Engr. Yousaf Hameed.

Modeling of Finite State Machines. Debdeep Mukhopadhyay

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

Finite State Machines

B.10 Finite State Machines B.10

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

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

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

Topics. Midterm Finish Chapter 7

Registers and finite state machines

Digital Design with FPGAs. By Neeraj Kulkarni

problem maximum score 1 10pts 2 8pts 3 10pts 4 12pts 5 7pts 6 7pts 7 7pts 8 17pts 9 22pts total 100pts

VERILOG: FLIP-FLOPS AND REGISTERS

Laboratory Exercise 3

Digital System Design with SystemVerilog

Finite-State Machine (FSM) Design

Creating Safe State Machines

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Microcomputers. Outline. Number Systems and Digital Logic Review

Verilog Essentials Simulation & Synthesis

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

Transcription:

Design of Datapath Controllers Lecturer: Wein-Tsung Shen Date: 2005.04.01 ACCESS IC LAB

Outline Sequential Circuit Model Finite State Machines Useful Modeling Techniques pp. 2

Model of Sequential Circuits Modeling system outputs depend not only on current input Depend on inputs Depend on current state Fundamental components Combinational circuits Memory elements Inputs Combinational Logic Outputs Current State Memory Elements Next State clock pp. 3

Types of Memory Elements Flip-Flop Latch Registers Others Register Files Cache Flash memory ROM RAM pp. 4

D-FF vs. D-Latch D FF is edge sensitive (can be either positive or negative edge) At trigger edge of clock, input transferred to output Latch is level sensitive (can be either active-high or active-low) When clock is active, input passes to output (transparent) When clock is not active, output stays unchanged in out in D Q clk D Q FF clk Latch E out in clk out in clk out pp. 5

FF Based, Edge Trigger Clocking T d = delay of combinational logic T cycle = cycle time of clock Duty cycle does not matter Timing requirements for T d T dmax < T cycle T setup T cq T dmin > T hold T cq no setup time violation no hold time violation clk FF Combinational Logic Td FF T cycle T cq T d T setup pp. 6

Latch Based, Single Phase Clocking Aka. Pulse Mode clocking T cycle = cycle time of clock; T w = pulse width of clock Timing requirements for T d T dmax < T cycle T dq T dmin > T w T dq data latched correctly no racing through next stage clk Latch Combinational Logic Td Latch T w T cycle T dq T d pp. 7

Flip-Flop Based Larger in area Comparison Larger clocking overhead (T setup, T cq ) + Design more robust Only have to worry about T dmax T dmin usually small, can be easily fixed by buffer + Pulse width does not matter Latch Based Single Phase + Smaller area + Smaller clocking overhead ( only T dq ) Worry about both T dmax and T dmin Pulse width DOES matter (unfortunately, pulse width can vary on chip) pp. 8

D Flip-Flop Flop with Positive-Edge Clock module flop (Q, D, C, S, R); output Q; // Flip-Flop Output input D; // Data Input input C; // Positive Edge Clock input E; // Clock Enable D C Q reg Q; // Register Type always @(posedge C) begin if (E) // Check Enable Q <= D; end endmodule D E C Q pp. 9

D Flip-Flop Flop with Positive-Edge Clock module flop (Q, D, C, S, R); output Q; // Flip-Flop Output input D; // Data Input input C; // Positive Edge Clock input R; // Asynchronous Reset input S; // synchronous Set reg Q; // Register Type always @(posedge C or negedge R) begin if (!R) Q <= 1 b0; else if (S) Q <= 1 b1; else Q <= D; end endmodule S D C R Q pp. 10

D-Latch Active High with Clear/Preset module flop (Q, D, G, C, P); output Q; // Flip-Flop Output input D; // Data Input input G; // Positive Gate input C; // synchronous Clear input P; // synchronous Preset reg Q; // Register Type always @(D or G or C or P) begin if (!C) Q <= 1 b0; else if (P) Q <= 1 b1; else if (G) Q <= D; end endmodule P D G C Q pp. 11

Finite State Machine ACCESS IC LAB

Finite State Machine Used control the circuit core Partition FSM and non-fsm part Controller Non-FSM Circuit core FSM pp. 13

Finite State Machines Synchronous (i.e. clocked) finite state machines (FSMs) have widespread application in digital systems, e.g. as datapath controllers in computational units and processors. Synchronous FSMs are characterized by a finite number of states and by clock-driven state transitions. Mealy Machine: The next state and the outputs depend on the present state and the inputs. Moore Machine: The next state depends on the present state and the inputs, but the output depends on only the present state. Mealy machine Moore machine Inputs Next State and Output Combinational Logic State Register Outputs Inputs Next State Combinational Logic clock State Register Output Combinational Logic Outputs clock pp. 14

What is FSM A model of computation consisting of a set of states, (limited number) a start state, input symbols, a transition function that maps input symbols and current states to a next state. pp. 15

Memory Elements (ME) Elements of FSM Memorize Current States (CS) Usually consist of FF or latch N-bit FF have 2 n possible states Next-state Logic (NL) Combinational Logic Produce next state Based on current state (CS) and input (X) Output Logic (OL) Combinational Logic Produce outputs (Z) Based on current state, or Based on current state and input pp. 16

Output is function of both Input and current state Mealy Machine pp. 17

Output is function of CS only Not function of inputs Moore Machine pp. 18

Mealy Finite State Machine A serially-transmitted BCD (8421 code) word is to be converted into an Excess-3 code. An Excess-3 code word is obtained by adding 3 to the decimal value and taking the binary equivalent. Excess-3 code is self-complementing [Wakerly, p. 80], i.e. the 9's complement of a code word is obtained by complementing the bits of the word. Decimal 8-4-2-1 Excess-3 Digit Code Code (BCD) B in = 8 bcd LSB MSB B out = 8 Excess-3 MSB 0 0000 0011 1 0001 0100 2 0010 0101 3 0011 0110 4 0100 0111 5 0101 1000 6 0110 1001 7 0111 1010 8 1000 1011 9 1001 1100 MSB + 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 1 B in t clk LSB Excess-3 Code Converter B out 1 1 0 1 t pp. 19

Mealy Finite State Machine The serial code converter is described by the state transition graph of a Mealy FSM. State Transition Graph 0/1 S_0 1/0 S_1 1/0 S_2 0/1 S_3 S_4 0/0, 1/1 0/1 0/0, 1/1 1/0 S_5 S_6 input / output Next State/OutputTable next state/output state input 0 1 S_0 S_1 / 1 S_2 / 0 S_1 S_3 / 1 S_4 / 0 S_2 S_4 / 0 S_4 / 1 S_3 S_5 / 0 S_5 / 1 S_4 S_5 / 1 S_6 / 0 S_5 S_0 / 0 S_0 / 1 S_6 S_0 / 1 - / - 0/0, 1/1 The vertices of the state transition graph of a Mealy machine are labeled with the states. The branches are labeled with (1) the input that causes a transition to the indicated next state, and (2) with the output that is asserted in the present state for that input. The state transition is synchronized to a clock. 0/1 The state table summarizes the machine's behavior in tabular format. pp. 20

Design of a Mealy Finite State Machine To design a D-type flip-flop realization of a FSM having the behavior described by a state transition graph, (1) select a state code, (2) encode the state table, (3) develop Boolean equations describing the input of a D-type flip-flop, and (4) using K-maps, optimize the Boolean equations. Encoded Next state/ Output Table state next state output Next State/Output Table next state/output state input 0 1 S_0 S_1 / 1 S_2 / 0 S_1 S_3 / 1 S_4 / 0 S_2 S_4 / 0 S_4 / 1 S_3 S_5 / 0 S_5 / 1 S_4 S_5 / 1 S_6 / 0 S_5 S_0 / 0 S_0 / 1 S_6 S_0 / 1 - / - State Assigment q 2 0 1 0 0 S_0 S_1 0 1 S_6 S_4 1 0 S_2 1 1 S_5 S_3 q 2 q + 2 q + 1 q + 0 input input 0 1 0 1 S_0 000 001 101 1 0 S_1 001 111 011 1 0 S_2 101 011 011 0 1 S_3 111 110 110 0 1 S_4 011 110 010 1 0 S_5 110 000 000 0 1 S_6 010 000-1 - 100 - - - - pp. 21

Design of a Mealy Finite State Machine B in 0 01 11 10 2 00 1 1 1 1 01 11 10 S_0 S_0 S_1 S_1 0 0 0 0 S_6 S_6 S_4 S_4 0 0 0 0 S_5 S_5 S_3 S_3 x x 1 1 S_2 + = ' S_2 B in 0 01 11 10 2 00 0 1 0 1 01 11 10 S_0 S_0 S_1 0 0 0 1 0 0 1 1 x x 0 0 S_1 S_6 S_6 S_4 S_4 S_5 S_5 S_3 S_3 S_2 S_2 B in 0 01 11 10 2 00 0 0 1 1 01 11 10 S_0 S_0 S_1 S_1 0 0 1 1 S_6 S_6 S_4 S_4 0 0 1 1 S_5 S_5 S_3 S_3 x x 1 1 S_2 + = S_2 B in q 2 00 01 11 10 00 1 0 0 1 01 1 0 0 1 11 0 1 1 0 10 x x 1 0 S_0 S_0 S_1 S_1 S_6 S_6 S_4 S_4 S_5 S_5 S_3 S_3 S_2 S_2 Note: We will optimize the equations individually. In general -this does not necessarily produce the optimal (area, speed) realization of the logic. We'll address this when we consider synthesis. q 2 + = ' 'B in + q 2 ' B in ' + q 2 q 2 + = ' 'B in + q 2 ' B in ' + q 2 q 2 + = ' 'B in q 2 ' B in ' q 2 q 2 + = ' 'B in q 2 ' B in ' q 2 q 2 + = ' 'B in + q 2 ' B in ' + q 2 B out = q 2 'B in ' + q 2 B in pp. 22

Design of a Mealy Finite State Machine Realization of the sequential BCD-to-Excess-3 code converter (Mealy machine): q 2 + = ' 'B in + q 2 ' B in ' + q 2 q 2 + = ' 'B in + q 2 ' B in ' + q 2 q 2 + = ' 'B in q 2 ' B in ' q 2 ' D Q q 2 + = ' 'B in q 2 ' B in ' q 2 Q ' q 2 D Q Q ' Bin B in q 2 ' B in ' ' ' D Q Q q 2 q 2 ' B in ' B out clk pp. 23

Design of a Mealy Finite State Machine Simulation results for Mealy machine: B_in B_out 0 0 1 0 1 1 1 0 pp. 24

Examples Design of A Serial Line Code Converter Serial Line Codes [Wakerly] are used for serial data time transmission or storage. NRZ Code NRZI Code RZ Code Manchester Code Serial Bit Value B_in NRZ Mealy NRZ Moore 0 1 1 1 0 0 1 0 NRZI Mealy NRZI Moore RZ Manchester clock_1 clock_2 pp. 25

Serial Line Code Converter Mealy FSM Objective: Design a Mealy-type FSM that converts a data stream in NRZ format to a data stream in Manchester code format. Data NRZ NRZ-to- Manchester Code Converter Data Manchester time Serial Bit Value 0 1 1 1 0 0 1 0 S_2 1 / 0 S_0 0 / 1 S_1 B_in 1 / 1 0 / 0 NRZ Mealy Manchester clock_1 clock_2 pp. 26

Serial Line Code Converter Mealy FSM State Transition Graph State Code: 1 / 0 0 / 1 0 1 S_2 S_0 S_1 0 S_0 S_1 1 / 1 0 / 0 1 S_2 State Table: next state/output state input 0 1 S_0 S_1 / 0 S_2 / 1 S_1 S_0 / 1 - S_2 - S_0 / 0 Encoded State Table: state next state output q + 1 q + 0 input input 0 1 0 1 S_0 00 01 10 0 1 S_1 01 00-1 - S_2 10-00 - 0 pp. 27

Encoded State Table: Graduate Institute of Electronics Engineering, NTU Serial Line Code Converter Mealy FSM state next state output + + input input 0 1 0 1 S_0 00 01 10 0 1 S_1 01 00-1 - S_2 10-00 - 0 ' ' D Q B_in' q Q 0 ' ' B in ' D Q B q Q 1 ' in clk B out Karnaugh Maps: B in 0 1 00 0 1 01 11 10 S_0 0 0 S_1 - - S_0 S_1 0 S_2 0 S_2 + = ' 'B in B in 0 1 00 1 0 01 11 10 S_0 0 0 S_1 - - 0 0 S_2 S_0 S_1 S_2 + = ' 'B in ' B in 0 1 00 0 1 01 11 10 S_0 1 1 S_1 - - - 0 S_2 S_0 S_1 S_2 B out = ' ( + B in ) pp. 28

Serial Line Code Converter Mealy FSM Input and output bit times coincide Note: The Mealy machine's output is subject to glitches in the input bit stream. pp. 29

Serial Line Code Converter Moore FSM Objective: Design a Moore-type FSM that converts a data stream in NRZ format to a data stream in Manchester code format. Data NRZ NRZ-to- Manchester Code Converter Data Manchester time Serial Bit Value 0 1 1 1 0 0 1 0 S_0 0 0 S_1 0 B_in NRZ Mealy Manchester clock_1 1 S_3 1 1 1 0 0 S_2 1 0 clock_2 pp. 30

Serial Line Code Converter Moore FSM State Transition Graph S_0 0 0 S_1 0 State Code: 0 1 1 1 0 0 0 S_0 S_1 0 1 S_2 S_3 S_3 1 1 S_2 1 State Table: Encoded State Table: state next state/output input 0 1 S_0 S_1 / 0 S_3 / 1 S_1 S_2 / 1 - S_3 - S_0 / 1 S_2 S_1 / 0 S_3 / 0 state next state output q + 1 q + 0 input 0 1 S_0 00 01 11 0 S_1 01 10-0 S_3 11-00 1 S_2 10 01 11 1 pp. 31

Encoded State Table: Karnaugh Maps: Graduate Institute of Electronics Engineering, NTU Serial Line Code Converter Moore FSM state next state output + + input 0 1 S_0 00 01 11 0 S_1 01 10-0 S_3 11-00 1 S_2 10 01 11 1 ' ' B in B out D Q Q ' clk D Q q Q 0 ' B in 0 1 00 0 1 01 11 10 S_0 1 - S_1-0 S_3 S_0 S_1 S_3 0 S_2 1 S_2 + = ' + 'B in B in 0 1 00 1 1 01 11 10 S_0 0 - S_1 - S_3 S_0 0 1 1 S_2 S_1 S_3 S_2 + = ' 0 1 0 0 0 1 S_0 1 1 S_1 S_0 S_1 B_out = pp. 32

Serial Line Code Converter Moore FSM NRZ bit time Manchester bit time Note: The Manchester encoder must run at twice the frequency of the incoming data. The output bit stream lags the input bit stream by one-half the input cycle time. pp. 33

Building Behavioral Models ACCESS IC LAB

Modeling FSM in Verilog Sequential Circuits Memory elements of States (CS) Combinational Circuits Next-state Logic (NL) Output Logic (OL) Three coding styles (1) Separate CS, OL and NL (2) Combines NL+ OL, separate CS (3) Combine CS + NL, separate OL pp. 35

CS Graduate Institute of Electronics Engineering, NTU Coding Style 1 Separate CS, NL, OL NL OL pp. 36

CS Graduate Institute of Electronics Engineering, NTU Coding Style 2 Combine NL+OL; Separate CS NL+OL pp. 37

CS+NL Graduate Institute of Electronics Engineering, NTU Coding Style 3 Combine CS+NL; Separate OL OL pp. 38

Behavioral Models of FSM Example1 brake=0 accelerator=1 brake=0 accelerator=1 low speed medium speed brake=1 brake=1 brake=1 stopped high speed brake=1 brake=0 accelerator=1 brake accelerator clock speed brake=0 accelerator=1 pp. 39

Verilog Coding 1 (CS, NL, OL) module speed_machine ( clock, accelerator, brake, speed ); input clock, accelerator, brake; output [1:0] speed; reg [1:0] current_state, next_state; // state encoding parameter stopped = 2`b00; parameter s_slow = 2`b01; parameter s_medium = 2`b10; parameter s_high = 2`b11; // CS always @ ( posedge clock ) current_state <= next_state; // OL, Output Logic assign speed = current_state; // NL, Next-state Logic always@( state or accelerator or brake ) if ( brake == 1`b1 ) case ( current_state ) stopped: next_state <= stopped; s_low: next_state <= stopped; s_medium:next_state <= s_low; s_high: next_state <= s_medium; default: next_state <= stopped; endcase else if ( accelerator == 1`b1 ) case ( current_state ) stopped: next_state <= s_low; s_low: next_state <= s_medium; s_medium:next_state <= s_high; s_high: next_state <= s_high; default: next_state <= stopped; endcase else next_state <= current_state; endmodule pp. 40

Verilog Coding 3 (CS+NL, OL) module speed_machine2 ( clock, accelerator, brake, speed ); input clock, accelerator, brake; output [1:0] speed; reg [1:0] speed; `define stopped 2`b00 `define s_low 2`b01 `define s_medium 2`b10 `define s_high 2`b11 // OL is empty // because speed itself is state // NL + CS always @ ( posedge clock ) if ( brake == 1`b1 ) case ( speed ) `stopped: speed <= `stopped; `s_low: speed <= `stopped; `s_medium:speed <= `s_low; `s_high: speed <= `s_medium; default: speed <= `stopped; endcase else if ( accelerator == 1`b1 ) case ( speed ) `stopped: speed <= `s_low; `s_low: speed <= `s_medium; `s_medium:speed <= `s_high; `s_high: speed <= `s_high; default: speed <= `stopped; endcase endmodule pp. 41

State encoding pp. 42

FSM Design Conclusion Partition FSM and non-fsm logic Partition combinational part and sequential part Use parameter to define names of the state vector Assign a default (reset) state pp. 43

Homework #4 Design a traffic signal controller at crossroads One pair traffic signal controller State Diagram State Coding Performance [Optional] With interrupt/extra setting 1 2 Other example: Automatic Vending Machine Automatic Teller Machine 2 1 pp. 44

Useful Modeling Techniques ACCESS IC LAB

Learning Objectives Describe procedural continuous assignment statements assign, deassign, force, and release. Understand how to override parameters by using the defparam statement at the time of module instantiation. Explain conditional compilation and execution of parts of the Verilog. Identify system tasks for file output, displaying hierarchy, strobing, random number generation, memory initialization, and value change dump. pp. 46

Procedural Continuous Assignments Procedural Assignments assign a value to a register. The value stays in the register until another procedural assignment puts another value in that register. Procedural Continuous Assignments behave differently. They are procedural statements which allow value of expressions to be driven continuously onto register or net for limited periods of time. They override existing assignments to a register or net, They provide an useful extension to regular procedural assignment statement. pp. 47

assign & deassign First type of procedural continuous assignment. The LHS of procedural continuous assignments can only be a register or a concatenation of registers. It cannot be a part or bit select of a net or an array of registers. Procedural continuous assignments override the effect of regular procedural assignments. Procedural continuous assignments are normally used for controlled periods of time. pp. 48

Example module edge_dff(q, qbar, d, clk, reset); output q, qbar; input d, clk, reset; reg q, qbar; always @(negedge clk) begin q = d; qbar = ~d; end always @(reset) if (reset) begin assign q = 1 b0; assign qbar = 1 b1; end else begin deassign q; deassign qbar; end endmodule pp. 49

force & release Second form of the procedural continuous assignments. They can be used to override assignments on both register and nets. Typically, used in the interactive debugging process, where certain registers or nets are forced to a value and the effect on other registers and nets is noted. They not be used inside design blocks. They should appear only in stimulus or as debug statements. pp. 50

Example module stimulus; // instantiate the d-flip-flop edge_dff dff(q, Qbar, D, CLK, RESET); initial begin // these statements force value of 1 // on dff.q between time 50 and 100, // regardless of the actual output of // the edge_dff #50 force dff.q = 1 b1; #50 release dff.q; end endmodule module top; assign out = a & b & c; initial begin #50 force out = a b & c; #50 release; end endmodule pp. 51

Overriding Parameters Parameters can be defined in a module definition. However, during compilation of Verilog modules, parameter values can be altered separately for each module instance. this allows us to pass a distinct set of parameter values to each module during compilation regardless of predefined parameter values. Two ways to override parameter values: defparam statement module instance parameter value assignment. pp. 52

Example // Define a module hello_world module hello_world; parameter id_num = 0; // define a module identification number = 0 initial $display( Displaying hello_world id number = %d, id_num); endmodule // Define top-level module module top; // Change parameter values in the instantiated modules // Use defparam statement defparam w1.id_num = 1, w2.id_num = 2; // Instantiate two hello_world modules hello_world w1( ); hello_world w2( ); Displaying hello_world id number = 1 Displaying hello_world id number = 2 endmodule pp. 53

Condition Compilation and Execution A portion of Verilog might be suitable for one environment and not for the other. The designer does not wish to create two versions of Verlog design for the two environments. Instead, the designer can specify that the particular portion of the code be compiled only if certain flag is set. This is called conditional compilation. A designer might also want to execute certain parts of the Verilog design only when a flag is set at run time. This is called conditional execution. pp. 54

Conditional Compilation Conditional compilation can be accomplished by using compiler directives `ifdef, `else, and `endif. // Conditional Compilation // Example 1 `ifdef TEST // compile module test only if module test; // text marco TEXT is defined endmodule `else // compile the stimulus as default module stimulus; endmodule `endif // completion // Conditional Compilation // Example 2 module top; bus_master b1 ( ); `ifdef ADD_B2 bus_master b2 ( ); `endif endmodule pp. 55

Conditional Execution Conditional execution flags allow the designer to control statement execution flow at run time. All statements are compiled but executed conditionally. Conditional execution flags can be used only for behavioral statements. The system task keywork $test$plusargs is used for conditional execution. // Conditional Execution module test; initial begin end if ($test$plusargs( DISPLAY_VAR )) $display( Display = %b, {a, b, c} ); // display only if flag is set else endmoduel $display( No Display ); // otherwise no display pp. 56

File Output Files Open/Write/Close Opening a file integer filepointer; initial filepointer = $fopen( file.out ); Writing to file fdisplay(filepointer, Display ); fmonitior(filepointer, P1=%b, P1); Closing files $fclose(filepointer); pp. 57

Strobing Useful System Tasks The $strobe task is very similar to the $display task except for a slight difference The $strobe task provides a synchronization mechanism to ensure that data is displayed only after all other assignment statements. Random Number Generation $random; or $random(seed); returns a 32-bit random number. pp. 58

Useful System Tasks Initializing memory form file reg[7:0] memory[0:7]; initial begin $readmemb( init.dat, memory); // display contents of initialized memory for (i=0; i<8; i=i+1) $display( Memory[%0d] = %b, i, memory[i]); end Memory[0] = xxxxxxxx Memory[1] = xxxxxxxx Memory[2] = 11111111 Memory[3] = 01010101 Memory[4] = 00000000 Memory[5] = 10101010 Memory[6] = 1111zzzz Memory[7] = 00001111 init.dat @002 11111111 01010101 00000000 10101010 @006 1111zzzz 00001111 uninitialized locations default to x pp. 59