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

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

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

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

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

Modeling Sequential Circuits in Verilog

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

DIGITAL SYSTEM DESIGN

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

Chapter 5 Registers & Counters

Sequential Logic Design

Modeling Synchronous Logic Circuits. Debdeep Mukhopadhyay IIT Madras

EECS 270 Verilog Reference: Sequential Logic

ECEN 468 Advanced Logic Design

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

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

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

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

Ripple Counters. Lecture 30 1

Chapter 10. Counters (a short discussion)

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

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

Verilog Execution Semantics

FSM and Efficient Synthesizable FSM Design using Verilog

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Digital Integrated Circuits

Quick Introduction to SystemVerilog: Sequental Logic

Writing Circuit Descriptions 8

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

University of Technology

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

Lecture 15: System Modeling and Verilog

Lab 7 (All Sections) Prelab: Introduction to Verilog

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

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

Sequential Circuit Design: Principle

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

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

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

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

Spiral 1 / Unit 6. Flip-flops and Registers

Digital Design with SystemVerilog

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

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

L11: Major/Minor FSMs

Synthesizable Verilog

Amrita Vishwa Vidyapeetham. EC429 VLSI System Design Answer Key

Lecture 12 VHDL Synthesis

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

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

Synthesis of Combinational and Sequential Circuits with Verilog

Sequential Circuit Design: Principle

Digital Design with FPGAs. By Neeraj Kulkarni

Laboratory Exercise 3

Chapter 9: Sequential Logic Modules

Lecture 32: SystemVerilog

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

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

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

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

Computer Architecture (TT 2012)

Introduction. Purpose. Intended Audience. Conventions. Close

VERILOG: FLIP-FLOPS AND REGISTERS

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

Verilog Behavioral Modeling

Verilog for High Performance

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

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

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

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

CSE140L: Components and Design Techniques for Digital Systems Lab

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

Verilog for Synthesis Ing. Pullini Antonio

Sequential Logic Blocks

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

8 Describing Combinational and Sequential Logic using Verilog HDL

Code No: R Set No. 1

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

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

CSE140L: Components and Design

EN2911X: Reconfigurable Computing Lecture 06: Verilog (3)

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

Verilog Tutorial (Structure, Test)

Two hours - online EXAM PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

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

ECE 574: Modeling and Synthesis of Digital Systems using Verilog and VHDL. Fall 2017 Final Exam (6.00 to 8.30pm) Verilog SOLUTIONS

CS/EE Homework 7 Solutions

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

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

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

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

Behavioral Modeling and Timing Constraints

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

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

Sequential Logic - Module 5

Announcements. Midterm 2 next Thursday, 6-7:30pm, 277 Cory Review session on Tuesday, 6-7:30pm, 277 Cory Homework 8 due next Tuesday Labs: project

Transcription:

L5: Simple Sequential Circuits and Verilog Acknowledgements: Nathan Ickes and Rex Min

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 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, ). We will most commonly use the -Register, though you should understand how the different types are built and their functionality. 2

System Timing Parameters In Combinational Logic Clk Register Timing Parameters T cq : worst case rising edge clock to q delay T cq, cd : contamination or minimum delay from clock to q T su : setup time T h : hold time Clk Logic Timing Parameters T logic : worst case delay through the combinational logic network T logic,cd : contamination or minimum delay through logic network 3

elay in igital Circuits V in V V 5% R on t t phl t plh V out V out V out 9% C L C L 5% R on % t t f t r (a) Low-to-high (b) High-to-low R v out review v in C t p = ln (2) τ =.69 RC 4

System Timing (I): Minimum Period CLout In Combinational Logic Clk Clk CLK T h T h IN T su T cq T su T cq FF T cq,cd T logic T cq,cd CLout T l,cd T su2 T > T cq + T logic + T su 5

System Timing (II): Minimum elay CLout In Combinational Logic Clk Clk CLK IN FF CLout T su T h T cq,cd T h T l,cd T cq,cd + T logic,cd > T hold 6

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) begin if (sel) out = a; else out = b; end endmodule Sequential module sequential(a, b, sel, clk, out); input a, b; input sel, clk; output out; reg out; always @ (posedge clk) begin if (sel) out <= a; else out <= b; end endmodule a a b out b out sel sel clk 7

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! Flip-flop with synchronous clear module dff_sync_clear(d, clearb, clock, q); input d, clearb, clock; output q; reg q; always @ (posedge clock) begin if (!clearb) q <= 'b; else q <= d; end endmodule always block entered only at each positive clock edge 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) begin if (!clearb) q <= b; else q <= d; end endmodule 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 8

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

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) begin x = a b; y = a ^ b ^ c; z = b & ~c; end. 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 (end of simulation timestep) always @ (a or b or c) begin x <= a b; y <= a ^ b ^ c; z <= b & ~c; end. 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!

Assignment Styles for Sequential Logic Flip-Flop Based igital elay Line clk in q q2 out Will nonblocking and blocking assignments both produce the desired result? module nonblocking(in, clk, out); input in, clk; output out; reg q, q2, out; always @ (posedge clk) begin q <= in; q2 <= q; out <= q2; end endmodule module blocking(in, clk, out); input in, clk; output out; reg q, q2, out; always @ (posedge clk) begin q = in; q2 = q; out = q2; end endmodule

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

Non-blocking Simulation Simulation Blocking Simulation 3

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 a b a b c x y eferred x<= x<=, y<= 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) begin x = a & b; y = x c; end endmodule module nonblocking(a,b,c,x,y); input a,b,c; output x,y; reg x,y; always @ (a or b or c) begin x <= a & b; y <= x c; end endmodule 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 4

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 Count[] Count [3:] Count[] Count[2] Count[3] but ripple architecture leads to large skew between outputs Clock register set up to always toggle: i.e., T Register with T= Skew Count [3] Count [2] Count [] Count [] Clock 5

The Ripple Counter in Verilog Single Register with Asynchronous Clear: module dreg_async_reset (clk, clear, d, q, qbar); input d, clk, clear; output q, qbar; reg q; Count[] Count [3:] Count[] Count[2] Count[3] always @ (posedge clk or negedge clear) begin if (!clear) q <= 'b; else q <= d; end assign qbar = ~q; endmodule clk Countbar[] Countbar[] Countbar[2] Countbar[3] Structural escription of Four-bit Ripple Counter: module ripple_counter (clk, count, clear); input clk, clear; output [3:] count; wire [3:] count, countbar; dreg_async_reset bit(.clk(clk),.clear(clear),.d(countbar[]),.q(count[]),.qbar(countbar[])); dreg_async_reset bit(.clk(countbar[]),.clear(clear),.d(countbar[]),.q(count[]),.qbar(countbar[])); dreg_async_reset bit2(.clk(countbar[]),.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])); endmodule 6

Simulation of Ripple Effect 7

Logic for a Synchronous Counter Count (C) will retained by a Register Next value of counter (N) computed by combinational logic C3 C2 C N3 N2 N C3 N N2 C C C2 C3 N3 C C2 C2 C3 N := C N2 := C C2 + C C2 := C xor C2 N3 := C C2 C3 + C C3 + C2 C3 := C C2 C3 + (C + C2 ) C3 := (C C2) xor C3 CLK C C2 C3 From [Katz5] 8

The 7463 Catalog Counter Synchronous Load and Clear Inputs Positive Edge Triggered FFs Parallel Load ata from, C, B, A P, T Enable Inputs: both must be asserted to enable counting Ripple Carry Output (RCO): asserted when counter value is (conditioned by T); used for cascading counters 7 9 2 6 5 4 3 P T C B A 63 CLK LOA CLR RCO C B A 5 2 3 4 Synchronous CLR and LOA If CLRb = then <= Else if LOAb= then <= Else if P * T = then <= + Else <= 7463 Synchronous 4-Bit Upcounter 9

Inside the 7463 (Courtesy TI) - Operating Modes CLR =, LOA = : Clear takes precedence CLR =, LOA = : Parallel load from ATA A A B B C C 2

63 Operating Modes - II CLR =, LOA =, P T = : Counting inhibited CLR =, LOA =, P T = : Count enabled A NA B NB C NC N 2

Verilog Code for 63 Behavioral description of the 63 counter: module counter(lbar, CLRbar, P, T, CLK,, count, RCO); input Lbar, CLRbar, P, T, CLK; input [3:] ; output [3:] count; output RCO; reg [3:] ; always @ (posedge CLK) begin if (!CLRbar) <= 4'b; else if (!Lbar) <= ; else if (P && T) <= + ; end priority logic for control signals 7 9 2 6 5 4 3 P T C B A 63 CLK LOA CLR RCO C B A 5 2 3 4 assign count = ; assign RCO = [3] & [2] & [] & [] & T; endmodule RCO gated by T input 22

Simulation Notice the glitches on RCO! 23

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. Care is required of the Ripple Carry Output: It can have glitches: Any of these transition paths are possible! 24

Cascading the 7463: Will this Work? V bits -3 bits 4-7 bits 8- P CL T A B C 63 RCO L A B C P CL T A B C 63 RCO L A B C P CL T A B C 63 RCO L A B C V 63 is enabled only if P and T are high CLK When first counter reaches = 4 b, its RCO goes high for one cycle When RCO goes high, next counter is enabled (P T = ) So far, so good...then what s wrong? 25

Incorrect Cascade for 7463 Everything is fine up to 8 b: V P CL T A B C T A B C RCO P RCO 63 63 L A B C CL L A B C P CL T A B C 63 RCO L A B C V CLK Problem at 8 b: one of the RCOs is now stuck high for 6 cycles! V P CL T A B C T A B C RCO P RCO 63 63 L A B C CL L A B C P CL T A B C 63 RCO L A B C V CLK 26

Correct Cascade for 7463 Master enable P A B C P A B C T CL L RCO A B C T CL L RCO A B C P input takes the master enable T input takes the ripple carry assign RCO = [3] & [2] & [] & [] & T; 27

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) 28