FPGA TechNote: Asynchronous signals and Metastability

Similar documents
Asynchronous inputs. 9 - Metastability and Clock Recovery. A simple synchronizer. Only one synchronizer per input

HDL & High Level Synthesize (EEET 2035) Laboratory II Sequential Circuits with VHDL: DFF, Counter, TFF and Timer

Laboratory Exercise 7


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

Metastability Analysis of Synchronizer

Synchronous Sequential Design

9. Synopsys PrimeTime Support

EE178 Spring 2018 Lecture Module 5. Eric Crabill

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 7

Laboratory Exercise 7

Flip-flop and Registers

Lecture 8: Sequential Logic

Digital Logic Design ENEE x. Lecture 19

Figure 1 shows a simple implementation of a clock switch, using an AND-OR type multiplexer logic.

DEDICATED TO EMBEDDED SOLUTIONS

DEPARTMENT OF ELECTRICAL &ELECTRONICS ENGINEERING DIGITAL DESIGN

Digital Fundamentals: A Systems Approach

Product Level MTBF Calculation

INTEGRATED CIRCUITS. AN219 A metastability primer Nov 15

Feedback Sequential Circuits

FIFO Memories: Solution to Reduce FIFO Metastability

ECE 263 Digital Systems, Fall 2015

EECS150 - Digital Design Lecture 15 Finite State Machines. Announcements

Achieving Timing Closure in ALTERA FPGAs

FPGA Laboratory Assignment 4. Due Date: 06/11/2012

IT T35 Digital system desigm y - ii /s - iii

Using SignalTap II in the Quartus II Software

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

CHAPTER 6 DESIGN OF HIGH SPEED COUNTER USING PIPELINING

CSE115: Digital Design Lecture 23: Latches & Flip-Flops

Clock Domain Crossing. Presented by Abramov B. 1

ECE337 Lab 4 Introduction to State Machines in VHDL

Sequential circuits. Same input can produce different output. Logic circuit. William Sandqvist

EE178 Lecture Module 4. Eric Crabill SJSU / Xilinx Fall 2005

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

EECS150 - Digital Design Lecture 10 - Interfacing. Recap and Topics

Outline. EECS150 - Digital Design Lecture 27 - Asynchronous Sequential Circuits. Cross-coupled NOR gates. Asynchronous State Transition Diagram

MC9211 Computer Organization

SignalTap: An In-System Logic Analyzer

L4: Sequential Building Blocks (Flip-flops, Latches and Registers)

Digital System Design

The basic logic gates are the inverter (or NOT gate), the AND gate, the OR gate and the exclusive-or gate (XOR). If you put an inverter in front of

2.6 Reset Design Strategy

ECE 3401 Lecture 12. Sequential Circuits (II)

EITF35: Introduction to Structured VLSI Design

cascading flip-flops for proper operation clock skew Hardware description languages and sequential logic

CHAPTER 4: Logic Circuits

Sequential Circuit Design: Principle

More on Flip-Flops Digital Design and Computer Architecture: ARM Edition 2015 Chapter 3 <98> 98

Using the Quartus II Chip Editor

Debugging of VHDL Hardware Designs on Altera s DE2 Boards

CHAPTER 4: Logic Circuits

D Latch (Transparent Latch)

Chapter 6. Flip-Flops and Simple Flip-Flop Applications

Digital Electronics II 2016 Imperial College London Page 1 of 8

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Introductory Digital Systems Laboratory

Unit 11. Latches and Flip-Flops

CS3350B Computer Architecture Winter 2015

Chapter 5 Flip-Flops and Related Devices

CPS311 Lecture: Sequential Circuits

EECS 373 Design of Microprocessor-Based Systems

Logic Design. Flip Flops, Registers and Counters

Sequential Logic Basics

Software Engineering 2DA4. Slides 9: Asynchronous Sequential Circuits

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District UNIT-III SEQUENTIAL CIRCUITS

Name Of The Experiment: Sequential circuit design Latch, Flip-flop and Registers

Chapter 4: One-Shots, Counters, and Clocks

Ryerson University Department of Electrical and Computer Engineering EES508 Digital Systems

Figure 1 Block diagram of a 4-bit binary counter

PGT104 Digital Electronics. PGT104 Digital Electronics

Sequential Logic. E&CE 223 Digital Circuits and Systems (A. Kennings) Page 1

Basis of sequential circuits: the R-S latch

Cyclone II EPC35. M4K = memory IOE = Input Output Elements PLL = Phase Locked Loop

problem maximum score 1 28pts 2 10pts 3 10pts 4 15pts 5 14pts 6 12pts 7 11pts total 100pts

DALHOUSIE UNIVERSITY Department of Electrical & Computer Engineering Digital Circuits - ECED 220. Experiment 4 - Latches and Flip-Flops

STATIC RANDOM-ACCESS MEMORY

Chapter 4. Logic Design

COMP sequential logic 1 Jan. 25, 2016

L14: Quiz Information and Final Project Kickoff. L14: Spring 2004 Introductory Digital Systems Laboratory

Chapter 6. sequential logic design. This is the beginning of the second part of this course, sequential logic.

Review of digital electronics. Storage units Sequential circuits Counters Shifters

Good afternoon! My name is Swetha Mettala Gilla you can call me Swetha.

Digital Fundamentals

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Introductory Digital Systems Laboratory

Sequential logic. Circuits with feedback. How to control feedback? Sequential circuits. Timing methodologies. Basic registers

CHAPTER 3 EXPERIMENTAL SETUP

DO NOT COPY DO NOT COPY

Counters

Objectives. Combinational logics Sequential logics Finite state machine Arithmetic circuits Datapath

Chapter 7 Counters and Registers

Digital Fundamentals: A Systems Approach

Universal Asynchronous Receiver- Transmitter (UART)

The outputs are formed by a combinational logic function of the inputs to the circuit or the values stored in the flip-flops (or both).

2. Logic Elements and Logic Array Blocks in the Cyclone III Device Family

Flip-Flops and Registers

Static Timing Analysis for Nanometer Designs

WINTER 15 EXAMINATION Model Answer

CS 151 Final. Instructions: Student ID. (Last Name) (First Name) Signature

MTBF Bounds for Multistage Synchronizers

Transcription:

FPGA TechNote: Asynchronous signals and Metastability This Doulos FPGA TechNote gives a brief overview of metastability as it applies to the design of FPGAs. The first section introduces metastability and gives links to resources. The second part looks specifically at making calculations using typical metastability data, and also at the automation of metastability calculation that has recently been introduced in the Altera Quartus II software. A PDF version of this document, together with the code examples, can be downloaded from our web site: www.doulos.com/knowhow/fpga Our KnowHow pages are often updated with new material call back soon! Copyright 2009 by Doulos. All rights reserved.

Asynchronous Signals and Metastability Contents Asynchronous Signals and Metastability... 3 Introduction... 4 Synchronous Design and Synchronization... 4 Metastability... 5 Metastability documentation... 6 Calculation of Metastability... 7 Increasing the MTBF... 8 More than one asynchronous input... 9 Practical Example... 0 Circuit Description... 0 Setting up Altera Quartus II... 2 Using Altera Quartus II for Metastability... 2 Conclusion... 7 And Finally...... 7 2 Copyright 2009 by Doulos. All rights reserved.

Asynchronous Signals and Metastability This introductory part of the TechNote introduces the problems we aim to solve, and the available methods. Copyright 2009 by Doulos. All rights reserved. 3

Asynchronous Signals and Metastability Introduction Synchronous Design and Synchronization Modern digital design is normally carried out using a synchronous design methodology. A design consists of combinational logic and edge-triggered flip-flops. Combinational logic is logic such that the output of the logic is purely a function of the steady-state values of the inputs in other words it has no memory. Edge-triggered flip-flops are used to remember the state of a design. They are triggered by one edge of a clock signal. As long as the input to an edge-triggered flip-flop is available some time before the clock edge (the setup time), the value on that input will be sampled correctly. Here s a simplified diagram. 4 Copyright 2009 by Doulos. All rights reserved.

Designers tend to concentrate mainly on register-to-register delay, as this governs the maximum clock frequency at which a circuit can run. Inputs that are triggered by the same clock may have an arrival time specified so that they are guaranteed to settle before the following clock edge. However in the real world, some signals may not be related to the clock A signal may come from another chip running on a different clock A signal may be an external input, for instance a push-button A signal may be from another clock domain inside the same chip. In all these cases the designer needs to take care of synchronization. Metastability When an external asynchronous signal is sampled by a flip-flop, it will be sampled correctly if it changes before the input setup time of the flip-flop, and after the input hold time. If the signal changes too close to the clock edge (within the time interval from the input setup time to the input hold time) it is possible that the signal will be sampled with the wrong value. However on the following clock edge, the correct value should be seen. However if the input signal changes extremely close to the clock edge, it is possible for that signal to enter a metastable state an analogue value which is neither a zero nor a one. The signal will then eventually settle to either a zero or a one randomly. The big problem with metastability is if the analogue value at the output of the flip-flop lasts such a long time that it affects other flipflops. In that case, it is possible for downstream circuitry to end up in an illegal state that is two downstream flip-flops could sample the same sampled signal at the same time, yet end up with different output values; because that sampled signal is in an indeterminate (analogue) state. Copyright 2009 by Doulos. All rights reserved. 5

Asynchronous Signals and Metastability That could mean, for instance, that a state machine reaches a supposedly impossible state. The most important thing to realise about metastability is that there is no cure. Metastability can always occur if you sample an asynchronous signal the question is only how often? Because of its probabilistic nature, metastability is characterized by the mean time between failures (MTBF). Metastability documentation There is a lot of documentation available for metastability. General descriptions The FPGA FAQ http://www.fpga-faq.org/faq_pages/007_tell_me_about_metas tables.htm The Massachusetts Institute of Technology course Computation Structures contains a lecture about metastability http://6004.csail.mit.edu/currentsemester/ Vendor provided information Actel Application Note AC308 Metastability Characterization Report for Actel Antifuse FPGAs Actel Application Note Metastability Characterization Report for Actel Flash FPGAs Altera Understanding Metastability in FPGAs white paper wp- 0082 Altera AN473 Using DCFIFO for data transfer between asynchronous clock domains Altera Quartus II 9.0 Handbook Volume section 7 Managing Metastability with the Quartus II software Lattice Semiconductor Corporation Technical Note 055 Metastability in Lattice Devices Xilinx Application Note: Virtex II Pro Family XAPP094 Metastable Recovery in Virtex II Pro FPGAs 6 Copyright 2009 by Doulos. All rights reserved.

Calculation of Metastability In the references above you will find a full discussion of metastability. The following equation can be derived for the MTBF due to metastability Where MTBF 2 e F * F K Metastability catching set-up time. K 2 Re-convergence quality factor, which is proportional to the gain-bandwidth product in the internal feedback path of the first latch inside the flip-flop. F and F 2 system (sampling) and external (asynchronous) event frequencies. We assume than there is no correlation between F and F2. t r acceptable extra delay (r representing recovery or resolution ). The constants K and K 2 are due to the detailed electronic design of the flip-flop. The value of t r is the amount of extra settling time that can be allowed before the (possibly metastable) signal is sampled by the next downstream flip-flop. Regardless of the actual values involved, it can be seen that increasing t r makes the MTBF exponentially better (longer). Interpreting the Metastability Equation Note that you have to be careful when encountering the equation above to look at the definition of t r. When deriving the equation from fundamentals, the value of total time t to resolve a meta-stable state is the total settling time available, which comprises of Tco (the clock to K * 2 t r * K Copyright 2009 by Doulos. All rights reserved. 7

Asynchronous Signals and Metastability output delay of the flip-flop) + t r the additional time available to resolve to a known value. In other words t = Tco + t r Thus the equation could be written MTBF which can be re-arranged as K2 e F * F * Tco 2 t r * C MTBF K2* Tco K2 e e F * F * C K2 Tco Then by absorbing the constant term e * our original K ) the original equation can be obtained. into C (to give Some of the papers above also use the contstant /K 2, normally writing this as the greek letter τ (tau). 2 * Tr Increasing the MTBF To increase the MTBF we want to allow as much time as possible after the clock edge. If you imagine the case of flip-flop feeding into the first flip-flop of the main circuit, then the settling time t r = clock period Tco Tsu Tpd where Tco is the clock to output delay of the first flip-flop, Tsu is the input setup time of the following flip-flop, and Tpd is the propagation delay of any combinational logic (or wiring) between the two flip-flops. To make Tpd as small as possible, and hence make t r as large as possible, we can simply cascade two flip-flops. To a first 8 Copyright 2009 by Doulos. All rights reserved.

approximation, this multiplies the MTBF for one flip-flop by itself (i.e the result is the square of the MTBF). This technique is known as a two stage synchroniser. More than one asynchronous input What happens if you have more than one independent asynchronous input? In that case each input will need separate synchronization. If you have n inputs then the combined MTBF is given by MTBF MTBF MTBF MTBF n This means that the worst MTBF tends to dominate. For instance if you have two MTBFs of 000 years and one of year, the combined MTBF will be very close to (just less than) year. 2 Copyright 2009 by Doulos. All rights reserved. 9

Asynchronous Signals and Metastability Practical Example Let s now create a simple example problem. Rather than try and obtain metastability constant values, we will use the new features of Altera Quartus II 9.0 to show the effect of synchronization on our circuit. Circuit Description We will use a simple counter. As modern devices and flip-flops are very fast, we will write the counter in a bad style, to try and show the effect of metastability. The counter has a number of inputs including an UpDn signal which causes it to count up (when UpDn is true) or down (when UpDn is false); and a Load signal, which causes data to be loaded in from a parallel input port. We will assume all signals are synchronized to the counter clock except for UpDn and Load which are assumed to be asynchronous. The counter has been written is such a way that there is a long path from UpDn through to the adder of the counter. This is so that when we synchronize this path, the metastability recovery time is reduced by extra combinational logic. You can download the counter code (both VHDL and Verilog versions) from our website at http://www.doulos.com/knowhow/fpga To synchronize the asynchronous inputs we create a synchronizer design entity which is parameterizable for the number of stages of synchronization. Here is the VHDL code for that synchronizer: 0 Copyright 2009 by Doulos. All rights reserved.

library IEEE; use IEEE.Std_logic_64.all; entity sync is generic (nstages : positive); port (Clock : in Std_logic; D: in Std_logic; Q : out std_logic); end; architecture RTL of sync is signal delay : std_logic_vector(nstages- downto 0); begin g: for I in delay'range generate -- first stage of synchronizer -- Capture external input g2: if I = 0 generate process(clock) begin if rising_edge(clock) then delay(0) <= D; end if; end process; end generate; -- subsequent stages - will not be used if nstages = g3: if I /= 0 generate process(clock) begin if rising_edge(clock) then delay(i) <= delay(i-); end if; end process; end generate; end generate; -- assign from final stage of synchronizer to external output Q <= delay(nstages-); end; By setting nstages to or 2 we can create a or 2 stage synchronizer. Copyright 2009 by Doulos. All rights reserved.

Asynchronous Signals and Metastability Setting up Altera Quartus II To get started you ll need to create a project in Altera Quartus II. The easiest way to do this is to use the File > New Project Wizard... menu. To see the same results described in this TechNote, select the device EP3C5E44C8 (a Cyclone III device). You will need to add the files sync.vhd and counter.vhd to the project. Using Altera Quartus II for Metastability First, note that at the time of writing only certain device families are supported for metastability calculation: Arria II GX, Stratix IV, Stratix III, and Cyclone III. That is why we specified a Cyclone III device above. Setting up the Timing Analyzer Set up the TimeQuest Timing Analyzer as follows: Select menu Assignments > Settings In the left pane, select Timing Analysis Settings To the right, select Use TimeQuest Timing Analyzer during Compilation In the left pane, select TimeQuest Timing Analyzer To the right, click on the... next to the SDC FileName: box, and find the file counter.sdc (which is in the download from the website). This file sets the clock frequency. Click Add to add the counter.sdc file to the project. Now at the bottom of the same form, set Synchronizer Identification: to Auto Click OK The last step tells Quartus to search for chains of registers automatically note however that Quartus will not carry out 2 Copyright 2009 by Doulos. All rights reserved.

metastability analysis until you have manually identified valid synchronization chains. Identifying Synchronization Chains With the default setting of stage of synchronization on UpDn and Load, you should find that Quartus fails to identify any synchronization chains. This is because the default behaviour is to look for at least 2 flip-flops, and we have set our synchronization chain length to. To verify this Compile the design Run TimeQuest (double-click the clock icon) In TimeQuest, double-click Update Timing Netlist Double-click Report Metastability You should see the message Info: No synchronizer chains to report. Now you can close TimeQuest. To identify synchronization chains Select menu Assignments > Assignment Editor In the assignment editor, use the drop-down list under Assignment Name, and select Synchronizer Identification Now double-click under To so a small right-pointing arrow appears From the arrow, select Node Finder... In the node finder, set Filter... to Registers: Post Fitting Click List Select sync:s delay and sync:s2 delay, and add them to the SelectedNodes There s a screenshot at the top of the next page: Copyright 2009 by Doulos. All rights reserved. 3

Asynchronous Signals and Metastability Click OK to close the dialogue box. The final step is to set the value for these assignments in the Assignment Editor (which should still be open). In the column labelled Value, select Forced if asynchronous for both assignments. Save the assignments once saved, you can quite the assignments editor. Now run compilation and TimeQuest again, and run the metastability report. This time you should see By carefully writing a bad design (!) and only using one stage of synchronization we have achieved a very bad MTBF of 2 seconds! However before changing our chains to length 2, it would be a good idea to understand what this figure is really means. Altera Quartus is automatically calculating a value based on the performance of the flip- 4 Copyright 2009 by Doulos. All rights reserved.

flips in a Cyclone III chip with speed grade 8 but what about the frequencies? The sampling frequency is set by the clock, which was set in the counter.sdc constraint file. If you look in there, you ll see we set a clock period of 4.3ns (frequency of 233MHz). The Quartus software assumes that the inputs we are sampling are changing at /8 of the clock frequency (about 29 million transitions per second). In other words, the calculation is assuming that UpDn and Load are both changing asynchronously 29 million times per second. If this is not realistic, then you can adjust the assumptions by setting the assignment Synchronizer Toggle Rate in the Assignment Editor. You ll also see from the Report Metastability output in TimeQuest the figure Worst Case Available Settling Time 0.57 ns Improving Metastability To improve the metastability we could reduce the clock rate reduce the input toggle rate (for UpDn and Load) choose a faster speed grade device re-design our code to remove the large amount of combinational logic between UpDn and the destination registers in the counter increase the length of the synchronization chain Let s try the last one of these, increase the synchronization chain length. First, let s find out what is the main contributor to our metastability. From the metastability report it is possible to get the individual contribution of each asynchronous input, which is shown below: Copyright 2009 by Doulos. All rights reserved. 5

Asynchronous Signals and Metastability From this you can see that UpDn is the main culprit. By increasing the synchronization chain to length 2 on the UpDn input, we obtain an MTBF of greater than billion years for the UpDn input, and.24 years for the Load input which gives a combined MTBF of.24 years. By making the synchronization chain length 2 for the Load signal as well, the combined MTBF becomes over billion years which should be good enough! 6 Copyright 2009 by Doulos. All rights reserved.

Conclusion We have summarised literature for metastability, and shown the governing equation pointing out the care needed to correctly understand the various constants involved. We have then worked through a practical example using the metastability calculation features in Altera Quartus II 9.0 to show the effect of adding stages to input synchronization of asynchronous signals. For modern fast CMOS processes a 2 stage synchronizer will almost definitely be sufficient to increase MTBF to acceptable levels, but it is easily possible that a single stage of synchronization is not sufficient. Finally, it is wise not to ignore metastability even though modern chips are very fast it only takes one bad synchronizer (or even worse an unsynchronized asynchronous input) to drastically reduce MTBF. And Finally... We hope you find this Technote useful. Please visit www.doulos.com/knowhow for more valuable hints and tips, and to download example code to go with this Technote. Copyright 2009 by Doulos. All rights reserved. 7