Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.

Slides:



Advertisements
Similar presentations
Synchronous Sequential Logic
Advertisements

Combinational Logic.
Table 7.1 Verilog Operators.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
Slide 1 7. Verilog: Combinational always statements. VHDL: Combinational Processes: To avoid (I.E. DO NOT What in your HDL code?) Cases that generate Synthesis.
Verilog - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
ECE 551 Digital System Design & Synthesis Lecture 09 Synthesis of Common Verilog Constructs.
Digital System Design by Verilog University of Maryland ENEE408C.
Copyright © 2007 Elsevier4- Chapter 4 :: Hardware Description Languages Digital Design and Computer Architecture David Money Harris and Sarah L. Harris.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
ELEN 468 Lecture 161 ELEN 468 Advanced Logic Design Lecture 16 Synthesis of Language Construct II.
Kazi Fall 2006 EEGN 4941 EEGN-494 HDL Design Principles for VLSI/FPGAs Khurram Kazi Some of the slides were taken from K Gaj’s lecture slides from GMU’s.
ELEN 468 Advanced Logic Design
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,
Sequential Logic in Verilog
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
Registers & Counters M. Önder Efe
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.
Slide 1 2. Verilog Elements. Slide 2 Why (V)HDL? (VHDL, Verilog etc.), Karen Parnell, Nick Mehta, “Programmable Logic Design Quick Start Handbook”, Xilinx.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
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.
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.
Verilog for Synthesis Ing. Pullini Antonio
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Slide 1 2. Verilog Elements. Slide 2 Why (V)HDL? (VHDL, Verilog etc.), Karen Parnell, Nick Mehta, “Programmable Logic Design Quick Start Handbook”, Xilinx.
3/4/20031 ECE 551: Digital System Design * & Synthesis Lecture Set 3 3.1: Verilog - User-Defined Primitives (UDPs) (In separate file) 3.2: Verilog – Operators,
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:
ELEN 468 Lecture 131 ELEN 468 Advanced Logic Design Lecture 13 Synthesis of Combinational Logic II.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
M.Mohajjel. Structured Procedures Two basic structured procedure statements always initial All behavioral statements appear only inside these blocks Each.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
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.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 6: Procedural Modeling Spring 2009 W. Rhett.
03/31/031 ECE 551: Digital System Design & Synthesis Lecture Set 8 8.1: Miscellaneous Synthesis (In separate file) 8.2: Sequential Synthesis.
1 COMP541 State Machines - II Montek Singh Feb 13, 2012.
Slide 1 3.VHDL/Verilog Description Elements. Slide 2 To create a digital component, we start with…? The component’s interface signals Defined in MODULE.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 8.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Finite State Machine -Moore & Mealy Machine -State Encoding Techniques.
Pusat Pengajian Kejuruteraan Mikroelektronik EMT 351/4 DIGITAL IC DESIGN Verilog Behavioural Modeling (Part 4) Week #
Overview Logistics Last lecture Today HW5 due today
Verilog Tutorial Fall
Supplement on Verilog FF circuit examples
Figure 8.1. The general form of a sequential circuit.
4.VHDL/Verilog Hierarchical Description
Last Lecture Talked about combinational logic always statements. e.g.,
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
‘if-else’ & ‘case’ Statements
Supplement on Verilog Sequential circuit examples: FSM
Sequential logic examples
HDL Compiler Unsupport (Do NOT use in your verilog code)
SYNTHESIS OF SEQUENTIAL LOGIC
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
COE 202 Introduction to Verilog
Supplement on Verilog Sequential circuit examples: FSM
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
ECE 551: Digital System Design & Synthesis
Sequntial-Circuit Building Blocks
Lecture 7: Verilog Part II
Presentation transcript:

Slide 1 6. VHDL/Verilog Behavioral Description

Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them using behavioral description in a single module Connect the various components using internal signals Advantages: Often allows for shorter description A single module may be needed to describe a project consisting of various components Easier to understand the behavior of the internal components Disadvantages: It might reduce code readability – Comments here are necesarry! Can lead to large files i.e. hundredths of lines of code

Slide 3 Verilog for Synthesis: Behavioral description example SSG Decoder again: module Ssg_decoder #( parameter CLK_FREQ = , parameter REFRESH_RATE = 1000) (input CLK, input RESET, input [15:0] DIN, output [3:0] AN, output [6:0] SSG); //now we need more internal signals //to make the frequency divider wire CE; integer Freq_divider; //to make the shift register reg [3:0] AN_Int; //to make the multiplexer wire [3:0] mux_data; //mux_addr disappeard! The priority //decoder will be also made using behavioral // description //to make the Hex_to_ssg_decoder reg [6:0] SSG_Int; CLK CE_div Freq_divider Din CLK 16 Ssg_decoder CLK CE Shift_reg_walk_0 RESET AN 4 Din Dout Priority_decoder 4 2 I0 4 I1 4 I2 4 I3 4 O 4 2 A Mux_4X_4To1 Din Dout Hex_to_ssg_encoder SSG AN 4 Din[3:0] [7:4] [11:8] [15:11] RESET CE AN_Int mux_data mux_addr CLK RESET Din 16 #(CLK_FREQ REFRESH_RATE) #(CLK_FREQ, DIV_RATE) Ssg_decoder #(CLK_FREQ REFRESH_RATE) AN 4 7 SSG CE AN_Int mux_addr mux_data #(CLK_FREQ, DIV_RATE) #(CLK_FREQ REFRESH_RATE)

Slide 4 SSG Decoder again: //describe the divider (posedge CLK) if (Freq_divider == ((CLK_FREQUENCY_HZ/REFRESH_RATE) - 1 )) Freq_divider <=0; else Freq_divider <= Freq_divider + 1; //assign the divided signal assign CE = (CE_div == ((CLK_FREQUENCY_HZ/REFRESH_RATE) - 1 )) ? 1:0; //note: CE is one-shot signal! //describe the walking 0 shift register (posedge CLK or posedge RESET) if (RESET) AN_Int<=4'hf; else if (CE) if (AN_Int==4'b0111 || AN_Int==4'b0000 || AN_Int==4'b1111) AN_Int<=4'b1110; else AN_Int <= {AN_Int[2:0],1'b1}; //shift register Verilog for Synthesis: Behavioral description example

Slide 5 SSG Decoder again: //Priority encoder and multiplexer combined assign mux_data = (An_Int==4'b1110) ? DIN[3:0] : (An_Int==4'b1101) ? DIN[7:4] : (An_Int==4'b1011) ? DIN[11:8] : (An_Int==4'b0111) ? DIN[15:12] : 4'h0; Verilog for Synthesis: Behavioral description example

Slide 6 SSG Decoder again: //write the seven segment decoder (mux_data) case (mux_data) 4'b0001: Ssg_Int=7'b ; //1 4'b0010: Ssg_Int=7'b ; //2 4'b0011: Ssg_Int=7'b ; //3 4'b0100: Ssg_Int=7'b ; //4 4'b0101: Ssg_Int=7'b ; //5 4'b0110: Ssg_Int=7'b ; //6 4'b0111: Ssg_Int=7'b ; //7 4'b1000: Ssg_Int=7'b ; //8 4'b1001: Ssg_Int=7'b ; //9 4'b1010: Ssg_Int=7'b ; //A 4'b1011: Ssg_Int=7'b ; //B 4'b1100: Ssg_Int=7'b ; //C 4'b1101: Ssg_Int=7'b ; //D 4'b1110: Ssg_Int=7'b ; //E 4'b1111: Ssg_Int=7'b ; //F default: Ssg_Int=7'b ; //0 endcase Verilog for Synthesis: Behavioral description example

Slide 7 SSG Decoder again: //Do NOT forget to assign the outputs! //Otherwise, the module will be REMOVED //by the synthesizer assign AN = AN_Int; assign SSG = SSG_Int; // Suggestion 1: better make the output //assignment at the beginning of the file! //Suggestion 2: for each component to be made, //write its comment first, then fill the code //with instructions! Such as: //Here comes the frequency divider //Here comes the shift register //… endmodule Verilog for Synthesis: Behavioral description example

Slide 8 SSG Decoder again: //Do NOT forget to assign the outputs! //Otherwise, the module will be REMOVED //by the synthesizer assign AN = AN_Int; assign SSG = SSG_Int; // Suggestion 1: better make the output //assignment at the beginning of the file! //Suggestion 2: for each component to be made, //write its comment first, then fill the code //with instructions! Such as: //Here comes the frequency divider //Here comes the shift register //… endmodule Verilog for Synthesis: Behavioral description example

Slide 9 Q: Which one should I use: Behavioral or Hierarchical description? A: It depends... Create modules that can be REUSED. Those later can be used as hierarchical components in other projects. Examples: Ssg_Decoder Your components in your project need to run at several different frequencies? Create a PARAMETRIZED divider then use it! You can describe the divider using behavioral description, NOT as a set of counters and comparators! Conclusion (?): Decide based on the experience you have I.e. try both There is a reason for the existence of project managers! Verilog for Synthesis: Behavioral description

Slide 10 Q: What signals should I declare: wire or reg? A: 1. For SEQUENTIAL components/signals (components running synchronous to a clock signal): The answer is clearly reg (the signal has to be assigned in a (posedge CLK) statement! 2.For COMBINATIONAL components/signals: Use continuous (assign) assignments whenever possible (also if it worth) You avoid in this way incomplete assignments (what are those…?) – the syntax checker will generate an error in the case of an incomplete assignment! Combinational loops (again, what are those…?) cannot be avoided To describe logic with many inputs and outputs such as state- machine logic or decoders/encoders, consider using always statements There is a risk of both incomplete assignments and combinational loops Verilog for Synthesis: Behavioral description

Slide 11 To describe logic with many inputs and outputs such as state-machine logic or decoders/encoders, consider using always statements Example: the Hex_to_ssg decoder, if it would be made using continuous assignments: assign Ssg_Int = (mux_data == 4’b0001) ? 7’b : (mux_data == 4’b0010) ? 7’b : …. More text/symbols to write than using a case statement: case (mux_data) 4'b0001: Ssg_Int=7'b ; //1 4'b0010: Ssg_Int=7'b ; //2 … default: Ssg_Int=7'b ; //0 endcase Special casez or casex statements in Verilog: casez: treat ‘z’ as don’t care, casex: treat ‘z’ and ‘x’ as don’t care Used mostly in simulation (testbenches) Verilog for Synthesis: Behavioral description

Slide 12 Example: (posedge CLK or posedge Reset or posedge Load) if (Reset) cnt <= 0; else if (Load) cnt <= Din; else if (CE) cnt <= cnt +1; CLK will be the CLOCK signal NOT BECAUSE IS CALLED CLK! Because is the signal that is not present as a CONDITION in the code! Remember that the clock signal is the one that gives the RHYTHM of a synchronous circuit! (as a cowbell for cows or drum for music) Also, Reset is the reset signal, Load is the load signal, Reset has HIGHER PRIORITY, BOTH ARE ACTIVE_HIGH and BOTH ARE ASYNCHRONOUS because: The (Reset) condition causes cnt <= 0. (Reset) is equivalent to (Reset == 1’b1) (Reset is a reset signal) The (Load) condition causes cnt <= Din (Load is a load signal) Reset is checked BEFORE Load! (Reset has higher priority) BOTH signals are in the sensitivity list as posedge, also checked against 1 (Both are asynchronous and active-high) … Not because the reset signal is called Reset and … Verilog for Synthesis: Sequential always statements

Slide 13 Example: (posedge CLK or posedge Reset or posedge Load) if (Reset) cnt <= 0; else if (Load) cnt <= Din; else if (CE) cnt <= cnt +1; CE is a Clock Enable signal and is SYNCHRONOUS Because enables counting Because CE DOES NOT APPEAR IN THE SENSITIVITY LIST The asynchronous signals have always HIGHER priority than the synchronous signals Then the asynchronous signals have to be tested FIRST! Example (BAD): (posedge CLK or posedge Reset or posedge Load) if (CE) cnt <= cnt +1; else if (Reset) cnt <= Din;.. Verilog for Synthesis: Sequential always statements

Slide 14 Example: (posedge CLK or posedge Reset or posedge Load) if (Reset) cnt <= 0; else if (Load) cnt <= Din; else if (CE) cnt <= cnt +1; The asynchronous signals have always HIGHER priority than the synchronous signals Then the asynchronous signals have to be tested FIRST! Example (BAD): (posedge CLK or posedge Reset or posedge Load) if (CE) cnt <= cnt +1; else if (Reset) cnt <= Din; Example (GOOD!) (posedge CLK or posedge Reset or posedge Load) begin if (CE) cnt <= cnt +1; if (Load) cnt <= Din; if (Reset) cnt <= 0; The last change (if the condition is true) is cnt <= 0;. Therefore Reset has the highest priority! Not recommended. Some synthesizers may not recognize the counter Verilog for Synthesis: Sequential always statements

Slide 15 Example: (posedge CLK or posedge Reset or posedge Load) if (Reset) cnt <= 0; else if (Load) cnt <= Din; else if (CE) cnt <= cnt +1; The posedge or negedge statements have to be in conjunction with the condition tested Otherwise the synthesizer generates an error Examples (BAD): (posedge CLK or posedge Reset or posedge Load) if (!Reset) cnt <= cnt +1; else if (Reset) cnt <= Din; … (posedge CLK or negedge Reset or posedge Load) if (CE) cnt <= cnt +1; else if (Reset) cnt <= Din; … Verilog for Synthesis: Sequential always statements

Slide 16 Avoid describing combinational logic for asynchronous control signals! Example (BAD): (posedge CLK or posedge Reset1 or posedge Reset2) if (Reset1 || Reset2) cnt <= 0; else if (Load) cnt <= Din; else if (CE) cnt <= cnt +1; ISE 12.2 may accept it, ISE 12.3 or 13.X might not! (calling XST in batch mode from EDK, for example) Reason: it may “believe” that we want to syntesize a sequential circuit with two reset signals! Example (correct) wire Reset = Reset1 | Reset2; (posedge CLK or posedge Reset) if (Reset) cnt <= 0; … Verilog for Synthesis: Sequential always statements

Slide 17 Avoid using the SAME priority for asynchronous and synchronous control signals! Example (BAD): (posedge CLK or posedge Reset1) if (Reset1 || Reset2 || Reset3) cnt <= 0; else if (Load) cnt <= Din; else if (CE) cnt <= cnt +1; Reset1 is asynchronous, but Reset2 and Reset3 are synchronous! Have you seen a flip-flop with both synchronous and asynchronous reset, also with synchronous load? It is possible to make it. How? Then describe the circuit so! Example (correct): Make all of the reset signals either synchronous or asynchronous wire Reset = Reset1 | Reset2 | Reset3; (posedge CLK or posedge Reset) if (Reset) cnt <= 0; … Or: wire Reset = Reset1 | Reset2 | Reset3; (posedge CLK) … Verilog for Synthesis: Sequential always statements

Slide 18 Generates COMBINATIONAL CIRCUITS Example: (A or B or C) if (A) D <= 1; else if (B||C) D <=1; else D <= 0; What circuit will be generated by the synthesizer? Note: for combinational always statements, both changes (from 0 to 1 or from 1 to 0 matter) – combinational circuits may change their output when the input changes, regardless of a clock signal Do not use posedge or negedge conditions for combinational always statements! It may either: Make a sequential circuit, if there is an extra signal in the sensitivity list, or Synthesizer generates an error Verilog for Synthesis: Combinational always statements

Slide 19 Generates COMBINATIONAL CIRCUITS All the signals read inside the always statements should be on the sensitivity list, otherwise simulation differences appear between behavioral and post-translate! Reason: The syntesizer IGNORES the sensitivity list and will connect signals read inside the always statement, only generates a warning The simulator WILL NOT run the always statement when a signal changes, if the signal is not on the sensitivity list! Conclusion: DO NOT make exclusions based on the sensitivity list! Verilog for Synthesis: Combinational always statements

Slide 20 Combinational always statements: include decision-based statements: if..else, case..endcase Every if has to have an else branch! Every case has to contain every branch (default, if not) Otherwise: we have incomplete assignments that lead to latch inference! SO: What to avoid in combinational always statements? Verilog for Synthesis: Combinational always statements