L5: Simple Sequential Circuits and Verilog

Similar documents
L5: Simple Sequential Circuits and Verilog

L5: Simple Sequential Circuits and Verilog

L5: Simple Sequential Circuits and Verilog

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

Sequential Logic. Reminder: Lab #2 due Thursday Fall 2016 Lecture 4

Sequential Logic. Use Explicit Port Declarations. Verilog Summary. Examples

Modeling Sequential Circuits in Verilog

Sequential Logic. Reminder: Lab #2 due Thursday Fall 2017 Lecture 4

Techniques for Digital Systems Lab. Verilog HDL. Tajana Simunic Rosing. Source: Eric Crabill, Xilinx

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

Logic Circuits II ECE 2411 Thursday 4:45pm-7:20pm. Lecture 3

DIGITAL SYSTEM DESIGN

Modeling Synchronous Logic Circuits. Debdeep Mukhopadhyay IIT Madras

N-input EX-NOR gate. N-output inverter. N-input NOR gate

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

Digital Integrated Circuits

EECS 270 Verilog Reference: Sequential Logic

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

Quick Introduction to SystemVerilog: Sequental Logic

Sequential Logic Design

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

Writing Circuit Descriptions 8

University of Technology

Lab 7 (All Sections) Prelab: Introduction to Verilog

EN164: Design of Computing Systems Lecture 07: Lab Foundations / Verilog 3

Lecture 3. Behavioral Modeling Sequential Circuits. Registers Counters Finite State Machines

Ripple Counters. Lecture 30 1

Sequential Circuit Design: Principle

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Verilog Execution Semantics

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

L11: Major/Minor FSMs

Chapter 5 Registers & Counters

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

ECEN 468 Advanced Logic Design

C A R L E T O N U N I V E R S I T Y. FINAL EXAMINATION April Duration: 3 Hours No. of Students: 108

Sequential Logic Blocks

FSM and Efficient Synthesizable FSM Design using Verilog

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Amrita Vishwa Vidyapeetham. EC429 VLSI System Design Answer Key

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Synthesizable Verilog

HANSABA COLLEGE OF ENGINEERING & TECHNOLOGY (098) SUBJECT: DIGITAL ELECTRONICS ( ) Assignment

Lecture 15: System Modeling and Verilog

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and

Verilog for Synthesis Ing. Pullini Antonio

Sequential Circuit Design: Principle

Lecture 4: Modeling in VHDL (Continued ) EE 3610 Digital Systems

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

Last Lecture. Talked about combinational logic always statements. e.g., module ex2(input logic a, b, c, output logic f); logic t; // internal signal

Digital Design with SystemVerilog

VERILOG: FLIP-FLOPS AND REGISTERS

Outcomes. Spiral 1 / Unit 6. Flip Flops FLIP FLOPS AND REGISTERS. Flip flops and Registers. Outputs only change once per clock period

Verilog for High Performance

Lecture 12 VHDL Synthesis

Nanosistemų programavimo kalbos 5 paskaita. Sekvencinių schemų projektavimas

VLSI Design 13. Introduction to Verilog

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

Why Should I Learn This Language? VLSI HDL. Verilog-2

Department of Computer Science and Electrical Engineering. CMPE 415 Verilog Events Timing and Testbenches Prof. Ryan Robucci

Lecture 32: SystemVerilog

Latch Based Design (1A) Young Won Lim 2/18/15

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

Synthesis of Combinational and Sequential Circuits with Verilog

Outcomes. Spiral 1 / Unit 6. Flip Flops FLIP FLOPS AND REGISTERS. Flip flops and Registers. Outputs only change once per clock period

Spiral 1 / Unit 6. Flip-flops and Registers

Chapter 9: Sequential Logic Modules

Chapter 10. Counters (a short discussion)

Chapter 2: Introduction to Verilog

Registers and finite state machines

CS/EE Homework 7 Solutions

CSE 140L Final Exam. Prof. Tajana Simunic Rosing. Spring 2008

ECE 4514 Digital Design II. Spring Lecture 13: Logic Synthesis

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

SHRI ANGALAMMAN COLLEGE OF ENGINEERING. (An ISO 9001:2008 Certified Institution) SIRUGANOOR, TIRUCHIRAPPALLI

EN2911X: Reconfigurable Computing Lecture 06: Verilog (3)

CSE 140L Final Exam. Prof. Tajana Simunic Rosing. Spring 2008

R10. II B. Tech I Semester, Supplementary Examinations, May

ECE 331: N0. Professor Andrew Mason Michigan State University. Opening Remarks

Testbenches for Sequential Circuits... also, Components

Behavioral Modeling and Timing Constraints

register:a group of binary cells suitable for holding binary information flip-flops + gates

Sequential Logic - Module 5

8 Describing Combinational and Sequential Logic using Verilog HDL

Code No: R Set No. 1

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

- 1 of 18 - The Verilog Hardware Description Language - A Behavioural View Overview. The Behavioural Model

5.14 Algorithmic State Machine (ASM) Charts

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING QUESTION BANK NAME OF THE SUBJECT: EE 2255 DIGITAL LOGIC CIRCUITS

Digital Design with FPGAs. By Neeraj Kulkarni

CSE140L: Components and Design Techniques for Digital Systems Lab

Verilog Behavioral Modeling

Behavioral Modeling and Timing Constraints

ECE 4514 Digital Design II. Spring Lecture 2: Hierarchical Design

Transcription:

L5: Simple Sequential Circuits and Verilog Courtesy of Rex Min. Used with permission. 1

Key Points from L4 (Sequential Blocks) Classification: Latch: level sensitive (positive latch passes input to output on high phase, hold value on low phase) Register: edge-triggered (positive register samples input on rising edge) Flip-Flop: any element that has two stable states. uite often Flip-flop also used denote an (edge-triggered) register Positive Latch D D D D Positive Register Clk Clk Latches are used to build Registers (using the Master-Slave Configuration), but are almost NEVER used by itself in a standard digital design flow. uite often, latches are inserted in the design by mistake (e.g., an error in your Verilog code). Make sure you understand the difference between the two. Several types of memory elements (SR, JK, T, D). We will most commonly use the D-Register, though you should understand how the different types are built and their functionality. 2

Key Points from L4 : System Timing CLout In D Combinational Logic D Clk Clk CLK T h T h IN T su T cq T su T cq FF1 T cq,cd T logic T cq,cd CLout T l,cd T su T > T cq + T logic + T su T cq,cd + T logic,cd > T hold 3

The Sequential always Block Edge-triggered circuits are described using a sequential always block Combinational module combinational(a, b, sel, out); input a, b; input sel; output out; reg out; always @ (a or b or sel) if (sel) out = a; else out = b; module Sequential module sequential(a, b, sel, clk, out); input a, b; input sel, clk; output out; reg out; always @ (posedge clk) if (sel) out <= a; else out <= b; module a 1 a 1 b 0 out b 0 D out sel sel clk 4

Importance of the Sensitivity List The use of posedge and negedge makes an always block sequential (edge-triggered) Unlike a combinational always block, the sensitivity list does determine behavior for synthesis! D Flip-flop with synchronous clear module dff_sync_clear(d, clearb, clock, q); input d, clearb, clock; output q; reg q; always @ (posedge clock) if (!clearb) q <= 1'b0; else q <= d; module always block entered only at each positive clock edge D Flip-flop with asynchronous clear module dff_async_clear(d, clearb, clock, q); input d, clearb, clock; output q; reg q; always @ (negedge clearb or posedge clock) if (!clearb) q <= 1 b0; else q <= d; module always block entered immediately when (active-low) clearb is asserted Note: The following is incorrect syntax: always @ (clear or negedge clock) If one signal in the sensitivity list uses posedge/negedge, then all signals must. Assign any signal or variable from only one always block, Be wary of race conditions: always blocks execute in parallel 5

Simulation DFF with Synchronous Clear DFF with Asynchronous Clear t c-q Clear on Clock Edge Clear happens on falling edge of clearb 6

Blocking vs. Nonblocking Assignments Verilog supports two types of assignments within always blocks, with subtly different behaviors. Blocking assignment: evaluation and assignment are immediate always @ (a or b or c) x = a b; y = a ^ b ^ c; z = b & ~c; 1. Evaluate a b, assign result to x 2. Evaluate a^b^c, assign result to y 3. Evaluate b&(~c), assign result to z Nonblocking assignment: all assignments deferred until all right-hand sides have been evaluated ( of simulation timestep) always @ (a or b or c) x <= a b; y <= a ^ b ^ c; z <= b & ~c; 1. Evaluate a b but defer assignment of x 2. Evaluate a^b^c but defer assignment of y 3. Evaluate b&(~c) but defer assignment of z 4. Assign x, y, and z with their new values Sometimes, as above, both produce the same result. Sometimes, not! 7

Assignment Styles for Sequential Logic Flip-Flop Based Digital Delay Line clk in q1 q2 D D D out Will nonblocking and blocking assignments both produce the desired result? module nonblocking(in, clk, out); input in, clk; output out; reg q1, q2, out; always @ (posedge clk) q1 <= in; q2 <= q1; out <= q2; module module blocking(in, clk, out); input in, clk; output out; reg q1, q2, out; always @ (posedge clk) q1 = in; q2 = q1; out = q2; module 8

Use Nonblocking for Sequential Logic always @ (posedge clk) q1 <= in; q2 <= q1; out <= q2; At each rising clock edge, q1, q2, and out simultaneously receive the old values of in, q1, and q2. always @ (posedge clk) q1 = in; q2 = q1; out = q2; At each rising clock edge, q1 = in. After that, q2 = q1 = in. After that, out = q2 = q1 = in. Therefore out = in. q1 q2 q1 q2 in D D D out in D out clk clk Blocking assignments do not reflect the intrinsic behavior of multi-stage sequential logic Guideline: use nonblocking assignments for sequential always blocks 9

Non-blocking Simulation Simulation Blocking Simulation 10

Use Blocking for Combinational Logic Blocking Behavior (Given) Initial Condition a changes; always block triggered x = a & b; y = x c; Nonblocking Behavior (Given) Initial Condition a changes; always block triggered x <= a & b; y <= x c; Assignment completion a b c x y 1 1 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 0 0 a b c x y a b Deferred 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 x<=0 0 1 0 1 1 x<=0, y<=1 0 1 0 01 c x y module blocking(a,b,c,x,y); input a,b,c; output x,y; reg x,y; always @ (a or b or c) x = a & b; y = x c; module module nonblocking(a,b,c,x,y); input a,b,c; output x,y; reg x,y; always @ (a or b or c) x <= a & b; y <= x c; module Nonblocking and blocking assignments will synthesize correctly. Will both styles simulate correctly? Nonblocking assignments do not reflect the intrinsic behavior of multi-stage combinational logic While nonblocking assignments can be hacked to simulate correctly (expand the sensitivity list), it s not elegant Guideline: use blocking assignments for combinational always blocks 11

The Asynchronous Ripple Counter A simple counter architecture uses only registers (e.g., 74HC393 uses T-register and negative edge-clocking) Toggle rate fastest for the LSB D Count[0] D D D Count [3:0] Count[1] Count[2] Count[3] but ripple architecture leads to large skew between outputs Clock D register set up to always toggle: i.e., T Register with T=1 Skew Count [3] Count [2] Count [1] Count [0] Clock 12

The Ripple Counter in Verilog Single D Register with Asynchronous Clear: module dreg_async_reset (clk, clear, d, q, qbar); input d, clk, clear; output q, qbar; reg q; Count[0] Count [3:0] Count[1] Count[2] Count[3] always @ (posedge clk or negedge clear) if (!clear) q <= 1'b0; else q <= d; assign qbar = ~q; module D Clock D D D Countbar[0] Countbar[1] Countbar[2] Countbar[3] Structural Description of Four-bit Ripple Counter: module ripple_counter (clk, count, clear); input clk, clear; output [3:0] count; wire [3:0] count, countbar; dreg_async_reset bit0(.clk(clk),.clear(clear),.d(countbar[0]),.q(count[0]),.qbar(countbar[0])); dreg_async_reset bit1(.clk(countbar[0]),.clear(clear),.d(countbar[1]),.q(count[1]),.qbar(countbar[1])); dreg_async_reset bit2(.clk(countbar[1]),.clear(clear),.d(countbar[2]),.q(count[2]),.qbar(countbar[2])); dreg_async_reset bit3(.clk(countbar[2]),.clear(clear),.d(countbar[3]),.q(count[3]),.qbar(countbar[3])); module 13

Simulation of Ripple Effect 14

Logic for a Synchronous Counter Count (C) will retained by a D Register Next value of counter (N) computed by combinational logic C3 C2 C1 N3 N2 N1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 0 0 0 C3 N1 1 1 1 1 N2 0 1 C1 0 0 0 0 C1 1 0 C2 C3 N3 0 0 1 1 C1 0 1 0 1 C2 C2 C3 1 0 0 1 N1 := C1 N2 := C1 C2 + C1 C2 := C1 xor C2 N3 := C1 C2 C3 + C1 C3 + C2 C3 := C1 C2 C3 + (C1 + C2 ) C3 := (C1 C2) xor C3 CLK C1 C2 C3 D D D From [Katz93], See Chapter 7 for different counters 15

The 74163 Catalog Counter Synchronous Load and Clear Inputs Positive Edge Triggered FFs Parallel Load Data from D, C, B, A P, T Enable Inputs: both must be asserted to enable counting Ripple Carry Output (RCO): asserted when counter value is 1111 (conditioned by T); used for cascading counters 7 10 9 1 2 6 5 4 3 P T D C B A 163 CLK LOAD CLR RCO D C B A 15 11 12 13 14 Synchronous CLR and LOAD If CLRb = 0 then <= 0 Else if LOADb=0 then <= D Else if P * T = 1 then <= + 1 Else <= 74163 Synchronous 4-Bit Upcounter 16

Verilog Code for 163 Behavioral description of the 163 counter: module counter(ldbar, CLRbar, P, T, CLK, D, count, RCO); input LDbar, CLRbar, P, T, CLK; input [3:0] D; output [3:0] count; output RCO; reg [3:0] ; always @ (posedge CLK) if (!CLRbar) <= 4'b0000; else if (!LDbar) <= D; else if (P && T) <= + 1; priority logic for control signals 7 10 2 6 5 4 3 9 1 P T D C B A 163 CLK LOAD CLR RCO D C B A 15 11 12 13 14 assign count = ; assign RCO = [3] & [2] & [1] & [0] & T; module RCO gated by T input 19

Simulation Notice the glitches on RCO! 20

Output Transitions Any time multiple bits change, the counter output needs time to settle. Even though all flip-flops share the same clock, individual bits will change at different times. Clock skew, propagation time variations Can cause glitches in combinational logic driven by the counter The RCO can also have a glitch. 21

Cascading the 74163: Will this Work? V DD bits 0-3 bits 4-7 bits 8-11 P CL T A B C D 163 RCO LD D A D B D C D D P CL T A B C D 163 RCO LD D A D B D C D D P CL T A B C D 163 RCO LD D A D B D C D D V DD 163 is enabled only if P and T are high CLK When first counter reaches = 4 b1111, its RCO goes high for one cycle When RCO goes high, next counter is enabled (P T = 1) So far, so good...then what s wrong? 22

Incorrect Cascade for 74163 Everything is fine up to 8 b11101111: V DD P CL T 1 1 1 1 0 1 1 1 A B C D T A B C D 1 0 RCO P RCO 163 163 LD D A D B D C D D CL LD D A D B D C D D P CL 0 0 0 0 T A B C D 163 RCO LD D A D B D C D D V DD CLK Problem at 8 b11110000: one of the RCOs is now stuck high for 16 cycles! V DD P CL T 0 0 0 0 1 1 1 1 A B C D T A B C D 0 RCO P RCO 163 163 LD D A D B D C D D CL LD D A D B D C D D 1 P CL 0 0 0 0 T A B C D 163 RCO LD D A D B D C D D V DD CLK 23

Correct Cascade for 74163 Master enable P A B C D P A B C D T CL LD RCO D A D B D C D D T CL LD RCO D A D B D C D D P input takes the master enable T input takes the ripple carry assign RCO = [3] & [2] & [1] & [0] & T; 24

Summary Use blocking assignments for combinational always blocks Use non-blocking assignments for sequential always blocks Synchronous design methodology usually used in digital circuits Single global clocks to all sequential elements Sequential elements almost always of edge-triggered flavor (design with latches can be tricky) Today we saw simple examples of sequential circuits (counters) 25