Modeling Synchronous Logic Circuits. Debdeep Mukhopadhyay IIT Madras

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

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

Sequential Circuit Design: Principle

Chapter 5 Registers & Counters

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

Sequential Logic Blocks

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

Introduction to Verilog HDL. Verilog 1

Modeling of Finite State Machines. Debdeep Mukhopadhyay

Verilog for Synthesis Ing. Pullini Antonio

Writing Circuit Descriptions 8

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

Sequential Circuit Design: Principle

L5: Simple Sequential Circuits and Verilog

Synthesis of Combinational and Sequential Circuits with Verilog

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

L5: Simple Sequential Circuits and Verilog

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

Modeling Sequential Circuits in Verilog

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

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

L5: Simple Sequential Circuits and Verilog

University of Technology

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

Verilog for High Performance

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

Digital Design with FPGAs. By Neeraj Kulkarni

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

Workshop on Digital Circuit Design in FPGA

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

L5: Simple Sequential Circuits and Verilog

Digital Integrated Circuits

Chapter 9: Sequential Logic Modules

Quick Introduction to SystemVerilog: Sequental Logic

Ripple Counters. Lecture 30 1

Topics. Midterm Finish Chapter 7

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

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

Lecture 12 VHDL Synthesis

Testbenches for Sequential Circuits... also, Components

EITF35: Introduction to Structured VLSI Design

ENSC E-123: HW D3: Counter Applications; Counter in Verilog

Digital Integrated Circuits

CSE140L: Components and Design Techniques for Digital Systems Lab

Verilog Sequential Logic. Verilog for Synthesis Rev C (module 3 and 4)

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

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

Lecture 32: SystemVerilog

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

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

Register Transfer Level in Verilog: Part I

CSE140L: Components and Design

Chapter 9: Sequential Logic Modules

Spiral 1 / Unit 6. Flip-flops and Registers

Homework deadline extended to next friday

Nikhil Gupta. FPGA Challenge Takneek 2012

Chapter-5. EE 335 : Advanced Microprocessor. Logic Design with Behavioral Models of Combinational and Sequential Logic

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

EITF35: Introduction to Structured VLSI Design

Lecture #2: Verilog HDL

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

Verilog Coding Guideline

ECEN 468 Advanced Logic Design

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

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Introduction to Verilog/System Verilog

Topics. Midterm Finish Chapter 7

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

Sequential Logic Design

Register Transfer Level

Course Topics - Outline

FPGA: FIELD PROGRAMMABLE GATE ARRAY Verilog: a hardware description language. Reference: [1]

Verilog Execution Semantics

ACS College of Engineering. Department of Biomedical Engineering. Logic Design Lab pre lab questions ( ) Cycle-1

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

Finite-State Machine (FSM) Design

VHDL for Synthesis. Course Description. Course Duration. Goals

Digital Design (VIMIAA01) Introduction to the Verilog HDL

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATIONS ENGINEERING

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

DIGITAL SYSTEM DESIGN

Course Topics - Outline

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

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

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

Xilinx ASMBL Architecture

VHDL: RTL Synthesis Basics. 1 of 59

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

Verilog introduction. Embedded and Ambient Systems Lab

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

MLR Institute of Technology

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Verilog Behavioral Modeling

Chap 6 Introduction to HDL (d)

CS6710 Tool Suite. Verilog is the Key Tool

EECS 373 Design of Microprocessor-Based Systems

EEL 4783: HDL in Digital System Design

Transcription:

Modeling Synchronous Logic Circuits Debdeep Mukhopadhyay IIT Madras

Basic Sequential Circuits A combinational circuit produces output solely depending on the current input. But a sequential circuit remembers its previous state. Its output depends on present inputs and previous state. Examples: Latches Registers Memory parallel to serial / serial to parallel converters Counters

Latch vs Registers Latch: Level sensitive device Positive Latches and Negative latches Can be realized using multiplexers Register: edge triggered storage element Can be implemented using latches Cascade a negative latch with a positive latch to obtain a positive edge triggered register Flip flop: bi-stable component formed by the cross coupling of gates.

Latches Cycle stealing is possible leading to faster circuits Problem of timing analysis.

Latch inference using if module. always@(...) begin if(en1) Y1=A1; if(en2) begin M2<=!(A2&B2); Y2<=!(M2 C2); end if(en3) begin M3=!(A3&B3); Y3=!(M3 C3); end A1 En1 C2 A2 B2 En2 A3 B3 En3 C3 D G D G Q ~Q Q ~Q D G Q ~Q D G Y3 Y1 Q ~Q Y2

Modeling latches with present and clear inputs begin if(!clear1) Y1=0; else if(en) Y1=A1; begin if(clear2) Y2=0; else if(en) Y2=A2;

Modeling latches with present and clear inputs if(!preset3) Y3=1; else if(en3) Y3=A3; if(!preset3) Y3=1; else if(en3) Y3=A3; D G Q ~Q CLR

Modeling latches with present and clear inputs if(clear5) Y5=0; else if(preset5) Y5=1; else if(en5) Y5=A5; A5 En5 Preset5 Clear5 If there are no latches with a preset input In the library, equivalent functionality is produced by using latches with a clear input. D G Q ~Q CLR Y5

Multiple gated latch always @(En1 or En2 or En3 ) if(en1==1) Y=A1; else if(en2==1) Y=A2; else if(en3==1) Y=A3; Try to synthesize and check whether: 1. Is there a latch inferred? 2. Put an else statement. Is a latch inferred now? 3. Put a default output assignment before the if starts. Is a latch inferred now? 4. Use the posedge keyword in the trigger list, and repeat the above experiments.

Other places of latch inferences Nested if: If all the possibilities are not mentioned in the code. Case: In advertent. Not advisable to infer a latch from case statement. may lead to superfluous latches. Nested case statements can also infer latches.

The D-Flip Flop always @(posedge clk) Y=D; A-Synchronous reset: always @(posedge clk or posedge reset) if(reset) Y=0 else Y=D;

Resets Synchronous reset: always @(posedge clk) if(reset) Y=0 else Y=D;

Combinational Block between two flops always@(posedge clk) begin M <=!(A & B); Y <= M N; end assign N=C D; What will happen if a blocking assignment is used? The first flip flop will become redundant

Sequence Generators Linear Feedback Shift Registers Counters

LFSR Applications Pattern Generators Counters Built-in Self-Test (BIST) Encryption Compression Checksums Pseudo-Random Bit Sequences (PRBS)

LFSR Linear Feedback Shift Register (LFSR): For pseudo random number generation A shift register with feedback and exclusive-or gates in its feedback or shift path. The initial content of the register is referred to as seed. The position of XOR gates is determined by the polynomial (poly).

An LFSR outline The feedback function (often called the taps) can be reprsesented by a polynomial of degree n

A 4 bit LFSR The feedback polynomial is p(x)=x 4 +x+1

A 4 bit LFSR 1111 0111 1011 0101 1010 1101 0110 0011 1001 0100 0010 0010 1000 1100 1110 Output sequence: 111101011001000... All the 2 4-1 possible states are generated. This is called a maximal length LFSR. So, the sequence depends on the feedbacks.

Types of feedbacks Feedbacks can be comprising of XOR gates. Feedbacks can be comprising of XNOR gates. Given the same tap positions, both will generate the same number of values in a cycle. But the values will be same. Permutation!

Number of Taps For many registers of length n, only two taps are needed, and can be implemented with a single XOR (XNOR) gate. For some register lengths, for example 8, 16, and 32, four taps are needed. For some hardware architectures, this can be in the critical timing path. A table of taps for different register lengths is included in the back of this module.

One-to-Many and Many-to- One Implementation (a) has only a single gate delay between flip-flops.

Avoiding the Lockup State Will Use XOR Form For Examples We have an n-bit LFSR, shifting to the right n 0

Avoiding the Lockup State Will Use XOR Form For Examples The all 0 s state can t be entered during normal operation but we can get close. Here s one of n examples: 0 0 0 0 0 1 n 0 We know this is a legal state since the only illegal state is all 0 s. If the first n-1 bits are 0, then bit 0 must be a 1.

Avoiding the Lockup State Will Use XOR Form For Examples Now, since the XOR inputs are a function of taps, including the bit 0 tap, we know what the output of the XOR tree will be: 1. It must be a 1 since 1 XOR 0 XOR 0 XOR 0 = 1. 0 0 0 0 0 1 n So normally the next state will be: 0 1 0 0 0 0 0 n 0

Avoiding the Lockup State Will Use XOR Form For Examples But instead, let s do this, go from this state: 0 0 0 0 0 1 n 0 To the all 0 s state: 1 0 0 0 0 0 n 0

Avoiding the Lockup State Modification to Circuit 2 n-1 states 2 n states NOR of all bits except bit 0 Added this term a) 000001 : 0 Xor 0 Xor 0 Xor 1 Xor 1 0 b) 000000 : 0 Xor 0 Xor 0 Xor 0 Xor 1 1 c) 100000 :

Verilog code module always@(posedge clk or posedge rst) begin if(rst) LFSR_reg=8 b0; else LFSR_reg=Next_LFSR_reg; end

verilog always @(LFSR_reg) begin Bits0_6_zero=~ LFSR_Reg[6:0]; Feedback=LFSR_Reg[7]^ Bits0_6_zero; for(n=7;n>0;n=n-1) if(taps[n-1]==1) Next_LFSR_Reg[N]=LFSR_Reg[N-1]^Feedback; else Next_LFSR_Reg[N]=LFSR_Reg[N-1]; Next_LFSR_Reg[0]=Feedback; end assign Y=LFSR_Reg; endmodule

A Generic LFSR module LFSR_Generic_MOD(Clk,rst,Y); parameter wdth=8; input clk,rst; output [wdth-1:0] Y; reg [31:0] Tapsarray [2:32]; wire [wdth-1:0] Taps; integer N; reg Bits0_Nminus1_zero, Feedback; reg [wdth-1:0] LFSR_Reg, Next_LFSR_Reg;

always @(rst) begin TapsArray[2]=2 b11; TapsArray[3]=3 b101; TapsArray[32]=32 b10000000_00000000_00000000_01100010; end assign Taps[wdth-1:0]=TapsArray[wdth]; REST OF THE CODE IS SIMILAR TO THE PREVIOUS EXAMPLE

Counters A register that goes through a predetermined sequence of binary values (states), upon the application of input pulses in one or more than inputs is called a counter. The input pulses can be random or periodic. Counters are often used as clock dividers.

Timing Diagrams The outputs (Q0 Q3) of the counter can be used as frequency dividers with Q0 = Clock 2, Q1 = Clock 4, Q2 = Clock 8, and Q3 = Clock 16.

Types Synchronous Using adders, subtractors Using LFSRs, better performance because of simple circuits. Most feedback polynomials are trinomials or pentanomials. Asynchronous: Ripple through flip flops each single flip flop stage divides by 2 so, we may obtain division by 2 n what if they are not powers of two? we require extra feedback logic significantly smaller

Divide by 13 : A synchronous design always@(posedge clk or posedge rst) begin if(!rst) begin cnt<=startcnt; Y<=0; end

Divide by 13 : A synchronous design else if(count==endcount) begin Count<=StartCount; Y<=1; end

Divide by 13 : A synchronous design else begin for(n=1;n<=3;n=n-1) if(taps[n]) Count[N]<=Count[N-1]~^Count[3]; else Count[N]<=Count[N-1]; Count[0]<=Count[3]; Y=0; end end

Asynchronous Design Instantiate 4 DFFs. Ripple the clock through them Output is a divided by 16 clock. Use the output states and check when 13 clock cycles have elapsed. Use it to make the output bit high. Reset the Flip Flops Exercise: Write a verilog code!

Pros and Cons of Synchronous and Asynchronous Resets

Problem of Choice Quite a complex issue. All of us know the importance of the reset button. When our PC does not work! Less understood, less emphasized. Require to a treatment to perform an informed design.

Some Points Reset style depends on the ASIC design style, the application and where the flip flop is located. If we design considering all the unused states (like the 2 n -2n states in a Johnson s Counter), we should be able to do reset from any possible state. A power on reset is required if the designer used the unused states as don t cares to do optimization. Often an explicit reset is not required if the flop is a part of shift register, just wait for some clock cycles. These are often called follower flops

Good Reset Synchronous Reset: module goodffstyle ( output reg q2, input d, clk, rst_n); reg q1; always @(posedge clk) if (!rst_n) q1 <= 1'b0; else q1 <= d; always @(posedge clk) q2 <= q1; endmodule

Bad Reset module badffstyle ( output reg q2, input d, clk, rst_n); reg q1; always @(posedge clk) if (!rst_n) q1 <= 1'b0; else begin q1 <= d; q2 <= q1; end endmodule

Bad Hardware Unnecessary use of a loadable flip flop

Good Hardware This is one of the few cases where a multiple always block is adviced.

Pros of Synchronous Resets Flip flop size is less. Although the gate count increases. Circuit is 100% synchronous. Sometimes the reset may be an internally generated signal and may have glitches. Work as a filter for such reset glitches. However there can be a metastability if the glitches occur near the clock edges.

Cons Not all ASIC libraries do have them Need a pulse stretcher to ensure that reset stays when the clock goes high Simulation issues can creep in, due to x- logic. Its often an annoying fact that you can do reset only when there is a clock. What if the clock is disable, say to save power? And would like to start the block.

Good Reset Again! Asynchronous Reset: module good_async_resetffstyle ( output reg q, input d, clk, rst_n); always @(posedge clk or negedge rst_n) if (!rst_n) q <= 1'b0; else q <= d; endmodule

Data Path is clean. Less gates on the data path. module ctr8ar ( output reg [7:0] q, output reg co; input [7:0] d; input ld, rst_n, clk; always @(posedge clk or negedge rst_n) if (!rst_n) {co,q} <= 9'b0; // async //reset else if (ld) {co,q} <= d; // sync load else {co,q} <= q + 1'b1; // sync increment endmodule Pros

Cons Difficult static Timing Analysis is hard. If the reset net is not derived from the input, they have to disable for scan based test (DFT issues). Glitches in the reset signal can be a problem. De-assertion of the reset could be an issue. If it happens near the active clock edge meta-stability can occur.

Two main Cons Reset Recovery Time: Time between the deassertion of reset and the next active clock edge. If this is not obeyed, meta-stability can occur. Reset removal is asynchronous: Consider, the reset going to more than one flop. Due to the different propagation time in either or both the reset and the clock signal, some flops may be in reset state, while others may have gone passed the reset state.

And Ugly Reset Two flip-flops are required to synchronize the reset signal to the clock pulse The second flip-flop is used to remove any metastability that might be caused by the reset signal being removed asynchronously and too close to the rising clock edge. You also have the best of asynchronous reset. Only reset becomes ugly!

Reset using the reset synchronizer module async_resetffstyle2 ( output reg rst_n, input clk, asyncrst_n); reg rff1; always @(posedge clk or negedge asyncrst_n) if (!asyncrst_n) {rst_n,rff1} <= 2'b0; else {rst_n,rff1} <= {rff1,1'b1}; endmodule

Conclusion We have seen various kinds of resets. Resets that are good, bad and ugly. One thing is clear reset is not simple. They should be carefully handled.