COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.

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

CPSC 321 Computer Architecture Andreas Klappenecker
//HDL Example 4-10 // //Gate-level description of circuit of Fig. 4-2 module analysis (A,B,C,F1,F2); input.
Verilog.
Synchronous Sequential Logic
EE 361 Fall 2003University of Hawaii1 Hardware Design Tips EE 361 University of Hawaii.
Combinational Logic.
Verilog Modules for Common Digital Functions
Verilog Intro: Part 1.
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.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
Verilog Module Module declaration Module instantiation module Add_full (sum, c_out, a, b, c_in); // parent module input a, b, c_in; output c_out, sum;
ENEE 408C Lab Capstone Project: Digital System Design Verilog Tutorial Class Web Site:
ECEN ECEN475 Introduction to VLSI System Design Verilog HDL.
Introduction to Verilog Multiplexers. Introduction to Verilog Verilog Hardware Description Language (Verilog HDL) released by Gateway Design Automation.
Verilog Intro: Part 2. Procedural Blocks There are two types of procedural blocks in Verilog. – initial for single-pass behavior : initial blocks execute.
Verilog Descriptions of Digital Systems. Electronic Lock // // Electronic combinational lock // module lock(seg7,key, valid_key, col, row, mclk, resetL)
Overview Logistics Last lecture Today HW5 due today
Spring 2007W. Rhett Davis with minor modification by Dean Brock UNCA ECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 7: Design Example,
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.
Figure 6.1. A 2-to-1 multiplexer.
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.
ECE 551 Digital Design And Synthesis
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
COE 405 Logic Design with Behavioral Models of Combinational & Sequential Logic Dr. Aiman H. El-Maleh Computer Engineering Department King Fahd University.
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.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Verilog Part 3 – Chapter.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
M.Mohajjel. Structured Procedures Two basic structured procedure statements always initial All behavioral statements appear only inside these blocks Each.
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.
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.
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
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
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
Verilog Tutorial Fall
TODAY’S OUTLINE Verilog Codings Concurrent and Sequential If-else
Introduction to Verilog
Verilog Introduction Fall
Behavioral Modeling Structural modeling Behavioral modeling
Supplement on Verilog Sequential circuit examples: FSM
Verilog-HDL-3 by Dr. Amin Danial Asham.
Hardware Description Languages: Verilog
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Introduction to Verilog
Behavioral Modeling in Verilog
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Verilog.
COE 202 Introduction to Verilog
Chapter 4: Behavioral Modeling
COE 202 Introduction to Verilog
Supplement on Verilog Sequential circuit examples: FSM
Supplement on Verilog adder examples
The Verilog Hardware Description Language
Supplement on Verilog combinational circuit examples
Introduction to Digital IC Design
COE 202 Introduction to Verilog
Lecture 7: Verilog Part II
Presentation transcript:

COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals

Outline  Always block  Procedural Assignment  If Statements  Case Statements  Comparator  Arithmetic & Logic Unit  Multiplexor  Encoder  Priority Encoder  Decoder

Always Block  always blocks are procedural blocks that contain sequential statements.  Syntax  list) begin  end  sensitivity list prevents the always block from executing again until another change occurs on a signal in the sensitivity list.  Level type  or b or c)  Edge type  clock)  clock)

Procedural Assignment  Assignments inside an always block are called procedural assignments  Can only be used within an always block  Two types : blocking assignment and nonblocking assignment. Basic syntax :  [variable-name] = [expression] ; // blocking assignment  [variable-name] <= [expression] ; // nonblocking assignment  In a blocking assignment, the expression is evaluated and then assigned to the variable immediately, before execution of the next statement (the assignment thus "blocks" the execution of other statements). It behaves like the normal variable assignment in the C language.

Procedural Assignment  In a nonblocking assignment, the evaluated expression is assigned at the end of the always block (the assignment thus does not block the execution of other statements).  The basic rule of thumb is:  Use blocking assignments for a combinational circuit.  Use nonblocking assignments for a sequential circuit  There are two types of variables in Verilog:  wire (all outputs of assign statements must be wire)  reg (all outputs modified in always blocks must be reg)  if-else and case statement are only in always block.

If Statements if (expression) begin...procedural statements... end else if (expression) begin...statements... end...more else if blocks else begin...statements... end module ALU #(parameter n=8) (output reg [n-1:0] c, input [1:0] s, input [n-1:0] a, b); or a or b) begin if (s==2'b00) c = a + b; else if (s==2'b01) c = a - b; else if (s==2'b10) c = a & b; else c = a | b; end endmodule

Case Statements case (expression) case_choice1: begin...statements... end case_choice2: begin...statements... end...more case choices blocks... default: begin...statements... end endcase module ALU2 #(parameter n=8) (output reg [n-1:0] c, input [1:0] s, input [n-1:0] a, b); or a or b) begin case (s) 2'b00: c = a + b; 2'b01: c = a - b; 2'b10: c = a & b; default: c = a | b; endcase end endmodule

Full Adder module fadd2 (output reg S, Cout, input A, B, Cin); or B or Cin) begin S = (A ^ B ^ Cin); Cout = (A & B) | (A & Cin) | (B & Cin); end endmodule

Comparator module comp #(parameter width=32) (input [width-1:0] A, B, output A_gt_B, A_lt_B, A_eq_B); assign A_gt_B = (A>B); assign A_lt_B = (A<B); assign A_eq_B = (A==B); endmodule

Comparator module comp2 #(parameter width=2) (input [width-1:0] A, B, output reg A_gt_B, A_lt_B, A_eq_B); B) begin A_gt_B = 0; A_lt_B = 0; A_eq_B = 0; if (A == B) A_eq_B = 1; else if (A > B) A_gt_B = 1; else A_lt_B = 1; end endmodule

Arithmetic Unit module arithmetic #(parameter width=8) (input [width-1:0] A, B, input [1:0] Sel, output reg [width-1:0] Y, output reg Cout); or B or Sel) begin case (Sel) 2'b 00 : {Cout,Y} = A+B; 2'b 01 : {Cout,Y} = A-B; 2'b 10 : {Cout,Y} = A+1; 2'b 11 : {Cout,Y} = A-1; default: begin Cout=0; Y=0; end endcase end endmodule

Logic Unit module logic #(parameter width=4) (input [width-1:0] A, B, input [2:0] Sel, output reg [width-1:0] Y); or B or Sel) begin case (Sel) 3'b 000 : Y = A & B; // A and B 3'b 001 : Y = A | B; // A or B 3'b 010 : Y = A ^ B; // A xor B 3'b 011 : Y = ~A; // 1’s complement of A 3'b 100 : Y = ~(A & B); // A nand B 3'b 101 : Y = ~(A | B); // A nor B default : Y = 0; endcase end endmodule

2x1 Multiplexer Method 1 module mux2x1 (input b, c, select, output a); assign a = (select ? b : c); endmodule Method 2 module mux2x1 (input b, c, select, output reg a); or b or c) begin if (select) a=b; else a=c; end endmodule Method 3 module mux2x1 (input b, c, select, output reg a); or b or c) begin case (select) 1’b1: a=b; 1’b0: a=c; endcase end endmodule

Encoder module encoder (output reg [2:0] Code, input [7:0] Data); if (Data==8'b ) Code = 0; else if (Data==8'b ) Code = 1; else if (Data==8'b ) Code = 2; else if (Data==8'b ) Code = 3; else if (Data==8'b ) Code = 4; else if (Data==8'b ) Code = 5; else if (Data==8'b ) Code = 6; else if (Data==8'b ) Code = 7; else Code = 'bx; endmodule

Priority Encoder module priority_encoder (output reg [2:0] Code, output valid_data, input [7:0] Data); assign valid_data = | Data; if (Data[7]) Code = 7; else if (Data[6]) Code = 6; else if (Data[5]) Code = 5; else if (Data[4]) Code = 4; else if (Data[3]) Code = 3; else if (Data[2]) Code = 2; else if (Data[1]) Code = 1; else if (Data[0]) Code = 0; else Code = 'bx; endmodule

Priority Encoder module priority_encoder2 (output reg [2:0] Code, output valid_data, input [7:0] Data); assign valid_data = | Data; case (Data) 8'b1xxxxxxx : Code = 7; 8'b01xxxxxx : Code = 6; 8'b001xxxxx : Code = 5; 8'b0001xxxx : Code = 4; 8'b00001xxx : Code = 3; 8'b000001xx : Code = 2; 8'b x : Code = 1;8'b : Code = 0; default: Code = 'bx; endcase endmodule

Decoder module decoder (output reg [7:0] Data, input [2:0] Code); if (Code == 0 ) Data= 8'b ; else if (Code == 1 ) Data= 8'b ; else if (Code == 2 ) Data= 8'b ; else if (Code == 3 ) Data= 8'b ; else if (Code == 4 ) Data= 8'b ; else if (Code == 5 ) Data= 8'b ; else if (Code == 6 ) Data= 8'b ; else if (Code == 7 ) Data= 8'b ; else Data = 'bx; endmodule

Seven Segment Display Decoder module Seven_Segment_Display (output reg [6:0] Display, input [3:0] BCD); parameter BLANK = 7’b111_1111; parameter ZERO= 7’b000_0001; //abc_defg parameter ONE= 7’b100_1111; parameter TWO= 7’b001_0010; parameter THREE= 7’b000_0110; parameter FOUR= 7’b100_1100; parameter FIVE= 7’b010_0100; parameter SIX= 7’b010_0000; parameter SEVEN= 7’b000_1111; parameter EIGHT= 7’b000_0000; parameter NINE= 7’b000_0100; case (BCD) 0: Display = ZERO; 1: Display = ONE; 2: Display = TWO; 3: Display = THREE; 4: Display = FOUR; 5 : Display = FIVE; 6: Display = SIX; 7: Display = SEVEN; 8: Display = EIGHT; 9: Display = NINE; default: DISPLAY = BLANK; endcase endmodule