Supplement on Verilog FF circuit examples

Slides:



Advertisements
Similar presentations
Digital System Design-II (CSEB312)
Advertisements

Recap : Always block module and_gate (out, in1, in2); inputin1, in2; outputout; regout; or in2) begin out = in1 & in2; end endmodule zAlways.
Simulation executable (simv)
Supplement on Verilog adder examples
Synchronous Sequential Logic
Combinational Logic.
Verilog Modules for Common Digital Functions
Table 7.1 Verilog Operators.
//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.
Registers and Counters. Register Register is built with gates, but has memory. The only type of flip-flop required in this class – the D flip-flop – Has.
1 COMP541 Sequential Circuits Montek Singh Sep 17, 2014.
Lecture 12 Latches Section , Block Diagram of Sequential Circuit gates New output is dependent on the inputs and the preceding values.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
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.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Advanced Verilog EECS 270 v10/23/06.
Registers and Shift Registers Discussion D8.2. D Flip-Flop X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
A State Element “Zoo”.
Introduction to Counter in VHDL
Figure 7.1. Control of an alarm system. Memory element Alarm Sensor Reset Set OnOff 
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
Registers & Counters M. Önder Efe
Introduction to FPGA AVI SINGH. Prerequisites Digital Circuit Design - Logic Gates, FlipFlops, Counters, Mux-Demux Familiarity with a procedural programming.
ECE 2372 Modern Digital System Design
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
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.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
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.
COMP541 Sequential Circuits
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.
Structural Description
Overview Logistics Last lecture Today HW5 due today
Lecture 10 Flip-Flops/Latches
Verilog Tutorial Fall
Class Exercise 1B.
Supplement on Verilog for Algorithm State Machine Chart
Lecture 11 Registers and Counters
Last Lecture Talked about combinational logic always statements. e.g.,
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
COMP541 Sequential Circuits
‘if-else’ & ‘case’ Statements
HDL for Sequential Circuits
Supplement on Verilog Sequential circuit examples: FSM
TODAY’S OUTLINE Procedural Assignments Verilog Coding Guidelines
Registers and Counters
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
Chapter 9: Sequential Logic Modules
SYNTHESIS OF SEQUENTIAL LOGIC
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Registers and Counters
332:437 Lecture 8 Verilog and Finite State Machines
Chapter 4: Behavioral Modeling
COE 202 Introduction to Verilog
6. Registers and Counters
Supplement on Verilog Sequential circuit examples: FSM
Register-Transfer Level Components in Verilog
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Registers and Counters
332:437 Lecture 8 Verilog and Finite State Machines
Sequntial-Circuit Building Blocks
(Sequential-Circuit Building Blocks)
Presentation transcript:

Supplement on Verilog FF circuit examples Based on Fundamentals of Digital Logic with Verilog Design, Fundamentals of Logic Design, and MIT slides Chung-Ho Chen

A Gated D Latch module D_latch (D, Clk, Q); input D, Clk; Whenever D or Clk changes, Q changes. Clk module D_latch (D, Clk, Q); input D, Clk; output reg Q; always @(D, Clk) if (Clk) Q = D; endmodule Not a real register!! A Verilog register needed because of assignment in always block Q = D if Clk = 1, the Verilog compiler assumes that the value of Q caused by the if must be maintained when Clk is not equal to 1. This implies that a memory, a latch is instantiated.

A D Flip-Flop module flipflop (D, Clk, Q); input D, Clk; output reg Q; negedge posedge module flipflop (D, Clk, Q); input D, Clk; output reg Q; always @(posedge Clk) Q = D; endmodule

Blocking assignment: evaluation and assignment are immediate Blocking assignment: always @ (a or b or c) begin x = a | b; 1. evaluate a | b, and assign result to x y = a ^ b ^ c; 2. evaluate a ^ b^c, and assign result to y end

Non-Blocking assignment Nonblocking assignment: all assignments deferred until all right-hand sides have been evaluated (end of simulation timestep) always @ (a or b or c) begin x <= a | b; 1. evaluate a | b, but defer assignment of x y <= a ^ b ^ c; 2. evaluate a ^ b^c, but defer assignment of y end 3. assign x, y with their new values Non-blocking assignment is 2-step processes: Step 1: Evaluate the RHS Step 2: Update the LHS Sometimes, as above, blocking and non-blocking produce the same result. Sometimes, not!

Why two ways of assigning values?

Use blocking assignment for combinational always blocks always @ (input a, b, c, output reg x, y) begin x = a & b; y = x | c; end always @ (input a, b, c, output reg x, y) begin x <= a & b; y <= x | c; end a b c x y 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 x<=0, new value for x is 0, but not assigned yet. 0 1 0 1 1 x<=0, y <=1 0 1 0 0 1 assignment completion Non-Blocking behavior Initial condition a changes; always block triggered x = a & b; y = x | c; This is incorrect!

Verilog Simulation Behavior Always blocks and “assign” statements execute in parallel Signals in the sensitivity list (@(..)) trigger the always blocks. “assign” triggered when RHS signal changes. All non-blocking assignment statements in an always block are evaluated using the values that the variables have when the always block is entered. That is, a given variable has the same value for all statements in the block. The result of each non-blocking assignment is not seen until the end of the always block.

Blocking Assignment module two-FFs (D, Clock, Q1, Q2); input D, Clock; output reg Q1, Q2; always @(posedge Clock) begin Q1 = D; Q2 = Q1; end endmodule // blocking assignment here, so at each rising clock edge, Q1=D, after that, Q2 = Q1, finally Q2=Q1=D This implies a circuit below:

Non-Blocking Assignment module two-FFs (D, Clock, Q1, Q2); input D, Clock; output reg Q1, Q2; always @(posedge Clock) begin Q1 <= D; Q2 <= Q1; end // at the end of always block, Q1 and Q2 change to a new value concurrently. endmodule // at the rising clock edge, Q1 and Q2 simultaneously receive the old values of D, and Q1.

D-FF with Asynchronous Reset (Clear) module flipflop (D, Clock, ClrN, Q); input D, Clock, ClrN; output reg Q; always @(negedge ClrN, posedge Clock) if (!ClrN) // if clear, then, Q <= 0; else // normal update Q <= D; endmodule What about both? PreN and ClrN

D-FF with Synchronous Reset module flipflop (D, Clock, ClrN, Q); input D, Clock, ClrN; output reg Q; always @(posedge Clock) if (!ClrN) // if clear, then, Q <= 0; else // normal update Q <= D; endmodule What about both? PreN and ClrN

n-bit register Naming: Resetn 16 bits here Asynchronous clear module regn (D, Clock, Resetn, Q); parameter n = 16; input [n-1:0] D; input Clock, Resetn; output reg [n-1:0] Q;   always @(negedge Resetn, posedge Clock) if (!Resetn) Q <= 0; else Q <= D; endmodule Naming: Resetn 16 bits here Asynchronous clear

Shift Register L: load register with input. module shift4 (R, L, Din, Clock, Q); input [3:0] R; input L, Din, Clock; output reg [3:0] Q;   always @(posedge Clock) if (L) Q <= R; else begin Q[0] <= Q[1]; Q[1] <= Q[2]; Q[2] <= Q[3]; Q[3] <= Din; end endmodule  L: load register with input. Non-blocking statements, so that value before clock edge is shifted into the destination bit, at the end of the always block. DFF 2 Q2 DFF 3 D Q3 DFF 0 Q1 Din Q0

Up Counter with enable module upcount (Resetn, Clock, E, Q); input Resetn, Clock, E; output reg [3:0] Q; always @(negedge Resetn, posedge Clock) if (!Resetn) Q <= 0; else if (E) Q <= Q + 1; endmodule If not reset, at rising edge and enabled, increment the counter by 1

Up/down Counter with enable module UDcount (R, Clock, L, E, up_down, Q); parameter n = 8; input [n-1:0] R; input Clock, L, E, up_down; output reg [n-1:0] Q; always @(posedge Clock) if (L) Q <= R; else if (E) Q <= Q + (up_down ? 1 : -1); endmodule Q <= Q+1 Q <= Q-1

FF with an enable module rege (D, Clock, Resetn, E, Q); input D, Clock, Resetn, E; output reg Q;   always @(posedge Clock, negedge Resetn) if (Resetn == 0) Q <= 0; else if (E) Q <= D; endmodule