Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-1 Chapter 5: Tasks, Functions,

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.
The Verilog Hardware Description Language
Combinational Logic.
Reconfigurable Computing S. Reda, Brown University Reconfigurable Computing (EN2911X, Fall07) Lecture 07: Verilog (3/3) Prof. Sherief Reda Division of.
Verilog Modules for Common Digital Functions
Table 7.1 Verilog Operators.
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.
Anurag Dwivedi.  Verilog- Hardware Description Language  Modules  Combinational circuits  assign statement  Control statements  Sequential circuits.
CSE 201 Computer Logic Design * * * * * * * Verilog Modeling
//HDL Example 5-1 // //Description of D latch (See Fig.5-6) module D_latch (Q,D,control); output Q; input.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
Latches and Flip-Flops Discussion D8.1 Section 13-9.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
ECE 353 Computer Systems Lab I Verilog Hardware Description Language.
ELEN 468 Lecture 51 ELEN 468 Advanced Logic Design Lecture 5 User-Defined Primitives.
Counters Discussion 12.1 Example 33. Counters 3-Bit, Divide-by-8 Counter 3-Bit Behavioral Counter in Verilog Modulo-5 Counter An N-Bit Counter.
2-to-1 Multiplexer: if Statement Discussion D7.1 Example 4.
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
ELEN 468 Advanced Logic Design
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
ECE 2372 Modern Digital System Design
Chapter 4: Behavioral Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 4-1 Ders – 4: Davranışsal Modelleme.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
Digital System 數位系統 Verilog HDL Ping-Liang Lai (賴秉樑)  
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Module 2.1 Gate-Level/Structural Modeling UNIT 2: Modeling in Verilog.
Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-1 Ders - 5 : Görevler,
EEE2243 Digital System Design Chapter 3: Verilog HDL (Combinational) by Muhazam Mustapha, January 2011.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
1 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Chap. 4 Modules and Ports. 2 Modules and Ports Modules Ports Hierarchical Names Summary.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Under-Graduate Project Logic Design with Behavioral Models Speaker: Darcy Tsai Adviser:
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
The Verilog Hardware Description Language. GUIDELINES How to write HDL code: How to write HDL code:
M.Mohajjel. Continuous Assignments Continuously Drive a value onto a net Left hand side must be net Right hand side registers nets function calls Keyword.
Chapter 2: Structural Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 2-1 Chapter 2a: Structural Modeling.
Introduction to ASIC flow and Verilog HDL
M.Mohajjel. Objectives Learn How to write synthesizable Verilog code Common mistakes and how to avoid them What is synthesized for what we code Digital.
Multiplexers Section Topics Multiplexers – Definition – Examples – Verilog Modeling.
Chapter 8: Combinational Logic Modules Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 8-1 Chapter 8: Combinational.
Introduction to Verilog
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Chapter 11: System Design.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Chapter 3: Dataflow Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 3-1 Chapter 3: Dataflow Modeling.
Chapter 6: Hierarchical Structural Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 6-1 Chapter 6: Hierarchical.
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,
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Logic Design with Behavioral Models Speaker: 銀子駒 Adviser:
Digital System Design Verilog ® HDL Dataflow Modeling Maziar Goudarzi.
LECTURE VI USER DEFINED PRIMITIVES GATE-LEVEL MODELING.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Hardware Description Languages: Verilog
Reg and Wire:.
Verilog Introduction Fall
Behavioral Modeling Structural modeling Behavioral modeling
Hardware Description Languages: Verilog
ELEN 468 Advanced Logic Design
Chapter 5: Tasks, Functions, and UDPs
Hardware Descriptive Languages these notes are taken from Mano’s book
Hardware Descriptive Languages these notes are taken from Mano’s book
Chapter 4: Behavioral Modeling
Chapter 8: Combinational Logic Modules
The Verilog Hardware Description Language
The Verilog Hardware Description Language
COE 202 Introduction to Verilog
Reconfigurable Computing (EN2911X, Fall07)
Presentation transcript:

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-1 Chapter 5: Tasks, Functions, and UDPs Prof. Ming-Bo Lin Department of Electronic Engineering National Taiwan University of Science and Technology

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-2 Syllabus  Objectives  Tasks  Functions  Combinational UDPs  Sequential UDPs

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-3 Task Definition and Calls // port list style task [automatic] task_identifier; [declarations] // include arguments procedural_statement endtask // port list declaration style task [automatic] task_identifier ([argument_declarations]); [other_declarations] // exclude arguments procedural_statement endtask task [automatic] task_identifier(task_port_list); … endtask

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-4 A Task Example // count the zeros in a byte module zero_count_task (data, out); input [7:0] data; output reg [3:0] out; count_0s_in_byte(data, out); // task declaration from here task count_0s_in_byte(input [7:0] data, output reg [3:0] count); integer i; begin // task body count = 0; for (i = 0; i <= 7; i = i + 1) if (data[i] == 0) count= count + 1; end endtask endmodule

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-5 Types of Tasks  (static) task task … endtask  automatic (reentrant, dynamic) task task automatic … endtask

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-6 Function Definition and Calls // port list style function [automatic] [signed] [range_or_type] function_identifier; input_declaration other_declarations procedural_statement endfunction // port list declaration style function [automatic] [signed] [range_or_type] function_identifier (input_declarations); other_declarations procedural_statement endfunction function [automatic] [signed] [range_of_type] … endfunction

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-7 A Function Example // count the zeros in a byte module zero_count_function (data, out); input [7:0] data; output reg [3:0] out; out = count_0s_in_byte(data); // function declaration from here. function [3:0] count_0s_in_byte(input [7:0] data); integer i; begin count_0s_in_byte = 0; for (i = 0; i <= 7; i = i + 1) if (data[i] == 0) count_0s_in_byte = count_0s_in_byte + 1; end endfunction endmodule

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-8 Types of Functions  (static) function function … endfunction  automatic (recursive, dynamic) function function automatic … endfunction

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-9 Automatic (Recursive) Functions // the use of reentrant function module factorial(input [7:0] n, output [15:0] result); // instantiate the fact function assign result = fact(7); // define fact function function automatic [15:0] fact; input [7:0] N; // the body of function if (N == 1) fact = 1; else fact = N * fact(N - 1); endfunction endmodule

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-10 Constant Functions module RAM (addr_bus, data_bus); parameter RAM_depth = 1024; input [count_log_b2(RAM_depth)-1:0] addr_bus; output reg [7:0] data_bus; // function declaration from here function integer count_log_b2(input integer depth); begin // function body count_log_b2 = 0; while (depth) begin count_log_b2 = count_log_b2 + 1; depth = depth >> 1; end endfunction endmodule

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-11 Definition of Combinational UDPs // port list style primitive udp_name(output_port, input_ports); output output_port; input input_ports; // UDP state table table // the state table starts from here endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-12 Definition of Combinational UDPs  State table entries  The values must be in the same order as in the input list …… : ;

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-13 A Primitive UDP --- An AND Gate primitive udp_and (out, a, b); output out; input a, b; table // a b : out; 0 0 : 0; 0 1 : 0; 1 0 : 0; 1 1 : 1; endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-14 Another UDP Example primitive prog253 (output f, input x, y, z); table // truth table for f(x, y, z,) = ~(~(x | y) | ~x & z); // x y z : f : 0; : 0; : 1; : 0; : 1; : 1; : 1; : 1; endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-15 Shorthand Notation for Don’t Cares primitive udp_and(f, a, b); output f; input a, b; table // a b : f; 1 1 : 1; 0 ? : 0; ? 0 : 0; // ? expanded to 0, 1, x endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-16 Instantiation of Combinational UDPs // instantiations of UDPs module UDP_full_adder(sum, cout, x, y, cin); output sum, cout; input x, y, cin; wire s1, c1, c2; // instantiate udp primitives udp_xor (s1, x, y); udp_and (c1, x, y); udp_xor (sum, s1, cin); udp_and (c2, s1, cin); udp_or (cout, c1, c2); endmodule

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-17 Definition of Sequential UDPs // port list style primitive udp_name(output_port, input_ports); output output_port; input input_ports; reg output_port; // unique for sequential UDP initial output-port = expression; // optional for sequential UDP // UDP state table table // keyword to start the state table endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-18 Definition of Sequential UDPs  State table entries  The output is always declared as a reg  An initial statement can be used to initialize output …… : : ;

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-19 Level-Sensitive Sequential UDPs // define a level-sensitive latch using UDP primitive d_latch(q, d, gate, clear); output q; input d, gate, clear; reg q; initial q = 0; // initialize output q table // d gate clear : q : q+; ? ? 1 : ? : 0 ; // clear : ? : 1 ; // latch q = : ? : 0 ; // latch q = 0 ? 0 0 : ? : - ; // no change endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-20 Edge-Sensitive Sequential UDPs // define a positive-edge triggered T-type flip-flop using UDP primitive T_FF(q, clk, clear); output q; input clk, clear; reg q; // define the behavior of edge-triggered T_FF table // clk clear : q : q+; ? 1 : ? : 0 ; // asynchronous clear ? (10) : ? : - ; // ignore negative edge of clear (01) 0 : 1 : 0 ; // toggle at positive edge (01) 0 : 0 : 1 ; // of clk (1?) 0 : ? : - ; // ignore negative edge of clk endtable endprimitive

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-21 Shorthand Symbols for Using in UDPs

Chapter 5: Tasks, Functions, and UDPs Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 5-22 Instantiation of UDPs // an example of sequential UDP instantiations module ripple_counter(clock, clear, q); input clock, clear; output [3:0] q; // instantiate the T_FFs. T_FF tff0(q[0], clock, clear); T_FF tff1(q[1], q[0], clear); T_FF tff2(q[2], q[1], clear); T_FF tff3(q[3], q[2], clear); endmodule