Supplement on Verilog adder examples

Slides:



Advertisements
Similar presentations
Verilog HDL -Introduction
Advertisements

Verilog.
Simulation executable (simv)
The Verilog Hardware Description Language
Supplement on Verilog adder examples
Verilog Intro: Part 1.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part3: Verilog – Part 1.
CSE 341 Verilog HDL An Introduction. Hardware Specification Languages Verilog  Similar syntax to C  Commonly used in  Industry (USA & Japan) VHDL 
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
 HDLs – Verilog and Very High Speed Integrated Circuit (VHSIC) HDL  „ Widely used in logic design  „ Describe hardware  „ Document logic functions.
Lecture 1 Design Hierarchy Chapter 1. Digital System Design Flow 1.Register-Transfer Levl (RTL) – e.g. VHDL/Verilog 2.Gate Level Design 3.Circuit Level.
The Multicycle Processor II CPSC 321 Andreas Klappenecker.
CSE241 R1 Verilog.1Kahng & Cichy, UCSD ©2003 CSE241 VLSI Digital Circuits Winter 2003 Recitation 1: Verilog Introduction.
Computer Organization Lecture Set – 03 Introduction to Verilog Huei-Yung Lin.
B. RAMAMURTHY Hardware Description Language 8/2/
Lecture # 12 University of Tehran
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
Verilog Intro: Part 2. Procedural Blocks There are two types of procedural blocks in Verilog. – initial for single-pass behavior: initial blocks execute.
ECE 2372 Modern Digital System Design
Workshop Topics - Outline
Figure 5.1. Conversion from decimal to binary.. Table 5.1. Numbers in different systems.
Figure 5.1. Conversion from decimal to binary.. Table 5.1. Numbers in different systems.
CS 3850 Lecture 3 The Verilog Language. 3.1 Lexical Conventions The lexical conventions are close to the programming language C++. Comments are designated.
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.
CWRU EECS 317 EECS 317 Computer Design LECTURE 1: The VHDL Adder Instructor: Francis G. Wolff Case Western Reserve University.
Module 1.2 Introduction to Verilog
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
Chap. 4 Modules and Ports. 2 Modules and Ports Modules Ports Hierarchical Names Summary.
Use of HDLs in Teaching of Computer Hardware Courses Zvonko Vranesic and Stephen Brown University of Toronto.
Introduction to ASIC flow and Verilog HDL
Verilog hdl – II.
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.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
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,
Exp#5 & 6 Introduction to Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
1 A hardware description language is a computer language that is used to describe hardware. Two HDLs are widely used Verilog HDL VHDL (Very High Speed.
Structural Description
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Behavioral Style Combinational Design with VHDL
Introduction to Verilog
Discussion 2: More to discuss
Verilog Introduction Fall
Lecture 2 Boolean Algebra Basic
‘if-else’ & ‘case’ Statements
Lecture 2 Supplement Verilog-01
Behavioral Style Combinational Design with VHDL
Hardware Description Languages: Verilog
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Chapter 4 Combinational Logic
Introduction to Verilog
Chapter 3: Dataflow Modeling
Introduction to Verilog
IAS 0600 Digital Systems Design
332:437 Lecture 8 Verilog and Finite State Machines
Lecture 2: Continuation of SystemVerilog
Lecture 4 Minterm and Maxterm
IAS 0600 Digital Systems Design
Supplement on Verilog adder examples
Introduction to Verilog
The Verilog Hardware Description Language
Supplement on Verilog combinational circuit examples
EEE2243 Digital System Design Chapter 1: Verilog HDL (Combinational) by Muhazam Mustapha, February 2012.
332:437 Lecture 8 Verilog and Finite State Machines
Introduction to Verilog – Part-2 Procedural Statements
COE 202 Introduction to Verilog
Reconfigurable Computing (EN2911X, Fall07)
Presentation transcript:

Supplement on Verilog adder examples Based on Fundamentals of Digital Logic with Verilog Design By Brown/Vranesic 3rd. Chung-Ho Chen

Typical IC Design Flow HDL: Hardware Description Language Design conception Verilog Schematic capture DESIGN ENTRY Design correct? Functional simulation No Yes Synthesis Physical design Tape-out Timing requirements met? Timing simulation HDL: Hardware Description Language FPGA prototyping Post-layout simulation

More details on physical design DRC: design rule check: ensures that the physical layout of a particular chip  satisfies a series of recommended parameters called Design Rules.  LVS: Layout Versus Schematic (LVS)  ERC: electrical rule check…..

Example: OpenGL ES 1.0 GPU; first in Taiwan using ESL Full System Verification, completed in 2009 CS252 S05

Example: ARM Hypervior and its ESL Platform, first in Taiwan, 2012 SystemC functional model TLM 2.0 Bus VM support, allow multiple VM Linux OSes booting on platform of one core system CASL Hypervisor VM 0 VM n CS252 S05

Example: CASLab System Simulator/ISS/Core Full access to CASLab students: 在CASLab可學的系統很多 ISA Axx v4 Axx v6 Axx v6k Axx v7a Axx v7a-VM CPU Axx 926 Axx 11 Axx 11 MP Cortex A8 Cortex A15 Core No. 1 4 Type RTL/ Functional OOO Board Versatile PB RealView EB RealView PB Linux Booting Yes VT Support No

Example: NCKUEE Dual-Core Processors, First in Taiwan’s University, 2013

Describe a circuit in a form of module Gate Level: structural description and (u, ~s, x1); // without an explicit not ahead module mux (x1, x2, s, f); input x1, x2, s; output f; not (si,s); and (u, si, x1); and (l, s, x2); or (f, u, l); endmodule keyword output

Behavioral: logic equation module mux (x1, x2, s, f); input x1, x2, s; output f; assign f = (~s & x1) | (s &x2); assign y = f | x2; endmodule Continuous assignment: f is re-evaluated whenever the right hand side signal changes. No order for f and y, concurrent statement; assign: for nets (like wire) since nets can not hold values, so you need to assign the value continuously.

Behavioral: procedural statement The simulator registers this value until the always block is executed again. output reg f; module mux (x1, x2, s, f); input x1, x2, s; output f; reg f; always@(x1, x2, s) if (s == 0) f = x1; else f = x2; endmodule always@(sensitivity list) Evaluated in the order given by the code; if first, then else. = blocking assignment (evaluated in order)

Coding in 3 ways: Gate instantiation Continuous assignment (assign) Procedural statements (always) Blocking assignment = sequencing S = X + Y; // S[3:0] C = S[0]; // C takes the new value from X+Y. Non-blocking assignment <= S <= X + Y; C <= S[0]; // at simulation time ti, C takes the value of S[0] at simulation time ti-1

More compact procedural statement module mux (input x1, x2, s, output reg f); always@(x1, x2,s) if (s == 0) f = x1; else f = x2; endmodule

Hierarchical Verilog Code Top-level module module whole (X1, X2, A, B, C, D, E); Input X1, X2; output A, B, C, D, E; wire w0, w1; front U1 (X1, X2, w0, w1); back U2 (w0, w1, A, B, C, D, E); ….. endmodule a b c d e w0 w1 A B C D E X1 a b c d y1 y2 X2 module front (a, b, c, d); Input a, b; output c, d; ….. endmodule module back (y1, y2, a, b, c, d, e); Input y1, y2; output a, b, c, d, e; ….. endmodule Internal (not output or input) uses wire.

Full Adder Using Gates module fulladd (Cin, x, y, s, Cout); input Cin, x, y; output s, Cout; xor (s, x, y, Cin); and (a, x, y); and (b, x, Cin); and (c, y, Cin); or (Cout, a, b, c); endmodule   module fulladd (Cin, x, y, s, Cout); input Cin, x, y; output s, Cout; xor (s, x, y, Cin); and (a, x, y), (b, x, Cin), //omit and (c, y, Cin); or (Cout, a, b, c); endmodule  

Full Adder Using Functional Expression module fulladd (Cin, x, y, s, Cout); input Cin, x, y; output s, Cout; assign s = x ^ y ^ Cin, Cout = (x & y) | (x & Cin) | (y & Cin); endmodule  

3-bit Ripple Adders module adder3 (c0, x2, x1, x0, y2, y1, y0, s2, s1, s0, carryout); input c0, x2, x1, x0, y2, y1, y0; output s2, s1, s0, carryout; fulladd b0 (c0, x0, y0, s0, c1); fulladd b1 (c1, x1, y1, s1, c2); fulladd b2 (c2, x2, y2, s2, carryout); endmodule   module fulladd (Cin, x, y, s, Cout); input Cin, x, y; output s, Cout; assign s = x ^ y ^ Cin, assign Cout = (x & y) | (x & Cin) | (y & Cin); endmodule  Instantiate the fulladd module

3-bit Ripple Adders Using Vectored Signals Vectored signals used module adder3 (c0, x2, x1, x0, y2, y1, y0, s2, s1, s0, carryout); input c0, x2, x1, x0, y2, y1, y0; output s2, s1, s0, carryout; fulladd b0 (c0, x0, y0, s0, c1); fulladd b1 (c1, x1, y1, s1, c2); fulladd b2 (c2, x2, y2, s2, carryout); endmodule   module fulladd (Cin, x, y, s, Cout); input Cin, x, y; output s, Cout; assign s = x ^ y ^ Cin, assign Cout = (x & y) | (x & Cin) | (y & Cin); endmodule  module adder3 (c0, X, Y, S, carryout); input c0; input [2:0] X, Y; output [2:0] S; output carryout; wire [2:1] C; fulladd b0 (c0, X[0], Y[0], S[0], C[1]); fulladd b1 (C[1], X[1], Y[1], S[1], C[2]); fulladd b2 (C[2], X[2], Y[2], S[2], carryout); endmodule 

n-bit Ripple Adders module adderN (c0, X, Y, S, carryout); parameter n = 16; input c0; input [n-1:0] X, Y; output reg [n-1:0] S; output reg carryout; reg [n:0] C; integer k; always @(X, Y, c0) begin C[0] = c0; for (k = 0; k < n; k = k+1) S[k] = X[k] ^ Y[k] ^ C[k]; C[k+1] = (X[k] & Y[k]) | (X[k] & C[k]) | (Y[k] & C[k]); end carryout = C[n]; endmodule  1: for: a procedural statement, must be inside a always block. for loop in Verilog specifies a different subcircuit in each iteration. for loop does not specify change that takes place in time during successive iterations as in a programming language. 2: Values inside a always block must retain their values until any change of signals in the sensitivity list. To hold on the values, use reg to keep them. There is no physical meaning of k in the circuit. It is used to tell the compiler that how many instances of the iteration are needed.

3-bit to n-bit transformation using generate module addern (c0, X, Y, S, carryout); parameter n = 16; input c0; input [n-1:0] X, Y; output [n-1:0] S; output carryout; wire [n:0] C;   genvar i; // to be used in generate assign C[0] = c0; assign carryout = C[n];   generate for (i = 0; i <= n-1; i = i+1) begin:adderbit fulladd b (C[i], X[i], Y[i], S[i], C[i+1]); end endgenerate endmodule module adder3 (c0, X, Y, S, carryout); input c0; input [2:0] X, Y; output [2:0] S; output carryout; wire [2:1] C; fulladd b0 (c0, X[0], Y[0], S[0], C[1]); fulladd b1 (C[1], X[1], Y[1], S[1], C[2]); fulladd b2 (C[2], X[2], Y[2], S[2], carryout); endmodule  Instantiate a submodule n times using generate Instance name produced adderbit[0].b adderbit[1].b …. adderbit[15].b

Overflow and Carry-Out detection n-bit signed number: -2n-1 to 2n-1 -1 Detect overflow for signed number: Overflow = Cn-1 ⊕ Cn Overflow = Xn-1 Yn-1 ~Sn-1 (110) + ~Xn-1 ~Yn-1 Sn-1 (001) (summation of two same signs produce different sign) where X and Y represent the 2’s complement numbers, S = X+Y. (sign bits 0, 0 ≠ 1 ) For unsigned number carry out from n-1 bit position: If both xn-1 and yn-1 are 1 or If either xn-1 or yn-1 is 1 and sn-1 is 0. Hence, carryout = xn-1 yn-1 + ~sn-1 xn-1 + ~sn-1 yn-1 1 x or y 0111 1111 carryin

n-bit adder with overflow and carryout module addern (carryin, X, Y, S, carryout, overflow); parameter n = 32; input carryin; input [n-1:0] X, Y; output reg [n-1:0] S; output reg carryout, overflow; always @(X, Y, carryin) begin S = X + Y + carryin; // arithmetic assignment carryout = (X[n-1] & Y[n-1]) | (X[n-1] & ~S[n-1]) | (Y[n-1] & ~S[n-1]); overflow = (X[n-1] & Y[n-1] & ~S[n-1]) | (~X[n-1] & ~Y[n-1] & S[n-1]); end   endmodule 

Another way to get carryout module addern (carryin, X, Y, S, carryout, overflow); parameter n = 32; input carryin; input [n-1:0] X, Y; output reg [n-1:0] S; output reg carryout, overflow; reg [n:0] Sum; //n+1 bits, nth for the carryout   always @(X, Y, carryin) begin Sum = {1'b0,X} + {1'b0,Y} + carryin; // One 0 bit is concatenated (,) with X S = Sum[n-1:0]; carryout = Sum[n]; overflow = (X[n-1] & Y[n-1] & ~S[n-1]) | (~X[n-1] & ~Y[n-1] & S[n-1]); end endmodule  Will this work? Sum = X + Y + carryin;?

Better module addern (carryin, X, Y, S, carryout, overflow); parameter n = 32; input carryin; input [n-1:0] X, Y; output reg [n-1:0] S; output reg carryout, overflow; always @(X, Y, carryin) begin {carryout, S} = X + Y + carryin; //using concatenation overflow = (X[n-1] & Y[n-1] & ~S[n-1]) | (~X[n-1] & ~Y[n-1] & S[n-1]); end   endmodule 

Module Hierarchy in Verilog two adders: 16-bit and 8-bit module adder_hier (A, B, C, D, S, T, overflow); input [15:0] A, B; input [7:0] C, D; output [16:0] S; output [8:0] T; output overflow;   wire v1, v2; // used for the overflow signals addern U1 (1’b0, A, B, S[15:0], S[16], v1); defparam U1.n = 16; addern U2 (1’b0, C, D, T[7:0], T[8], v2); defparam U2.n = 8; assign overflow = v1 | v2; endmodule  module addern (carryin, X, Y, S, carryout, overflow); parameter n = 32; input carryin; input [n-1:0] X, Y; output reg [n-1:0] S; output reg carryout, overflow; always @(X, Y, carryin) begin {carryout, S} = X + Y + carryin; overflow = (X[n-1] & Y[n-1] & ~S[n-1]) | (~X[n-1] & ~Y[n-1] & S[n-1]); end   endmodule  defparam: define n to be 16 S[16] and T[8] for unsigned carryout

Specifying Parameters two adders: 16-bit and 8-bit module adder_hier (A, B, C, D, S, T, overflow); input [15:0] A, B; input [7:0] C, D; output [16:0] S; output [8:0] T; output overflow; // not in an always block   wire v1, v2; // used for the overflow signals addern U1 (1’b0, A, B, S[15:0], S[16], v1); defparam U1.n = 16; addern U2 (1’b0, C, D, T[7:0], T[8], v2); defparam U2.n = 8; assign overflow = v1 | v2; endmodule  Using # operator. addern #(16) U1 (1’b0, A, B, S[15:0], S[16], v1);

Named port connection module adder_16(A, B, S, overflow); input [15:0] A, B; output [16:0] S; output overflow; // not in an always block wire v1; // used for the overflow signals addern #(.n(16)) U1 ( .carryin(1’b0), .X (A), .Y (B), .S (S[15:0), .carryout (S[16]), .overflow (v1) ); assign overflow = v1;   endmodule  module addern (carryin, X, Y, S, carryout, overflow); parameter n = 32; input carryin; input [n-1:0] X, Y; output reg [n-1:0] S; output reg carryout, overflow; always @(X, Y, carryin) begin {carryout, S} = X + Y + carryin; overflow = (X[n-1] & Y[n-1] & ~S[n-1]) | (~X[n-1] & ~Y[n-1] & S[n-1]); end   endmodule 

So far, nets and variables Net: connecting things. Represent structural connections between components. wire. A wire connects an output of one logic element to the input of another logic element. No need to declare scalar signals of wire, since signals are nets by default. tri. Another net is tri denoting circuit nodes which are connected in tri-state. Variable: used to describe behaviors of the circuits. reg. Represent variables. reg does not denote a storage element or register. reg can model either combinational or sequential part of the circuit. integer.