EECS150 - Digital Design Lecture 23 - FSMs & Counters

Similar documents
EECS150 - Digital Design Lecture 11 - Shifters & Counters. Register Summary

EECS150 - Digital Design Lecture 18 - Counters

EECS150 - Digital Design Lecture 18 - Counters

EECS150 - Digital Design Lecture 17 - Sequential Circuits 3 (Counters)

EECS150 - Digital Design Lecture 16 Counters. Announcements

EECS150 - Digital Design Lecture 25 Shifters and Counters. Recap

Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec 09 Counters Outline.

Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec09 Counters Outline.

Parity Checker Example. EECS150 - Digital Design Lecture 9 - Finite State Machines 1. Formal Design Process. Formal Design Process

EECS150 - Digital Design Lecture 15 SIFT2 + FSM. Recap and Outline

EECS Components and Design Techniques for Digital Systems. FSMs 9/11/2007

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 9 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

Models for representing sequential circuits

EECS150 - Digital Design Lecture 24 - Arithmetic Blocks, Part 2 + Shifters

Example: vending machine

Lecture 10: Synchronous Sequential Circuits Design

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

Ch 7. Finite State Machines. VII - Finite State Machines Contemporary Logic Design 1

Generalized FSM model: Moore and Mealy

Clocked Sequential Circuits UNIT 13 ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS. Analysis of Clocked Sequential Circuits. Signal Tracing and Timing Charts

Synchronous Sequential Circuit Design. Digital Computer Design

ECE 341. Lecture # 3

Present Next state Output state w = 0 w = 1 z A A B 0 B A C 0 C A C 1

Chapter 6. Synchronous Sequential Circuits

FSM model for sequential circuits

Last lecture Counter design Finite state machine started vending machine example. Today Continue on the vending machine example Moore/Mealy machines

Appendix B. Review of Digital Logic. Baback Izadi Division of Engineering Programs

CHW 261: Logic Design

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING BENG (HONS) ELECTRICAL & ELECTRONICS ENGINEERING EXAMINATION SEMESTER /2017

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

Digital Fundamentals

Chapter 5. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 5 <1>

The Design Procedure. Output Equation Determination - Derive output equations from the state table

Professor Fearing EECS150/Problem Set Solution Fall 2013 Due at 10 am, Thu. Oct. 3 (homework box under stairs)

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

Digital Circuits ECS 371

LOGIC CIRCUITS. Basic Experiment and Design of Electronics

ELEC Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10)

Digital Logic Design - Chapter 5

Synchronous Sequential Circuit Design. Dr. Ehab A. H. AL-Hialy Page 1

COE 202: Digital Logic Design Sequential Circuits Part 3. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

EECS150 - Digital Design Lecture 23 - FFs revisited, FIFOs, ECCs, LSFRs. Cross-coupled NOR gates

ENGG 1203 Tutorial _03 Laboratory 3 Build a ball counter. Lab 3. Lab 3 Gate Timing. Lab 3 Steps in designing a State Machine. Timing diagram of a DFF


EEE2135 Digital Logic Design

10/12/2016. An FSM with No Inputs Moves from State to State. ECE 120: Introduction to Computing. Eventually, the States Form a Loop

Sequential Logic Optimization. Optimization in Context. Algorithmic Approach to State Minimization. Finite State Machine Optimization

Introduction EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 6: Sequential Logic 3 Registers & Counters 5/9/2010

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

LOGIC CIRCUITS. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

Sample Test Paper - I

Different encodings generate different circuits

Analysis of clocked sequential networks

Digital Logic and Design (Course Code: EE222) Lecture 19: Sequential Circuits Contd..

ELCT201: DIGITAL LOGIC DESIGN

Finite State Machine (FSM)

Sequential Logic Worksheet

COE 202: Digital Logic Design Sequential Circuits Part 3. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

State and Finite State Machines

Logic Design II (17.342) Spring Lecture Outline

EECS150 - Digital Design Lecture 21 - Design Blocks

Design of Datapath Controllers

EGR224 F 18 Assignment #4

Digital Fundamentals

EECS 151/251A Fall 2018 Digital Design and Integrated Circuits. Instructor: John Wawrzynek & Nicholas Weaver. Lecture 5 EE141

Counters. We ll look at different kinds of counters and discuss how to build them

COEN 312 DIGITAL SYSTEMS DESIGN - LECTURE NOTES Concordia University

CPE100: Digital Logic Design I

COE 202: Digital Logic Design Sequential Circuits Part 4. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Lecture 8: Sequential Networks and Finite State Machines

CPE100: Digital Logic Design I

Total time is: 1 setup, 2 AND, 3 XOR, 1 delay = (1*1) + (2*2) + (3*3) + (1*1) = 15ns

PAST EXAM PAPER & MEMO N3 ABOUT THE QUESTION PAPERS:

For smaller NRE cost For faster time to market For smaller high-volume manufacturing cost For higher performance

FSM Optimization. Counter Logic Diagram Q1 Q2 Q3. Counter Implementation using RS FF 10/13/2015

State Graphs FSMs. Page 1

Chapter 7. Sequential Circuits Registers, Counters, RAM

EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

University of Toronto Faculty of Applied Science and Engineering Final Examination

PGT104 Digital Electronics. PGT104 Digital Electronics

CSC 322: Computer Organization Lab

04. What is the Mod number of the counter circuit shown below? Assume initially reset.

6 Synchronous State Machine Design

CSE 140 Midterm 3 version A Tajana Simunic Rosing Spring 2015

Appendix A: Digital Logic. Principles of Computer Architecture. Principles of Computer Architecture by M. Murdocca and V. Heuring

Philadelphia University Student Name: Student Number:

EE 209 Logic Cumulative Exam Name:

Lecture 7: Logic design. Combinational logic circuits

Final Exam. ECE 25, Spring 2008 Thursday, June 12, Problem Points Score Total 90

Preparation of Examination Questions and Exercises: Solutions

ECE380 Digital Logic. Synchronous sequential circuits

Review Problem 1. should be on. door state, false if light should be on when a door is open. v Describe when the dome/interior light of the car

Sequential logic and design

S.Y. Diploma : Sem. III [DE/ED/EI/EJ/EN/ET/EV/EX/IC/IE/IS/IU/MU] Principles of Digital Techniques

( c) Give logic symbol, Truth table and circuit diagram for a clocked SR flip-flop. A combinational circuit is defined by the function

Written exam with solutions IE Digital Design Friday 21/

Synchronous Sequential Logic

Finite State Machine. By : Ali Mustafa

BER KELEY D AV IS IR VINE LOS AN GELES RIVERS IDE SAN D IEGO S AN FRANCISCO

Transcription:

EECS150 - Digital Design Lecture 23 - FSMs & Counters April 8, 2010 John Wawrzynek Spring 2010 EECS150 - Lec22-counters Page 1 One-hot encoding of states. One FF per state. State Encoding Why one-hot encoding? Simple design procedure. Circuit matches state transition diagram (example next page). Often can lead to simpler and faster next state and output logic. Why not do this? Can be costly in terms of FFs for FSMs with large number of states. FPGAs are FF rich, therefore one-hot state machine encoding is often a good approach. Spring 2010 EECS150 - Lec22-counters Page 2

Even Parity Checker Circuit: One-hot encoded FSM Circuit generated through direct inspection of the STD. In General: FFs must be initialized for correct operation (only one 1) Spring 2010 EECS150 - Lec22-counters Page 3 One-hot encoded combination lock Spring 2010 EECS150 - Lec22-counters Page 4

General FSM form: FSM Implementation Notes All examples so far generate output based only on the present state: Commonly name Moore Machine (If output functions include both present state and input then called a Mealy Machine) Spring 2010 EECS150 - Lec22-counters Page 5 Finite State Machines Example: Edge Detector Bit are received one at a time (one per cycle), such as: 000111010 time CLK Design a circuit that asserts its output for one cycle when the input bit stream changes from 0 to 1. IN FSM OUT Try two different solutions. Spring 2010 EECS150 - Lec22-counters Page 6

State Transition Diagram Solution A ZERO CHANGE ONE IN PS NS OUT 0 00 00 0 1 00 01 0 0 01 00 1 1 01 11 1 0 11 00 0 1 11 11 0 Spring 2010 EECS150 - Lec22-counters Page 7 Solution A, circuit derivation ZERO CHANGE ONE IN PS NS OUT 0 00 00 0 1 00 01 0 0 01 00 1 1 01 11 1 0 11 00 0 1 11 11 0 Spring 2010 EECS150 - Lec22-counters Page 8

Solution B Output deps not only on PS but also on input, IN Let ZERO=0, ONE=1 IN PS NS OUT 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 NS = IN, OUT = IN PS What s the intuition about this solution? Spring 2010 EECS150 - Lec22-counters Page 9 Edge detector timing diagrams Solution A: output follows the clock Solution B: output changes with input rising edge and is asynchronous wrt the clock. Spring 2010 EECS150 - Lec22-counters Page 10

FSM Comparison Solution A Moore Machine output function only of PS maybe more states (why?) synchronous outputs no glitches one cycle delay full cycle of stable output Solution B Mealy Machine output function of both PS & input maybe fewer states asynchronous outputs if input glitches, so does output output immediately available output may not be stable long enough to be useful (below): If output of Mealy FSM goes through combinational logic before being registered, the CL might delay the signal and it could be missed by the clock edge. Spring 2010 EECS150 - Lec22-counters Page 11 FSM Recap Moore Machine Mealy Machine Both machine types allow one-hot implementations. Spring 2010 EECS150 - Lec22-counters Page 12

Final Notes on Moore versus Mealy 1. A given state machine could have both Moore and Mealy style outputs. Nothing wrong with this, but you need to be aware of the timing differences between the two types. 2. The output timing behavior of the Moore machine can be achieved in a Mealy machine by registering the Mealy output values: Spring 2010 EECS150 - Lec22-counters Page 13 General FSM Design Process with Verilog Implementation Design Steps: 1. Specify circuit function (English) 2. Draw state transition diagram 3. Write down symbolic state transition table 4. Assign encodings (bit patterns) to symbolic states 5. Code as Verilog behavioral description Use parameters to represent encoded states. Use separate always blocks for register assignment and CL logic block. Use case for CL block. Within each case section assign all outputs and next state value based on inputs. Note: For Moore style machine make outputs depent only on state not depent on inputs. Spring 2010 EECS150 - Lec22-counters Page 14

Mealy Machine FSMs in Verilog Moore Machine always @(posedge clk) if (rst) ps <= ZERO; else ps <= ns; always @(ps in) case (ps) ZERO: if (in) begin out = 1 b1; ns = ONE; else begin out = 1 b0; ns = ZERO; ONE: if (in) begin out = 1 b0; ns = ONE; else begin out = 1 b0; ns = ZERO; default: begin out = 1 bx; ns = default; always @(posedge clk) if (rst) ps <= ZERO; else ps <= ns; always @(ps in) case (ps) ZERO: begin out = 1 b0; if (in) ns = CHANGE; else ns = ZERO; CHANGE: begin out = 1 b1; if (in) ns = ONE; else ns = ZERO; ONE: begin out = 1 b0; if (in) ns = ONE; else ns = ZERO; default: begin out = 1 bx; ns = default; Spring 2010 EECS150 - Lec22-counters Page 15 Counters Special sequential circuits (FSMs) that repeatedly sequence through a set of outputs. Examples: binary counter: 000, 001, 010, 011, 100, 101, 110, 111, 000, gray code counter: 000, 010, 110, 100, 101, 111, 011, 001, 000, 010, 110, one-hot counter: 0001, 0010, 0100, 1000, 0001, 0010, BCD counter: 0000, 0001, 0010,, 1001, 0000, 0001 pseudo-random sequence generators: 10, 01, 00, 11, 10, 01, 00,... Moore machines with ring structure in State Transition Diagram: S0 Spring 2010 EECS150 - Lec22-counters Page 16 S3 S2 S1

What are they used? Counters are commonly used in hardware designs because most (if not all) computations that we put into hardware include iteration (looping). Examples: Shift-and-add multiplication scheme. Bit serial communication circuits (must count one words worth of serial bits. Other uses for counter: Clock divider circuits 16MHz 64 Systematic inspection of data-structures Example: Network packet parser/filter control. Counters simplify controller design by: providing a specific number of cycles of action, sometimes used with a decoder to generate a sequence of timed control signals. Consider using a counter when many FSM states with few branches. Spring 2010 EECS150 - Lec22-counters Page 17 Controller using Counters Example, Bit-serial multiplier (n 2 cycles, one bit of result per n cycles): Control Algorithm: repeat n cycles { // outer (i) loop repeat n cycles{ // inner (j) loop } shifta, selectsum, shifthi } shiftb, shifthi, shiftlow, reset Note: The occurrence of a control signal x means x=1. The absence of x means x=0. Spring 2010 EECS150 - Lec22-counters Page 18

Controller using Counters State Transition Diagram: Assume presence of two binary counters. An i counter for the outer loop and j counter for inner loop. TC is asserted when the counter reaches it maximum count value. CE is count enable. The counter increments its value on the rising edge of the clock if CE is asserted. Spring 2010 EECS150 - Lec22-counters Page 19 Controller using Counters Controller circuit implementation: Outputs: CE i = q 2 CE j = q 1 RST i = q 0 RST j = q 2 shifta = q 1 shiftb = q 2 shiftlow = q 2 shifthi = q 1 + q 2 reset = q 2 selectsum = q 1 Spring 2010 EECS150 - Lec22-counters Page 20

How do we design counters? For binary counters (most common case) incrementer circuit would work: 1 + register In Verilog, a counter is specified as: x = x+1; This does not imply an adder An incrementer is simpler than an adder And a counter is simpler yet. In general, the best way to understand counter design is to think of them as FSMs, and follow general procedure, however some special cases can be optimized. Spring 2010 EECS150 - Lec22-counters Page 21 Synchronous Counters All outputs change with clock edge. Binary Counter Design: Start with 3-bit version and generalize: c b a c + b + a + 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 a + = a b + = a b cb a 00 01 11 10 0 0 0 1 1 1 0 1 0 1 c + = a c + abc + b c = c(a +b ) + c (ab) = c(ab) + c (ab) = c ab Spring 2010 EECS150 - Lec22-counters Page 22

Synchronous Counters How do we ext to n-bits? Extrapolate c + : d + = d abc, e + = e abcd Has difficulty scaling (AND gate inputs grow with n) TC CE is count enable, allows external control of counting, TC is terminal count, is asserted on highest value, allows cascading, external sensing of occurrence of max value. Spring 2010 EECS150 - Lec22-counters Page 23 Synchronous Counters TC How does this one scale? Delay grows α n Generation of TC signals very similar to generation of carry signals in adder. Parallel Prefix circuit reduces delay: log 2 n log 2 n Spring 2010 EECS150 - Lec22-counters Page 24

Up-Down Counter c b a c + b + a + 0 0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 Down-count Spring 2010 EECS150 - Lec22-counters Page 25 Odd Counts Extra combinational logic can be added to terminate count before max value is reached: Example: count to 12 Alternative: Spring 2010 EECS150 - Lec22-counters Page 26

Ring Counters one-hot counters 0001, 0010, 0100, 1000, 0001, What are these good for? Self-starting version: Spring 2010 EECS150 - Lec22-counters Page 27 Johnson Counter Spring 2010 EECS150 - Lec22-counters Page 28

Asynchronous Ripple counters A 3 A 2 A 1 A 0 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 time Forbidden in Synchronous Design Each stage is 2 of previous. Look at output waveforms: CLK A 0 A 1 A 2 A 3 Often called asynchronous counters. A T flip-flop is a toggle flip-flop. Flips it state on cycles when T=1. Spring 2010 EECS150 - Lec22-counters Page 29