Hardware Description Languages: Verilog

Slides:



Advertisements
Similar presentations
Hardware Description Languages (HDL): Verilog
Advertisements

Hardware Description Languages: Verilog
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Combinational Logic.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
Anurag Dwivedi.  Verilog- Hardware Description Language  Modules  Combinational circuits  assign statement  Control statements  Sequential circuits.
CSE 201 Computer Logic Design * * * * * * * Verilog Modeling
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.
Verilog - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
ELEN 468 Lecture 151 ELEN 468 Advanced Logic Design Lecture 15 Synthesis of Language Construct I.
© UC Berkeley EECS Components and Design Techniques for Digital Systems Lec 04 – Hardware Description Languages / Verilog 9/6/2007 David Culler Electrical.
ECE 4680 Computer Architecture Verilog Presentation I. Verilog HDL.
1 EECS Components and Design Techniques for Digital Systems Lec 04 – Hardware Description Languages / Verilog 9/9-04 David Culler Electrical Engineering.
Computer Organization Lecture Set – 03 Introduction to Verilog Huei-Yung Lin.
B. RAMAMURTHY Hardware Description Language 8/2/
Lecture 7 Verilog Additional references Structural constructs
Overview Logistics Last lecture Today HW5 due today
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
1 An Update on Verilog Ξ – Computer Architecture Lab 28/06/2005 Kypros Constantinides.
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.
Module 1.2 Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Electrical and Computer Engineering University of Cyprus LAB 1: VHDL.
Chap. 4 Modules and Ports. 2 Modules and Ports Modules Ports Hierarchical Names Summary.
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
Introduction to ASIC flow and Verilog HDL
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.
Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Exp#5 & 6 Introduction to Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Hardware Description Languages
ELEN 468 Advanced Logic Design
Introduction to Verilog
Discussion 2: More to discuss
Lecture 7 Logistics Last lecture Today Homework 2 due today
KARTHIK.S Lecturer/ECE S.N.G.C.E
Lecture 2 Supplement Verilog-01
Verilog-HDL-3 by Dr. Amin Danial Asham.
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Introduction to Verilog
Behavioral Modeling in Verilog
Chapter 3: Dataflow Modeling
Overview Last lecture Today K-Maps Verilog Structural constructs
Overview Last lecture Today K-Maps Verilog Structural constructs
COE 202 Introduction to Verilog
Review Advancing technology changes the trade-offs and design techniques 2x transistors per chip every 18 months ASIC, Programmable Logic, Microprocessor.
Introduction to Verilog
Introduction to Verilog, ModelSim, and Xilinx ISE
Introduction to Verilog, ModelSim, and Xilinx Vivado
Supplement on Verilog adder examples
Introduction to Verilog
The Verilog Hardware Description Language
The Verilog Hardware Description Language
Introduction to Verilog
EEE2243 Digital System Design Chapter 1: Verilog HDL (Combinational) by Muhazam Mustapha, February 2012.
Introduction to Verilog – Part-2 Procedural Statements
COE 202 Introduction to Verilog
Presentation transcript:

Hardware Description Languages: Verilog Structural Models (Combinational) Behavioral Models Syntax Examples 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Typical Hardware 234262 - Spring 2017 - tutorial 2: Verilog

Design Methodology HDL Specification Simulation Synthesis Structure and Function (Behavior) of a Design Simulation Synthesis Verification: Design Behave as Required? Functional: I/O Behavior Generation: Map Specification to Implementation 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Supports structural and behavioral descriptions Structural Explicit structure of the circuit How a module is composed as an interconnection of more primitive modules/components E.g., each logic gate instantiated and connected to others Behavioral Program describes input/output behavior of circuit Many structural implementations could have same behavior E.g., different implementations of one Boolean function 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog Introduction the module describes a component in the circuit Two ways to describe: Structural Verilog List of components and how they are connected Just like schematics, but using text Hard to write, hard to decode Useful if you don’t have integrated design tools (today everybody have integrated design tools ) Behavioral Verilog Describe what a component does, not how it does it Synthesized into a circuit that has this behavior 234262 - Spring 2017 - tutorial 2: Verilog

Structural Model Composition of primitive gates to form more complex module Note use of wire declaration! module xor_gate (out, a, b); input a, b; output out; wire abar, bbar, t1, t2; inverter invA (abar, a); inverter invB (bbar, b); and_gate and1 (t1, a, bbar); and_gate and2 (t2, b, abar); or_gate or1 (out, t1, t2); endmodule By default, identifiers are wires 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Structural Model Example of full-adder module full_addr (A, B, Cin, S, Cout); input A, B; input Cin; output S; output Cout; assign {Cout, S} = A + B + Cin; endmodule module full_adder (A, B, Cin, S, Cout); input A, B; wire temp1,temp2,temp3; and_gate (temp1, A, B); and_gate (temp2, A, Cin); and_gate (temp3, B, Cin); or_gate (Cout, temp1, temp2, temp3); xor_gate (S, A , B , Cin); Behavior Structural 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Structural Model Example of full-adder module full_addr4 (A, B, Cin, S, Cout); input [3:0] A, B; input Cin; output [3:0] S; output Cout; assign {Cout, S} = A + B + Cin; endmodule module full_adder4 (A, B, Cin, S, Cout); wire C1, C2, C3; full_addr fa0 (A[0], B[0], Cin, S[0], C1); full_addr fa1 (A[1], B[1], C1, S[1], C2); full_addr fa2 (A[2], B[2], C2, S[2], C3); full_addr fa3 (A[3], B[3], C3, S[3], Cout); Behavior Structural 234262 - Spring 2017 - tutorial 2: Verilog

Simple Behavioral Model Combinational logic Describe output as a function of inputs Note use of assign keyword: continuous assignment module and_gate (out, in1, in2); input in1, in2; output out; wire out ;//default assign out = in1 & in2; endmodule 234262 - Spring 2017 - tutorial 2: Verilog

Verilog Data Types and Values Bits - value on a wire 0, 1 X - don’t know/ driven by more then one gate to different value Z - undriven Vectors of bits wire [3:0] A- vector of 4 bits: A[3], A[2], A[1], A[0] Treated as an unsigned integer value e.g. , A < 0 ?? Concatenating bits/vectors into a vector e.g., sign extend wire [7:0] B= {A[3], A[3], A[3], A[3], A[3:0]}; wire [7:0] B= {4{A[3]}, A[3:0]}; Style: Use a[7:3] = b[7:3] + c; המשמעות של Z היא "העדר זרם" (או "High Impedance"). 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog Numbers 14 - ordinary decimal number -14 - 2’s complement representation 12’b0000_0100_0110 - binary number with 12 bits (_ is ignored) 12’h046 - hexadecimal number with 12 bits Verilog values are unsigned e.g., C[4:0] = A[3:0] + B[3:0]; if A = 0110 (6) and B = 1010(10 not -6) C = 10000 not 00000 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog Operators פעולות Reduction מבוצעות על משתנה (וקטור) יחיד, והתוצאה היא ביט בודד (למשל, AND של כל הביטים בווקטור, וכו'). פעולת === נבדלת מפעולת == בהתנהגות שלהן כאשר בקלטים יש ביטי X או Z (הן זהות כאשר כל הביטים הם 0 או 1). 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog “Variables” wire Variable used simply to connect components together reg Variable that saves a value as part of a behavioral description Usually corresponds to a wire in the circuit Is NOT necessarily a register in the circuit 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog Module Corresponds to a circuit component “Parameter list” is the list of external connections, aka “ports” Ports are declared “input”, “output” or “inout” inout ports used on tri-state buses Port declarations imply that the variables are wires )default) module name ports module full_addr (A, B, Cin, S, Cout); input A, B, Cin; output S, Cout; assign {Cout, S} = A + B + Cin; endmodule inputs/outputs 234262 - Spring 2017 - tutorial 2: Verilog

Verilog Continuous Assignment Assignment is continuously evaluated assign corresponds to a connection or a simple component with the described function Target is NEVER a reg variable use of Boolean operators (~ for bit-wise, ! for logical negation) assign A = X | (Y & ~Z); assign C[15:0] = 16'h00ff; assign {Cout, S[3:0]} = A[3:0] + B[3:0] + Cin; variables can be n-bits wide (MSB:LSB) המשמעות של "continuous assignment" (בהתייחס למשפטי assign) היא שההשמה מבוצעת כל הזמן: כלומר, תמיד מובטח שהשוויון מתקיים. לעומת זאת, בלוק always מתבצע רק כאשר התנאי שבראשו מתקיים. use of arithmetic operator multiple assignment (concatenation) 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Comparator Example module Compare1 (A, B, Equal, A_larger, B_larger); input [3:0] A, B; output Equal, A_larger, B_larger; assign Equal = A == B; assign A_larger = A > B; assign B_larger = A< B; endmodule 234262 - Spring 2017 - tutorial 2: Verilog

Simple Behavioral Model: the always block Always waiting for a change to a trigger signal Then executes the body module and_gate (out1, out2, out3, clk,in1, in2); input in1, in2; output out1 , out2, out3; reg out1 , out2; always @(posedge clk) begin out1 <= in1 & in2; end always @(in1 or in2) begin out2 = in1 & in2; end assign out3 = in1 & in2; endmodule Specifies when block is executed I.e., triggered by which signals Not a real register!! In this case a variable would implemented as a wire הביטוי posedge פירושו "עלייה מ-0 לוגי ל-1 לוגי". הביטוי always @(x or y)‎ פירושו שבלוק ה-always מבוצע כאשר ערכו של x עובר שינוי או ערכו של y עובר שינוי. כאשר מקצים ערך למשתנה בתוך בלוק always, קיימים שני אופרטורי הקצאה אפשריים: אופרטור = שפירושו "הקצאה חוסמת": הקצאה שמבוצעת באופן מיידי. אופייני לערכים צירופיים. אופרטור ‎<=‎ שפירושו "הקצאה לא-חוסמת": הקצאה שמבוצעת רק לאחר סיום ביצוע בלוק ה-always (בדומה למערכות סינכרוניות, שם מחכים לסיום מחזור השעון בטרם מתעדכנים ערכי הרגיסטרים). אופייני לרגיסטרים. , המשמעות של המודול היא שכל הפלטים out1, out2, out3 מחושבים באותו אופן (כ-AND של הקלטים in1 ו-in2); אבל הם מתעדכנים בזמנים שונים: out1 מתעדכן כאשר אות השעון clk עולה מ-0 ל-1. (לכן out1 הוא רגיסטר.) out2 מתעדכן כאשר in1 או in2 משנה את ערכו (בדיוק מתי שצריך לפלט צירופי - ואכן, out2 בהחלט לא חייב להיות רגיסטר). out3 מתעדכן באופן רציף (ולכן זהה ל-out2). out2 and out 3 are identical 234262 - Spring 2017 - tutorial 2: Verilog

Incomplete Triggers - dangerous for the novice! NOT combinational logic  latch is inserted (implied memory) Variable keeps its old value module and_gate (out, in1, in2); input in1, in2; output out; reg out; always @(in1) begin out = in1 & in2; end endmodule always @(x) פירושו שבלוק ה-always מבוצע כאשר ערכו של x עובר שינוי. האזהרה היא מפני האפשרות שהערך שמקצים לא יתעדכן למרות שרוצים שהוא יתעדכן. במקרה זה - רוצים שהערך out יתעדכן גם כאשר in2 משתנה ולא רק כאשר in1 משתנה (כי לפי הקוד שבשקף, הוא נשאר כפי שהוא גם אם in2 משתנה, מה שגורם לסתירה בין הקלטים והפלט של השער AND), ולכן חיוני להחליף את always @(in1)‎ ב-always @(in1 or in2)‎. מבחינת המימוש - הכיתוב המתוקן זהה ל-assign וימומש בעזרת לוגיקה צירופית (שער AND) בלבד; הכיתוב המקורי מחייב מימוש בעזרת רגיסטר, כי הפלט out שומר על ערכו הישן כל עוד in1 לא השתנה (אפילו אם in2 כבר השתנה). Any variable assigned in an always block should be assigned for any (and every!) execution of the block 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog if Same as C if statement // Simple 4:1 mux module mux4 (select, A, B, C, D, Y); input [1:0] select; // 2-bit control signal input A, B, C, D; output Y; reg Y; // target of assignment always @(select or A or B or C or D) if (select == 2’b00) Y = A; else if (select == 2’b01) Y = B; else if (select == 2’b10) Y = C; else if (select == 2’b11) Y = D; endmodule 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog if Another way // Simple 4:1 mux module mux4 (sel, A, B, C, D, Y); input [1:0] sel; // 2-bit control signal input A, B, C, D; output Y; reg Y; // target of assignment always @(sel or A or B or C or D) if (sel[1] == 0) if (sel[0] == 0) Y = A; else Y = B; else if (sel[0] == 0) Y = C; else Y = D; endmodule 234262 - Spring 2017 - tutorial 2: Verilog

Verilog case Sequential execution of cases Only first case that matches is executed (implicit break) Default case can be used // Simple 4-1 mux module mux4 (sel, A, B, C, D, Y); input [1:0] sel; // 2-bit control signal input A, B, C, D; output Y; reg Y; // target of assignment always @(sel or A or B or C or D) case (sel) 2’b00: Y = A; 2’b01: Y = B; 2’b10: Y = C; 2’b11: Y = D; endcase endmodule Conditions tested in top to bottom order 234262 - Spring 2017 - tutorial 2: Verilog

234262 - Spring 2017 - tutorial 2: Verilog Verilog case Without the default case, this example would create a latch for Y Assigning X to a variable means synthesis is free to assign any value // Simple binary encoder (input is 1-hot) module encode (A, Y); input [7:0] A; // 8-bit input vector output [2:0] Y; // 3-bit encoded output reg [2:0] Y; // target of assignment always @(A) case (A) 8’b00000001: Y = 0; 8’b00000010: Y = 1; 8’b00000100: Y = 2; 8’b00001000: Y = 3; 8’b00010000: Y = 4; 8’b00100000: Y = 5; 8’b01000000: Y = 6; 8’b10000000: Y = 7; default: Y = 3’bXXX; // Don’t care when input is not 1-hot endcase endmodule 234262 - Spring 2017 - tutorial 2: Verilog